Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use global context by default when invoking a fn.

  • Loading branch information...
commit 2da238aa94000c6a6d4f571030052fb4c7403a3c 1 parent da11a11
@cowboyd authored
Showing with 11 additions and 0 deletions.
  1. +2 −0  lib/v8/function.rb
  2. +9 −0 spec/v8/function_spec.rb
View
2  lib/v8/function.rb
@@ -1,5 +1,6 @@
class V8::Function < V8::Object
include V8::Error::Try
+
def initialize(native = nil)
super do
native || V8::C::FunctionTemplate::New().GetFunction()
@@ -8,6 +9,7 @@ def initialize(native = nil)
def methodcall(this, *args)
@context.enter do
+ this ||= @context.native.Global()
@context.to_ruby try {native.Call(@context.to_v8(this), args.map {|a| @context.to_v8 a})}
end
end
View
9 spec/v8/function_spec.rb
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe V8::Function do
+ it "uses the global context if it is invoked with nil as the context" do
+ @cxt = V8::Context.new
+ @cxt['foo'] = 'bar'
+ @cxt.eval('(function() {return this.foo})').methodcall(nil).should eql 'bar'
+ end
+end

0 comments on commit 2da238a

Please sign in to comment.
Something went wrong with that request. Please try again.