diff --git a/lib/v8/array.rb b/lib/v8/array.rb index ea17a12..dd445ec 100644 --- a/lib/v8/array.rb +++ b/lib/v8/array.rb @@ -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| diff --git a/lib/v8/conversion.rb b/lib/v8/conversion.rb index b7e3721..377b0a9 100644 --- a/lib/v8/conversion.rb +++ b/lib/v8/conversion.rb @@ -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