From 441aa30a7f9b6a0cbd48cd2078d4569099cb0dce Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Sun, 10 Jan 2010 12:02:08 +0200 Subject: [PATCH] Set properties on javascript objects which are reflected into ruby. --- ext/v8/v8_obj.cpp | 4 ++-- lib/v8/object.rb | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ext/v8/v8_obj.cpp b/ext/v8/v8_obj.cpp index ab6c1f1..6d759c1 100644 --- a/ext/v8/v8_obj.cpp +++ b/ext/v8/v8_obj.cpp @@ -16,7 +16,7 @@ VALUE v8_Object_New(VALUE clazz) { VALUE v8_Object_Get(VALUE self, VALUE key) { HandleScope handles; Local obj = V8_Ref_Get(self); - VALUE keystr = rb_funcall(key,rb_intern("to_s"), 0); + VALUE keystr = rb_str_to_str(key); Local value = obj->Get(RB2V8(keystr)); 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) { HandleScope handles; Local obj = V8_Ref_Get(self); + VALUE keystr = rb_funcall(key, rb_intern("to_s"), 0); - obj->Set(RB2V8(keystr), RB2V8(value)); return Qnil; } diff --git a/lib/v8/object.rb b/lib/v8/object.rb index 9ee1cda..ee7ed70 100644 --- a/lib/v8/object.rb +++ b/lib/v8/object.rb @@ -6,7 +6,13 @@ module V8 end 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 \ No newline at end of file