1
0
Fork 0
mirror of https://github.com/rubyjs/therubyracer synced 2023-03-27 23:21:42 -04:00

move funcalls into their own module

This commit is contained in:
Charles Lowell 2010-05-17 14:39:29 +03:00
parent 597b840997
commit 9ef1695abd
4 changed files with 17 additions and 4 deletions

View file

@ -2,6 +2,7 @@
#include "v8_value.h"
#include "v8_obj.h"
#include "v8_func.h"
#include "v8_array.h"
#include "v8_str.h"
using namespace v8;

View file

@ -19,7 +19,19 @@ namespace {
rb_scan_args(argc, argv, "1*", &recv, &f_argv);
Local<Function> function = V8_Ref_Get<Function>(self);
Local<Object> thisObject = V8_Ref_Get<Object>(recv);
Local<Object> thisObject;
if (NIL_P(recv)) {
if (Context::InContext()) {
thisObject = Context::GetEntered()->Global();
} else {
Persistent<Context> cxt = Context::New();
Context::Scope scope(cxt);
thisObject = cxt->Global();
cxt.Dispose();
}
} else {
thisObject = V8_Ref_Get<Object>(recv);
}
int f_argc = argc - 1;
Local<Value> arguments[f_argc];
for (int i = 0; i < f_argc; i++) {

View file

@ -6,7 +6,7 @@ module V8
case value
when V8::C::Function then V8::Function.new(value)
when V8::C::Object then V8::Object.new(value)
when V8::C::String then "Wonkers!"
when V8::C::String then value.Utf8Value()
else
value
end

View file

@ -6,7 +6,7 @@ describe C::Function do
it "is callable" do
C::Context.new.open do |cxt|
f = cxt.eval('(function() {return "Hello World"})', '<eval>');
f.Call(cxt.Global).should == "Hello World"
f.Call(cxt.Global).AsciiValue().should == "Hello World"
end
end
@ -37,6 +37,6 @@ describe C::Function do
C::Context.new.open do |cxt|
@f = cxt.eval('(function() {return "Call Me"})', 'eval')
end
@f.Call(nil).should == "Call Me"
@f.Call(nil).Utf8Value().should == "Call Me"
end
end