mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
expose SetCallAsFunctionHandler() to ObjectTemplate
This commit is contained in:
parent
a262281ff4
commit
adc0597451
2 changed files with 19 additions and 7 deletions
|
@ -14,12 +14,14 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Compile(VALUE self, VALUE source, VALUE source_name) {
|
VALUE Compile(VALUE self, VALUE source, VALUE source_name) {
|
||||||
|
HandleScope scope;
|
||||||
Local<String> src(rr_rb2v8(source)->ToString());
|
Local<String> src(rr_rb2v8(source)->ToString());
|
||||||
Local<String> src_name(rr_rb2v8(source_name)->ToString());
|
Local<String> src_name(rr_rb2v8(source_name)->ToString());
|
||||||
return rr_v8_ref_create(self, Script::Compile(src, src_name));
|
return rr_v8_ref_create(self, Script::Compile(src, src_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Run(VALUE self) {
|
VALUE Run(VALUE self) {
|
||||||
|
HandleScope scope;
|
||||||
Local<Script> script(V8_Ref_Get<Script>(self));
|
Local<Script> script(V8_Ref_Get<Script>(self));
|
||||||
Local<Value> result(script->Run());
|
Local<Value> result(script->Run());
|
||||||
return result.IsEmpty() ? Qnil : rr_v82rb(result);
|
return result.IsEmpty() ? Qnil : rr_v82rb(result);
|
||||||
|
|
|
@ -38,6 +38,13 @@ namespace {
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<Value> RubyInvocationCallback(const Arguments& args) {
|
||||||
|
VALUE code = (VALUE)External::Unwrap(args.Data());
|
||||||
|
VALUE rb_args = rr_v82rb(args);
|
||||||
|
VALUE result = rb_funcall(code, rb_intern("call"), 1, rb_args);
|
||||||
|
return rr_rb2v8(result);
|
||||||
|
}
|
||||||
|
|
||||||
namespace Obj {
|
namespace Obj {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,17 +245,19 @@ namespace {
|
||||||
);
|
);
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
VALUE SetCallAsFunctionHandler(VALUE self) {
|
||||||
|
HandleScope scope;
|
||||||
|
VALUE code = rb_block_proc();
|
||||||
|
if (NIL_P(code)) {
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
|
obj(self)->SetCallAsFunctionHandler(RubyInvocationCallback, rr_v8_external_create(code));
|
||||||
|
return Qnil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Func {
|
namespace Func {
|
||||||
|
|
||||||
Handle<Value> RubyInvocationCallback(const Arguments& args) {
|
|
||||||
VALUE code = (VALUE)External::Unwrap(args.Data());
|
|
||||||
VALUE rb_args = rr_v82rb(args);
|
|
||||||
VALUE result = rb_funcall(code, rb_intern("call"), 1, rb_args);
|
|
||||||
return rr_rb2v8(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE New(VALUE function_template) {
|
VALUE New(VALUE function_template) {
|
||||||
HandleScope handles;
|
HandleScope handles;
|
||||||
VALUE code = rb_block_proc();
|
VALUE code = rb_block_proc();
|
||||||
|
@ -307,6 +316,7 @@ void rr_init_template() {
|
||||||
rr_define_method(ObjectTemplateClass, "NewInstance", Obj::NewInstance, 0);
|
rr_define_method(ObjectTemplateClass, "NewInstance", Obj::NewInstance, 0);
|
||||||
rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 5);
|
rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 5);
|
||||||
rr_define_method(ObjectTemplateClass, "SetIndexedPropertyHandler", Obj::SetIndexedPropertyHandler, 5);
|
rr_define_method(ObjectTemplateClass, "SetIndexedPropertyHandler", Obj::SetIndexedPropertyHandler, 5);
|
||||||
|
rr_define_method(ObjectTemplateClass, "SetCallAsFunctionHandler", Obj::SetCallAsFunctionHandler, 0);
|
||||||
|
|
||||||
FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
|
FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
|
||||||
rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, 0);
|
rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, 0);
|
||||||
|
|
Loading…
Reference in a new issue