diff --git a/v8_cxt.cpp b/v8_cxt.cpp index 40375cb..9ee0855 100644 --- a/v8_cxt.cpp +++ b/v8_cxt.cpp @@ -4,26 +4,19 @@ using namespace v8; -Local VALUE_TO_CONTEXT(VALUE value) { - v8_ref* ref = 0; - Data_Get_Struct(value, struct v8_ref, ref); - return (Context *)(*ref->handle); -} - VALUE v8_cxt_allocate(VALUE clazz) { - v8_ref* ref = new v8_ref(Context::New()); - return Data_Wrap_Struct(clazz, v8_ref_mark , v8_ref_free, ref); + return V8_Ref_Create(clazz, Context::New()); } VALUE v8_cxt_Global(VALUE self) { - Local cxt = VALUE_TO_CONTEXT(self); + V8_Ref_Get(Context, cxt, self); cxt->Global(); return Qnil; } VALUE v8_cxt_open(VALUE self) { HandleScope handles; - Local cxt = VALUE_TO_CONTEXT(self); + V8_Ref_Get(Context, cxt, self); Context::Scope enter(cxt); if (rb_block_given_p()) { return rb_yield(self); diff --git a/v8_ref.h b/v8_ref.h index 407df15..df2b102 100644 --- a/v8_ref.h +++ b/v8_ref.h @@ -20,4 +20,10 @@ void v8_ref_mark(v8_ref* ref); void v8_ref_free(v8_ref* ref); +//macros for helping make references + +#define V8_Ref_Create(clazz,handle) Data_Wrap_Struct(clazz,v8_ref_mark, v8_ref_free, new v8_ref(handle)) + +#define V8_Ref_Get(type,var,value) v8_ref* __ref__ = 0; Data_Get_Struct(value, struct v8_ref, __ref__); Local var = (type *)*__ref__->handle; + #endif \ No newline at end of file diff --git a/v8_script.cpp b/v8_script.cpp index 6a8ab14..e18f660 100644 --- a/v8_script.cpp +++ b/v8_script.cpp @@ -8,25 +8,16 @@ using namespace v8; -Local