1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

maintain referential integrity on ruby objects passed back and forth to the runtime

This commit is contained in:
Charles Lowell 2010-05-17 16:07:43 +03:00
parent 4dfc037e6b
commit ba7c233248
4 changed files with 40 additions and 5 deletions

View file

@ -70,7 +70,7 @@ Handle<Value> RacerRubyInvocationCallback(const Arguments& args) {
VALUE result = rb_funcall2(code, rb_intern("call"), args.Length(), arguments);
delete [] arguments;
Handle<Value> convertedResult = RB2V8(result);
Handle<Value> convertedResult = rr_rb2v8(result);
return convertedResult;
}
}

View file

@ -115,7 +115,29 @@ Handle<Value> 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) {

View file

@ -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> value) {
Local<Object> object(Object::Cast(*value));
Local<Value> 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<v8::Value> rr_reflect_rb_object(VALUE value) {
Local<Object> o = Racer_Create_V8_ObjectTemplate(value)->NewInstance();
o->SetHiddenValue(String::New("TheRubyRacer::RubyObject"), External::Wrap((void *) value));
return o;
}
namespace {

View file

@ -7,6 +7,7 @@ extern VALUE rr_cV8_C_Object;
void rr_init_obj();
VALUE rr_reflect_v8_object(v8::Handle<v8::Value> value);
v8::Handle<v8::Value> rr_reflect_rb_object(VALUE value);
VALUE v8_Object_New(VALUE clazz);
VALUE v8_Object_Get(VALUE self, VALUE key);