diff --git a/ext/v8/v8_callbacks.cpp b/ext/v8/v8_callbacks.cpp index bc14f51..ead7f7c 100644 --- a/ext/v8/v8_callbacks.cpp +++ b/ext/v8/v8_callbacks.cpp @@ -119,11 +119,3 @@ VALUE rr_v82rb(const AccessorInfo& info) { VALUE rr_v82rb(const Arguments& arguments) { return Data_Wrap_Struct(ArgumentsClass, gc_wrap_mark, gc_wrap_free, new WrapArguments(arguments)); } - -Handle RubyInvocationCallback(const Arguments& args) { - HandleScope handles; - VALUE code = (VALUE)External::Unwrap(args.Data()); - VALUE rb_args = rr_v82rb(args); - VALUE result = rb_funcall(code, rb_intern("call"), 1, rb_args); - return rr_rb2v8(result); -} diff --git a/ext/v8/v8_callbacks.h b/ext/v8/v8_callbacks.h index a00ba5b..b14a351 100644 --- a/ext/v8/v8_callbacks.h +++ b/ext/v8/v8_callbacks.h @@ -1,9 +1,8 @@ #ifndef _RR_V8_CALLBACKS_ #define _RR_V8_CALLBACKS_ -#include "v8.h" +#include "rr.h" void rr_init_v8_callbacks(); -// VALUE rr_v82rb(v8::AccessorInfo& info); -// VALUE rr_v82rb(v8::Arguments& arguments); +VALUE rr_v82rb(const v8::AccessorInfo& info); +VALUE rr_v82rb(const v8::Arguments& arguments); -v8::Handle RubyInvocationCallback(const v8::Arguments& args); #endif \ No newline at end of file diff --git a/ext/v8/v8_cxt.cpp b/ext/v8/v8_cxt.cpp index 5180ec5..faeb5be 100644 --- a/ext/v8/v8_cxt.cpp +++ b/ext/v8/v8_cxt.cpp @@ -18,6 +18,7 @@ namespace { return V8_Ref_Get(value); } + //TODO: make this scriptable and less static VALUE New(int argc, VALUE *argv, VALUE self) { HandleScope handles; VALUE scope; diff --git a/ext/v8/v8_obj.cpp b/ext/v8/v8_obj.cpp index 9f9954f..45e6d35 100644 --- a/ext/v8/v8_obj.cpp +++ b/ext/v8/v8_obj.cpp @@ -29,7 +29,7 @@ namespace { VALUE New(VALUE clazz) { HandleScope handles; if (!Context::InContext()) { - rb_raise(rb_eScriptError, "tried to allocate an Object, but no context was open"); + rb_raise(rb_eScriptError, "Object::New() called without an entered Context"); return Qnil; } return V8_Ref_Create(clazz, Object::New()); @@ -39,7 +39,7 @@ namespace { HandleScope handles; Local obj = unwrap(self); if (rb_obj_is_kind_of(key, rb_cNumeric)) { - return rr_v82rb(obj->Set(NUM2UINT(key), RB2V8(value))); + return rr_v82rb(obj->Set(NUM2UINT(key), rr_rb2v8(value))); } else { return rr_v82rb(obj->Set(rr_rb2v8(key), rr_rb2v8(value))); } @@ -50,7 +50,18 @@ namespace { Local object = unwrap(self); Local names = object->GetPropertyNames(); return rr_v82rb(names); - } + } + VALUE SetHiddenValue(VALUE self, VALUE key, VALUE value) { + HandleScope scope; + if (Context::InContext()) { + unwrap(self)->SetHiddenValue(rr_rb2v8(key)->ToString(), rr_rb2v8(value)); + } else { + rb_raise(rb_eScriptError, "Object::SetHiddenValue() called without an entered Context"); + } + //TODO: need to store a reference here? what's the best way + // rr_v8_ref_setref(self, "RubyPeer", ) + return Qnil; + } } void rr_init_obj() { @@ -60,6 +71,7 @@ void rr_init_obj() { rr_define_method(rr_cV8_C_Object, "Get", Get, 1); rr_define_method(rr_cV8_C_Object, "Set", Set, 2); rr_define_method(rr_cV8_C_Object, "GetPropertyNames", GetPropertyNames, 0); + rr_define_method(rr_cV8_C_Object, "SetHiddenValue", SetHiddenValue, 2); } VALUE rr_reflect_v8_object(Handle value) { diff --git a/ext/v8/v8_ref.cpp b/ext/v8/v8_ref.cpp index bf57744..e64bd6d 100644 --- a/ext/v8/v8_ref.cpp +++ b/ext/v8/v8_ref.cpp @@ -31,6 +31,10 @@ VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle handle, VALUE ref) { return Data_Wrap_Struct(ruby_class, gc_mark, gc_free, new v8_ref(handle, ref)); } +VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle handle) { + return Data_Wrap_Struct(rbclass, gc_mark, gc_free, new v8_ref(handle)); +} + void rr_v8_ref_setref(VALUE handle, const char *name, VALUE newref) { v8_ref *ref = 0; Data_Get_Struct(handle, struct v8_ref, ref); diff --git a/ext/v8/v8_ref.h b/ext/v8/v8_ref.h index 187c50d..6ea3129 100644 --- a/ext/v8/v8_ref.h +++ b/ext/v8/v8_ref.h @@ -18,7 +18,7 @@ struct v8_ref { void rr_v8_ref_setref(VALUE handle, const char *name, VALUE ref); VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle handle, VALUE ref = 0); -VALUE rr_wrap(VALUE ruby_class, void *value); +VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle handle); template v8::Local V8_Ref_Get(VALUE object) { v8_ref* ref = 0; diff --git a/ext/v8/v8_template.cpp b/ext/v8/v8_template.cpp index 57f4e6f..20e8c98 100644 --- a/ext/v8/v8_template.cpp +++ b/ext/v8/v8_template.cpp @@ -10,6 +10,15 @@ using namespace v8; namespace { + + VALUE rb_hash_lookup(VALUE hash, const char *key) { + return ::rb_hash_lookup(hash, rb_str_new2(key)); + } + + VALUE rb_hash_aset(VALUE hash, const char *key, VALUE value) { + return ::rb_hash_aset(hash, rb_str_new2(key), value); + } + Local