Mercurial > MadButterfly
changeset 559:ef078d7c57b4 Android_Skia
Use internal field to store njs_runtime_t object.
Instead of using named property to keep reference of njs_runtime_t
object, the internal field of v8 object is used.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 07 Jun 2010 11:42:45 +0800 |
parents | d61133da2845 |
children | ce7a35abcb0d |
files | nodejs/mbfly_njs.cc nodejs/mbfly_njs.h |
diffstat | 2 files changed, 38 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc Sun Jun 06 21:51:58 2010 +0800 +++ b/nodejs/mbfly_njs.cc Mon Jun 07 11:42:45 2010 +0800 @@ -5,6 +5,8 @@ #include "X_supp_njs.h" } +#include "mbfly_njs.h" + using namespace v8; /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. @@ -47,7 +49,7 @@ rt = X_njs_MB_new(display_name, width, height); self = args.This(); - self->Set(String::New("_njs_rt"), External::Wrap(rt)); + WRAP(self, rt); X_njs_MB_init_handle_connection(rt); @@ -60,6 +62,18 @@ /* @} */ +redraw_man_t * +xnjsmb_rt_rdman(Handle<Object> mbrt) { + HandleScope scope; + njs_runtime_t *rt; + redraw_man_t *rdman; + + rt = (njs_runtime_t *)UNWRAP(mbrt); + rdman = X_njs_MB_rdman(rt); + + return rdman; +} + Handle<Value> hello_func(const Arguments &args) { HandleScope scope; @@ -77,4 +91,5 @@ func = FunctionTemplate::New(xnjsmb_new); target->Set(String::New("mb_rt"), func->GetFunction()); + func->PrototypeTemplate()->SetInternalFieldCount(1); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/mbfly_njs.h Mon Jun 07 11:42:45 2010 +0800 @@ -0,0 +1,22 @@ +#ifndef __MBFLY_NJS_H_ +#define __MBFLY_NJS_H_ + +#include <v8.h> +extern "C" { +#include <mb.h> +} + +#define THROW(x) \ + do { \ + v8::Handle<v8::Value> exc; \ + exc = v8::Exception::Error(v8::String::New(x)); \ + return v8::ThrowException(exc); \ + } while(0) +#define UNWRAP(o) v8::External::Unwrap((o)->GetInternalField(0)) +#define WRAP(o, v) (o)->SetInternalField(0, v8::External::Wrap(v)) +#define SET(o, n, v) (o)->Set(v8::String::New(n), v) +#define GET(o, n) (o)->Get(v8::String::New(n)) + +redraw_man_t *xnjsmb_rt_rdman(v8::Handle<v8::Object> mbrt); + +#endif /* __MBFLY_NJS_H_ */