2012-05-17 10:30:37 -05:00
|
|
|
#include "rr.h"
|
|
|
|
|
|
|
|
namespace rr {
|
|
|
|
void Template::Init() {
|
|
|
|
ClassBuilder("Template");
|
2012-05-17 22:03:34 -05:00
|
|
|
ObjectTemplate::Init();
|
2012-05-17 10:30:37 -05:00
|
|
|
FunctionTemplate::Init();
|
|
|
|
}
|
|
|
|
|
2012-05-17 22:03:34 -05:00
|
|
|
void ObjectTemplate::Init() {
|
|
|
|
ClassBuilder("ObjectTemplate", "Template").
|
|
|
|
store(&Class);
|
|
|
|
}
|
|
|
|
|
2012-05-17 10:30:37 -05:00
|
|
|
void FunctionTemplate::Init() {
|
|
|
|
ClassBuilder("FunctionTemplate", "Template").
|
2012-05-21 12:22:07 -05:00
|
|
|
defineSingletonMethod("New", &New).
|
|
|
|
defineMethod("GetFunction", &GetFunction).
|
|
|
|
defineMethod("SetCallHandler", &SetCallHandler).
|
|
|
|
defineMethod("InstanceTemplate", &InstanceTemplate).
|
|
|
|
defineMethod("Inherit", &Inherit).
|
|
|
|
defineMethod("PrototypeTemplate", &PrototypeTemplate).
|
|
|
|
defineMethod("SetClassName", &SetClassName).
|
|
|
|
defineMethod("SetHiddenPrototype", &SetHiddenPrototype).
|
|
|
|
defineMethod("ReadOnlyPrototype", &ReadOnlyPrototype).
|
|
|
|
defineMethod("HasInstance", &HasInstance).
|
2012-05-17 10:30:37 -05:00
|
|
|
store(&Class);
|
|
|
|
}
|
2012-05-17 22:03:34 -05:00
|
|
|
|
|
|
|
VALUE FunctionTemplate::New(int argc, VALUE argv[], VALUE self) {
|
|
|
|
VALUE code; VALUE data; VALUE signature;
|
|
|
|
rb_scan_args(argc, argv, "03", &code, &data, &signature);
|
2012-05-21 12:22:07 -05:00
|
|
|
if (RTEST(code)) {
|
|
|
|
Invocation invocation(code, data);
|
|
|
|
return FunctionTemplate(v8::FunctionTemplate::New(invocation, invocation, Signature(signature)));
|
|
|
|
} else {
|
|
|
|
return FunctionTemplate(v8::FunctionTemplate::New());
|
|
|
|
}
|
2012-05-17 22:03:34 -05:00
|
|
|
}
|
|
|
|
|
2012-05-21 12:22:07 -05:00
|
|
|
VALUE FunctionTemplate::GetFunction(VALUE self) {
|
|
|
|
return Function(FunctionTemplate(self)->GetFunction());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::SetCallHandler(int argc, VALUE argv[], VALUE self) {
|
|
|
|
VALUE code; VALUE data;
|
|
|
|
rb_scan_args(argc, argv, "11", &code, &data);
|
|
|
|
Invocation invocation(code, data);
|
|
|
|
Void(FunctionTemplate(self)->SetCallHandler(invocation, invocation));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::InstanceTemplate(VALUE self) {
|
|
|
|
return ObjectTemplate(FunctionTemplate(self)->InstanceTemplate());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::Inherit(VALUE self, VALUE parent) {
|
|
|
|
Void(FunctionTemplate(self)->Inherit(FunctionTemplate(parent)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::PrototypeTemplate(VALUE self) {
|
|
|
|
return ObjectTemplate(FunctionTemplate(self)->PrototypeTemplate());
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::SetClassName(VALUE self, VALUE name) {
|
|
|
|
Void(FunctionTemplate(self)->SetClassName(String(name)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::SetHiddenPrototype(VALUE self, VALUE value) {
|
|
|
|
Void(FunctionTemplate(self)->SetHiddenPrototype(Bool(value)));
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE FunctionTemplate::ReadOnlyPrototype(VALUE self) {
|
|
|
|
Void(FunctionTemplate(self)->ReadOnlyPrototype());
|
|
|
|
}
|
2012-05-17 22:03:34 -05:00
|
|
|
|
2012-05-21 12:22:07 -05:00
|
|
|
VALUE FunctionTemplate::HasInstance(VALUE self, VALUE object) {
|
|
|
|
return Bool(FunctionTemplate(self)->HasInstance(Value(object)));
|
|
|
|
}
|
2012-05-17 10:30:37 -05:00
|
|
|
}
|