From 38e8902266eeff34ed5e1588e0969e24540a3c32 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Sat, 16 Jun 2012 12:49:09 -0500 Subject: [PATCH] move most important Context methods to the top --- lib/v8/context.rb | 48 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 25 deletions(-) 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