mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
DRY up array conversion
This commit is contained in:
parent
3b2a94d99d
commit
eb9b7b7490
2 changed files with 14 additions and 4 deletions
|
@ -1,4 +1,15 @@
|
|||
class V8::Array < V8::Object
|
||||
|
||||
def initialize(native_or_length = nil)
|
||||
if native_or_length.is_a?(Numeric)
|
||||
super V8::C::Array::New(native.to_i)
|
||||
elsif native_or_length.is_a?(V8::C::Array)
|
||||
super native_or_length
|
||||
else
|
||||
super V8::C::Array::New()
|
||||
end
|
||||
end
|
||||
|
||||
def each
|
||||
@context.enter do
|
||||
0.upto(@native.Length() - 1) do |i|
|
||||
|
|
|
@ -64,12 +64,11 @@ end
|
|||
|
||||
class Array
|
||||
def to_v8
|
||||
context = V8::Context.current
|
||||
array = V8::C::Array::New(length)
|
||||
array = V8::Array.new(length)
|
||||
each_with_index do |item, i|
|
||||
array.Set(i, context.to_v8(item))
|
||||
array[i] = item
|
||||
end
|
||||
return array
|
||||
return array.to_v8
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue