diff --git a/lib/v8.rb b/lib/v8.rb index 320afe9..a5f271a 100644 --- a/lib/v8.rb +++ b/lib/v8.rb @@ -25,7 +25,6 @@ require 'v8/conversion' # require 'v8/access/indices' # require 'v8/access/invocation' # require 'v8/access' -# require 'v8/context' -# require 'v8/object' +require 'v8/object' # require 'v8/array' # require 'v8/function' diff --git a/lib/v8/conversion.rb b/lib/v8/conversion.rb index 2cc202f..8f08c9a 100644 --- a/lib/v8/conversion.rb +++ b/lib/v8/conversion.rb @@ -31,6 +31,12 @@ module V8::C IsTrue() end end + + class Object + def to_ruby + ::V8::Object.new self + end + end end class String diff --git a/lib/v8/object.rb b/lib/v8/object.rb index 71f6281..5382f16 100644 --- a/lib/v8/object.rb +++ b/lib/v8/object.rb @@ -6,12 +6,12 @@ class V8::Object def initialize(native = nil) @context = V8::Context.current or fail "tried to initialize a #{self.class} without being in an entered V8::Context" @native = block_given? ? yield : native || V8::C::Object::New() - @context.link self, @native + #@context.link self, @native end def [](key) @context.enter do - @context.to_ruby @native.Get(@context.to_v8(key)) + @context.to_ruby @native.Get(@context.native, @context.to_v8(key)).FromJust() end end @@ -76,4 +76,4 @@ class V8::Object raise ArgumentError, "wrong number of arguments (#{args.length} for 0)" unless args.empty? end end -end \ No newline at end of file +end diff --git a/spec/v8/context_spec.rb b/spec/v8/context_spec.rb index 79dbd90..e996677 100644 --- a/spec/v8/context_spec.rb +++ b/spec/v8/context_spec.rb @@ -71,18 +71,18 @@ describe "V8::Context" do # end # end - # xit "can pass objects back to ruby" do - # @cxt.eval("({foo: 'bar', baz: 'bang', '5': 5, embedded: {badda: 'bing'}})").tap do |object| - # object.should_not be_nil - # object['foo'].should == 'bar' - # object['baz'].should == 'bang' - # object['5'].should == 5 - # object['embedded'].tap do |embedded| - # embedded.should_not be_nil - # embedded['badda'].should == 'bing' - # end - # end - # end + it "can pass objects back to ruby" do + @cxt.eval("({foo: 'bar', baz: 'bang', '5': 5, embedded: {badda: 'bing'}})").tap do |object| + object.should_not be_nil + object['foo'].should == 'bar' + object['baz'].should == 'bang' + object['5'].should == 5 + object['embedded'].tap do |embedded| + embedded.should_not be_nil + embedded['badda'].should == 'bing' + end + end + end # xit "can pass int properties to ruby", :compat => '0.2.1' do # @cxt.eval("({ 4: '4', 5: 5, '6': true })").tap do |object|