mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
implement passing objects from JS -> Ruby
This commit is contained in:
parent
78c841c6b6
commit
277926fc7f
4 changed files with 22 additions and 17 deletions
|
@ -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'
|
||||
|
|
|
@ -31,6 +31,12 @@ module V8::C
|
|||
IsTrue()
|
||||
end
|
||||
end
|
||||
|
||||
class Object
|
||||
def to_ruby
|
||||
::V8::Object.new self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Add table
Reference in a new issue