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
|
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
|
def each
|
||||||
@context.enter do
|
@context.enter do
|
||||||
0.upto(@native.Length() - 1) do |i|
|
0.upto(@native.Length() - 1) do |i|
|
||||||
|
|
|
@ -64,12 +64,11 @@ end
|
||||||
|
|
||||||
class Array
|
class Array
|
||||||
def to_v8
|
def to_v8
|
||||||
context = V8::Context.current
|
array = V8::Array.new(length)
|
||||||
array = V8::C::Array::New(length)
|
|
||||||
each_with_index do |item, i|
|
each_with_index do |item, i|
|
||||||
array.Set(i, context.to_v8(item))
|
array[i] = item
|
||||||
end
|
end
|
||||||
return array
|
return array.to_v8
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue