From fea99b72bd6783da570400f25730b76e7e0e44c2 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 26 May 2010 10:49:53 +0300 Subject: [PATCH] expose global scope as an attribute on context. Add Array#length. kinda useful :) --- lib/v8/array.rb | 4 ++++ lib/v8/context.rb | 12 ++---------- lib/v8/function.rb | 6 ++++-- spec/redjs | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/v8/array.rb b/lib/v8/array.rb index 2d0dc09..fe681f0 100644 --- a/lib/v8/array.rb +++ b/lib/v8/array.rb @@ -7,5 +7,9 @@ module V8 yield To.ruby(@native.Get(i)) end end + + def length + @native.Length() + end end end \ No newline at end of file diff --git a/lib/v8/context.rb b/lib/v8/context.rb index d7e27b7..b4cfed1 100644 --- a/lib/v8/context.rb +++ b/lib/v8/context.rb @@ -51,19 +51,11 @@ module V8 end def [](key) - open do - To.ruby(@native.Global().Get(key.to_s)) - end + @scope[key] end def []=(key, value) - value.tap do - open do - @native.Global().tap do |scope| - scope.Set(To.v8(key.to_s), To.v8(value)) - end - end - end + @scope[key] = value end def self.open(opts = {}, &block) diff --git a/lib/v8/function.rb b/lib/v8/function.rb index 5ad3394..fac784d 100644 --- a/lib/v8/function.rb +++ b/lib/v8/function.rb @@ -2,8 +2,10 @@ module V8 class Function < V8::Object def call(thisObject, *args) - this = To.v8(thisObject) - To.ruby(@native.Call(this, *args.map {|a| To.v8(a)})) + @context.enter do + this = To.v8(thisObject) + To.ruby(@native.Call(this, *args.map {|a| To.v8(a)})) + end end end diff --git a/spec/redjs b/spec/redjs index b31ad73..633cd07 160000 --- a/spec/redjs +++ b/spec/redjs @@ -1 +1 @@ -Subproject commit b31ad73b452ca016898bed475c896e2f741d8f82 +Subproject commit 633cd074545563a2bb362c97bbc758de6b7710d1