diff --git a/lib/v8/conversion.rb b/lib/v8/conversion.rb index fc15e71..9751738 100644 --- a/lib/v8/conversion.rb +++ b/lib/v8/conversion.rb @@ -69,7 +69,7 @@ end class Hash def to_v8 - object = V8::Object.new(V8::C::Object::New()) + object = V8::Object.new each do |key, value| object[key] = value end diff --git a/lib/v8/object.rb b/lib/v8/object.rb index fdbe628..9f72aed 100644 --- a/lib/v8/object.rb +++ b/lib/v8/object.rb @@ -2,9 +2,9 @@ class V8::Object include Enumerable attr_reader :native - def initialize(native) - @native = native - @context = V8::Context.current + def initialize(native = nil) + @context = V8::Context.current or fail "tried to initialize a #{self.class} without being in an entered V8::Context" + @native = native || V8::C::Object::New() end def [](key)