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

Set properties on javascript objects which are reflected into ruby.

This commit is contained in:
Charles Lowell 2010-01-10 12:02:08 +02:00
parent 772fa7d586
commit 441aa30a7f
2 changed files with 9 additions and 3 deletions

View file

@ -16,7 +16,7 @@ VALUE v8_Object_New(VALUE clazz) {
VALUE v8_Object_Get(VALUE self, VALUE key) { VALUE v8_Object_Get(VALUE self, VALUE key) {
HandleScope handles; HandleScope handles;
Local<Object> obj = V8_Ref_Get<Object>(self); Local<Object> obj = V8_Ref_Get<Object>(self);
VALUE keystr = rb_funcall(key,rb_intern("to_s"), 0); VALUE keystr = rb_str_to_str(key);
Local<Value> value = obj->Get(RB2V8(keystr)); Local<Value> value = obj->Get(RB2V8(keystr));
return V82RB(value); return V82RB(value);
} }
@ -24,8 +24,8 @@ VALUE v8_Object_Get(VALUE self, VALUE key) {
VALUE v8_Object_Set(VALUE self, VALUE key, VALUE value) { VALUE v8_Object_Set(VALUE self, VALUE key, VALUE value) {
HandleScope handles; HandleScope handles;
Local<Object> obj = V8_Ref_Get<Object>(self); Local<Object> obj = V8_Ref_Get<Object>(self);
VALUE keystr = rb_funcall(key, rb_intern("to_s"), 0); VALUE keystr = rb_funcall(key, rb_intern("to_s"), 0);
obj->Set(RB2V8(keystr), RB2V8(value)); obj->Set(RB2V8(keystr), RB2V8(value));
return Qnil; return Qnil;
} }

View file

@ -6,7 +6,13 @@ module V8
end end
def [](key) def [](key)
To.ruby(@native.Get(key)) To.ruby(@native.Get(key.to_s))
end
def []=(key, value)
value.tap do
@native.Set(key.to_s, value)
end
end end
end end
end end