mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
use global context by default when invoking a fn.
This commit is contained in:
parent
da11a11987
commit
2da238aa94
2 changed files with 11 additions and 0 deletions
|
@ -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 @@ class V8::Function < V8::Object
|
|||
|
||||
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
|
||||
|
|
9
spec/v8/function_spec.rb
Normal file
9
spec/v8/function_spec.rb
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue