mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
switch Context, Script to use ClassBuilder
This commit is contained in:
parent
9884c89074
commit
99d225c450
5 changed files with 21 additions and 15 deletions
|
@ -4,7 +4,7 @@ namespace rr {
|
|||
|
||||
VALUE New(VALUE ContextClass) {
|
||||
v8::Persistent<v8::Context> context = v8::Context::New();
|
||||
Ref<v8::Context> ref = Ref<v8::Context>::create(context, ContextClass);
|
||||
Ref<v8::Context> ref = Context::create(context, ContextClass);
|
||||
context.Dispose();
|
||||
return ref;
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ namespace rr {
|
|||
}
|
||||
|
||||
void Context::Init() {
|
||||
VALUE ContextClass = defineClass("Context");
|
||||
RR_DEFINE_SINGLETON_METHOD(ContextClass, "New", &New, 0);
|
||||
RR_DEFINE_METHOD(ContextClass, "Enter", &Enter, 0);
|
||||
RR_DEFINE_METHOD(ContextClass, "Exit", &Exit, 0);
|
||||
ClassBuilder("Context").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Enter", &Enter).
|
||||
defineMethod("Exit", &Exit);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,10 @@ namespace rr {
|
|||
rb_define_method(this->value, name, (VALUE (*)(...))impl, 1);
|
||||
return *this;
|
||||
}
|
||||
ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) {
|
||||
rb_define_method(this->value, name, (VALUE (*)(...))impl, 2);
|
||||
return *this;
|
||||
}
|
||||
ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE)) {
|
||||
rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 0);
|
||||
return *this;
|
||||
|
@ -35,4 +39,9 @@ namespace rr {
|
|||
rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 1);
|
||||
return *this;
|
||||
}
|
||||
ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) {
|
||||
rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 2);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
|
@ -129,18 +129,15 @@ public:
|
|||
ClassBuilder(const char* name, VALUE superclass = rb_cObject);
|
||||
ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE));
|
||||
ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE));
|
||||
ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE));
|
||||
ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE));
|
||||
ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE));
|
||||
ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE));
|
||||
inline operator VALUE() {return this->value;}
|
||||
private:
|
||||
VALUE value;
|
||||
};
|
||||
|
||||
VALUE defineClass(const char *name, VALUE superclass = rb_cObject);
|
||||
VALUE defineModule(const char *name);
|
||||
}
|
||||
|
||||
#define RR_DEFINE_METHOD(klass, name, impl, argc) rb_define_method(klass, name, (VALUE(*)(...))impl, argc)
|
||||
#define RR_DEFINE_SINGLETON_METHOD(object, name, impl, argc) rb_define_singleton_method(object, name, (VALUE(*)(...))impl, argc)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,9 +16,9 @@ VALUE Run(VALUE self) {
|
|||
}
|
||||
|
||||
void Script::Init() {
|
||||
VALUE ScriptClass = defineClass("Script");
|
||||
RR_DEFINE_SINGLETON_METHOD(ScriptClass, "New", &New, 2);
|
||||
RR_DEFINE_METHOD(ScriptClass, "Run", &Run, 0);
|
||||
ClassBuilder("Script").
|
||||
defineSingletonMethod("New", &New).
|
||||
defineMethod("Run", &Run);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@ namespace {
|
|||
}
|
||||
}
|
||||
void V8::Init() {
|
||||
VALUE V8Class = defineClass("V8");
|
||||
RR_DEFINE_SINGLETON_METHOD(V8Class, "IdleNotification", &IdleNotification, 0);
|
||||
ClassBuilder("V8").
|
||||
defineSingletonMethod("IdleNotification", &IdleNotification);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue