diff --git a/ext/v8/rr.cpp b/ext/v8/rr.cpp index 8fd3b72..e204e68 100644 --- a/ext/v8/rr.cpp +++ b/ext/v8/rr.cpp @@ -109,7 +109,6 @@ VALUE rr_v82rb(int32_t value) { return INT2FIX(value); } - Handle rr_rb2v8(VALUE value) { switch (TYPE(value)) { case T_FIXNUM: diff --git a/ext/v8/v8_external.cpp b/ext/v8/v8_external.cpp index d886183..0a7cda7 100644 --- a/ext/v8/v8_external.cpp +++ b/ext/v8/v8_external.cpp @@ -1,6 +1,8 @@ -#include "v8_external.h" #include "rr.h" +#include "v8_external.h" + #include "v8_ref.h" +#include "v8_value.h" using namespace v8; namespace { @@ -30,7 +32,7 @@ namespace { } void rr_init_v8_external() { - ExternalClass = rr_define_class("External"); + ExternalClass = rr_define_class("External", rr_cV8_C_Value); references = rb_hash_new(); rb_define_const(ExternalClass, "OBJECTS_REFERENCED_FROM_WITHIN_V8", references); rr_define_singleton_method(ExternalClass, "Wrap", Wrap, 1); @@ -44,7 +46,7 @@ VALUE rr_reflect_v8_external(Handle external) { Handle rr_v8_external_create(VALUE value) { rb_hash_aset(references, rb_obj_id(value), value); - Local external(External::Wrap((void *)value)); + Local external(External::New((void *)value)); Persistent record = Persistent::New(external); // V8::AdjustAmountOfExternalAllocatedMemory(100000000); record.MakeWeak(NULL, GCWeakReferenceCallback); diff --git a/ext/v8/v8_func.cpp b/ext/v8/v8_func.cpp index 1c90c36..2d1a564 100644 --- a/ext/v8/v8_func.cpp +++ b/ext/v8/v8_func.cpp @@ -36,7 +36,7 @@ namespace { for (int i = 0; i < argc; i++) { argv[i] = args->Get(i); } - return rr_v82rb(function->NewInstance(argc, argv)); + return rr_v8_ref_create(rr_cV8_C_Object, function->NewInstance(argc, argv)); } VALUE GetName(VALUE self) { return rr_v82rb(unwrap(self)->GetName()); diff --git a/ext/v8/v8_str.cpp b/ext/v8/v8_str.cpp index 4df0cfc..bfb776c 100644 --- a/ext/v8/v8_str.cpp +++ b/ext/v8/v8_str.cpp @@ -18,6 +18,7 @@ namespace { return rr_v8_ref_create(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str))); } VALUE NewSymbol(VALUE string_class, VALUE data) { + HandleScope scope; VALUE str = rb_funcall(data, rb_intern("to_s"), 0); return rr_v8_ref_create(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str))); } diff --git a/lib/v8/to.rb b/lib/v8/to.rb index 406e9e4..4004eb7 100644 --- a/lib/v8/to.rb +++ b/lib/v8/to.rb @@ -50,7 +50,6 @@ module V8 # obj = To.template.NewInstance() args = C::Array::New(1) args.Set(0, C::External::Wrap(value)) - rputs "about to call this mother." obj = To.class_template(value.class).GetFunction().NewInstance(args) return obj end @@ -79,13 +78,9 @@ module V8 end else class_template = C::FunctionTemplate::New() do |arguments| - rputs "In constructor" - if arguments.Length() > 0 if arguments.Length() > 0 && arguments[0].IsExternal() - rputs "this path?" wrapper = arguments[0] else - rputs "this path?????" rbargs = [] for i in 0..arguments.Length() - 1 rbargs << To.rb(arguments[i]) @@ -93,18 +88,19 @@ module V8 instance = V8::Function.rubycall(cls.method(:new), *rbargs) wrapper = C::External::Wrap(instance) end - arguments.This().SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), wrapper) - arguments.This() + arguments.This().tap do |this| + this.SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), wrapper) + end end - class_template.PrototypeTemplate().SetNamedPropertyHandler( + class_template.InstanceTemplate().SetNamedPropertyHandler( NamedPropertyGetter, NamedPropertySetter, nil, nil, NamedPropertyEnumerator ) - if cls.name && cls.name =~ /::(\w+?)$/ - class_template.SetClassName(C::String::NewSymbol($1)) + if cls.name && cls.name =~ /(::)?(\w+?)$/ + class_template.SetClassName(C::String::NewSymbol($2)) else class_template.SetClassName("Ruby") end