mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
construct Ruby objects from JavaScript
This commit is contained in:
parent
6a306a93db
commit
d020ba13b3
1 changed files with 32 additions and 6 deletions
|
@ -26,13 +26,39 @@ class V8::Conversion
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(arguments)
|
def call(arguments)
|
||||||
|
arguments.extend Args
|
||||||
protect do
|
protect do
|
||||||
context = V8::Context.current
|
if arguments.linkage_call?
|
||||||
args = ::Array.new(arguments.Length())
|
arguments.link
|
||||||
0.upto(args.length - 1) do |i|
|
else
|
||||||
args[i] = context.to_ruby arguments[i]
|
arguments.construct @class
|
||||||
end
|
end
|
||||||
context.to_v8 @class.new(*args)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module Args
|
||||||
|
def linkage_call?
|
||||||
|
self.Length() == 1 && self[0].IsExternal()
|
||||||
|
end
|
||||||
|
|
||||||
|
def link
|
||||||
|
context.link self[0].Value(), This()
|
||||||
|
end
|
||||||
|
|
||||||
|
def construct(cls)
|
||||||
|
context.link cls.new(*to_args), This()
|
||||||
|
end
|
||||||
|
|
||||||
|
def context
|
||||||
|
V8::Context.current
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_args
|
||||||
|
args = ::Array.new(Length())
|
||||||
|
0.upto(args.length - 1) do |i|
|
||||||
|
args[i] = self[i]
|
||||||
|
end
|
||||||
|
return args
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -42,7 +68,7 @@ class V8::Conversion
|
||||||
def intercept(info, key, &block)
|
def intercept(info, key, &block)
|
||||||
context = V8::Context.current
|
context = V8::Context.current
|
||||||
access = context.access
|
access = context.access
|
||||||
object = info.Data().Value()
|
object = context.to_ruby(info.This())
|
||||||
handles_property = true
|
handles_property = true
|
||||||
dontintercept = proc do
|
dontintercept = proc do
|
||||||
handles_property = false
|
handles_property = false
|
||||||
|
|
Loading…
Add table
Reference in a new issue