diff --git a/ext/v8/callbacks.cpp b/ext/v8/callbacks.cpp index 091c691..d6b84a5 100644 --- a/ext/v8/callbacks.cpp +++ b/ext/v8/callbacks.cpp @@ -70,8 +70,8 @@ Handle RacerRubyInvocationCallback(const Arguments& args) { VALUE result = rb_funcall2(code, rb_intern("call"), args.Length(), arguments); delete [] arguments; - Handle convertedResult = RB2V8(result); - return convertedResult ; + Handle convertedResult = rr_rb2v8(result); + return convertedResult; } } diff --git a/ext/v8/rr.cpp b/ext/v8/rr.cpp index 685e9a9..fb359ff 100644 --- a/ext/v8/rr.cpp +++ b/ext/v8/rr.cpp @@ -115,7 +115,29 @@ Handle rr_rb2v8(VALUE value) { return True(); case T_FALSE: return False(); + case T_OBJECT: + return rr_reflect_rb_object(value); + case T_DATA: + case T_CLASS: + case T_ICLASS: + case T_MODULE: + case T_REGEXP: + case T_MATCH: + case T_ARRAY: + case T_HASH: + case T_STRUCT: + case T_BIGNUM: + case T_FILE: + case T_SYMBOL: + case T_BLKTAG: + case T_UNDEF: + case T_VARMAP: + case T_SCOPE: + case T_NODE: + default: + return String::New("Undefined Conversion"); } + return Undefined(); } // VALUE rr_v82rb(v8::ScriptData *data) { diff --git a/ext/v8/v8_obj.cpp b/ext/v8/v8_obj.cpp index d2b69eb..33efe10 100644 --- a/ext/v8/v8_obj.cpp +++ b/ext/v8/v8_obj.cpp @@ -1,6 +1,7 @@ #include "v8_obj.h" #include "v8_ref.h" #include "v8_value.h" +#include "v8_template.h" #include "converters.h" using namespace v8; @@ -21,9 +22,20 @@ void rr_init_obj() { VALUE rr_reflect_v8_object(Handle value) { Local object(Object::Cast(*value)); - VALUE obj = V8_Ref_Create(rr_cV8_C_Object, object); - rb_iv_set(obj, "@context", rr_v82rb(Context::GetEntered())); - return obj; + Local peer = object->GetHiddenValue(String::New("TheRubyRacer::RubyObject")); + if (peer.IsEmpty()) { + VALUE obj = V8_Ref_Create(rr_cV8_C_Object, object); + rb_iv_set(obj, "@context", rr_v82rb(Context::GetEntered())); + return obj; + } else { + return (VALUE)External::Unwrap(peer); + } +} + +v8::Handle rr_reflect_rb_object(VALUE value) { + Local o = Racer_Create_V8_ObjectTemplate(value)->NewInstance(); + o->SetHiddenValue(String::New("TheRubyRacer::RubyObject"), External::Wrap((void *) value)); + return o; } namespace { diff --git a/ext/v8/v8_obj.h b/ext/v8/v8_obj.h index c8d1c2c..e23a64e 100644 --- a/ext/v8/v8_obj.h +++ b/ext/v8/v8_obj.h @@ -7,6 +7,7 @@ extern VALUE rr_cV8_C_Object; void rr_init_obj(); VALUE rr_reflect_v8_object(v8::Handle value); +v8::Handle rr_reflect_rb_object(VALUE value); VALUE v8_Object_New(VALUE clazz); VALUE v8_Object_Get(VALUE self, VALUE key);