diff --git a/lib/v8/context.rb b/lib/v8/context.rb index 6f3bcd5..211fa12 100644 --- a/lib/v8/context.rb +++ b/lib/v8/context.rb @@ -19,6 +19,29 @@ module V8 yield self if block_given? end + def eval(source, filename = '', line = 1) + if IO === source || StringIO === source + source = source.read + end + enter do + script = try { V8::C::Script::New(source.to_s, filename.to_s) } + to_ruby try {script.Run()} + end + end + + def [](key) + enter do + to_ruby(@native.Global().Get(to_v8(key))) + end + end + + def []=(key, value) + enter do + @native.Global().Set(to_v8(key), to_v8(value)) + end + return value + end + def scope enter { to_ruby @native.Global() } end @@ -81,30 +104,5 @@ module V8 self.eval file, filename end end - - def eval(source, filename = '', line = 1) - if IO === source || StringIO === source - source = source.read - end - enter do - source = V8::C::String::New(source.to_s) - filename = V8::C::String::New(filename.to_s) - script = try { V8::C::Script::New(source, filename) } - to_ruby try {script.Run()} - end - end - - def []=(key, value) - enter do - @native.Global().Set(to_v8(key), to_v8(value)) - end - return value - end - - def [](key) - enter do - to_ruby(@native.Global().Get(to_v8(key))) - end - end end end \ No newline at end of file