mirror of
https://github.com/rubyjs/therubyracer
synced 2023-03-27 23:21:42 -04:00
massively simplify reference creation.
make the template class define the RubyClass for a given reference class. That way, it can define the wrapping logic.
This commit is contained in:
parent
1e6afe7484
commit
356b47a86f
8 changed files with 16 additions and 42 deletions
|
@ -13,8 +13,8 @@ namespace rr {
|
||||||
}
|
}
|
||||||
|
|
||||||
Accessor::Accessor(const v8::AccessorInfo& info) {
|
Accessor::Accessor(const v8::AccessorInfo& info) {
|
||||||
this->thisObject = Object::wrap(info.This());
|
this->thisObject = Object::create(info.This());
|
||||||
this->holder = Object::wrap(info.Holder());
|
this->holder = Object::create(info.Holder());
|
||||||
this->value = Data_Wrap_Struct(Class, &mark, &sweep, this);
|
this->value = Data_Wrap_Struct(Class, &mark, &sweep, this);
|
||||||
this->info = new Info(info.Data());
|
this->info = new Info(info.Data());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace rr {
|
namespace rr {
|
||||||
|
|
||||||
VALUE Context::Class;
|
|
||||||
|
|
||||||
void Context::Init() {
|
void Context::Init() {
|
||||||
ClassBuilder("Context").
|
ClassBuilder("Context").
|
||||||
defineSingletonMethod("New", &New).
|
defineSingletonMethod("New", &New).
|
||||||
|
@ -42,15 +40,15 @@ VALUE Context::ReattachGlobal(VALUE self, VALUE global) {
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Context::GetEntered(VALUE self) {
|
VALUE Context::GetEntered(VALUE self) {
|
||||||
return Context::create(v8::Context::GetEntered(), Class);
|
return Context::create(v8::Context::GetEntered());
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Context::GetCurrent(VALUE self) {
|
VALUE Context::GetCurrent(VALUE self) {
|
||||||
return Context::create(v8::Context::GetCurrent(), Class);
|
return Context::create(v8::Context::GetCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Context::GetCalling(VALUE self) {
|
VALUE Context::GetCalling(VALUE self) {
|
||||||
return Context::create(v8::Context::GetCalling(), Class);
|
return Context::create(v8::Context::GetCalling());
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Context::SetSecurityToken(VALUE self, VALUE token) {
|
VALUE Context::SetSecurityToken(VALUE self, VALUE token) {
|
||||||
|
@ -95,7 +93,7 @@ VALUE Context::IsCodeGenerationFromStringsAllowed(VALUE self) {
|
||||||
|
|
||||||
VALUE Context::New(VALUE ContextClass) {
|
VALUE Context::New(VALUE ContextClass) {
|
||||||
v8::Persistent<v8::Context> context = v8::Context::New();
|
v8::Persistent<v8::Context> context = v8::Context::New();
|
||||||
Ref<v8::Context> ref = Context::create(context, ContextClass);
|
Ref<v8::Context> ref = Context::create(context);
|
||||||
context.Dispose();
|
context.Dispose();
|
||||||
return ref;
|
return ref;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ VALUE Convert(v8::Handle<v8::Value> value) {
|
||||||
return rb_float_new(value->NumberValue());
|
return rb_float_new(value->NumberValue());
|
||||||
}
|
}
|
||||||
if (value->IsString()) {
|
if (value->IsString()) {
|
||||||
return String::convert(value->ToString());
|
return String::create(value->ToString());
|
||||||
}
|
}
|
||||||
if (value->IsFunction()) {
|
if (value->IsFunction()) {
|
||||||
// return Function(value);
|
// return Function(value);
|
||||||
|
@ -40,7 +40,7 @@ VALUE Convert(v8::Handle<v8::Value> value) {
|
||||||
// return rr_reflect_v8_date(value);
|
// return rr_reflect_v8_date(value);
|
||||||
}
|
}
|
||||||
if (value->IsObject()) {
|
if (value->IsObject()) {
|
||||||
return Object::convert(value->ToObject());
|
return Object::create(value->ToObject());
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace rr {
|
namespace rr {
|
||||||
|
|
||||||
VALUE External::Class;
|
|
||||||
|
|
||||||
void External::Init() {
|
void External::Init() {
|
||||||
ClassBuilder("External", "Value").
|
ClassBuilder("External", "Value").
|
||||||
defineSingletonMethod("New", &New).
|
defineSingletonMethod("New", &New).
|
||||||
|
@ -11,7 +9,7 @@ void External::Init() {
|
||||||
store(&Class);
|
store(&Class);
|
||||||
}
|
}
|
||||||
VALUE External::New(VALUE self, VALUE data) {
|
VALUE External::New(VALUE self, VALUE data) {
|
||||||
return External::create(wrap(data), self);
|
return External::create(wrap(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
v8::Handle<v8::External> External::wrap(VALUE data) {
|
v8::Handle<v8::External> External::wrap(VALUE data) {
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace rr {
|
namespace rr {
|
||||||
|
|
||||||
VALUE Object::Class;
|
|
||||||
|
|
||||||
void Object::Init() {
|
void Object::Init() {
|
||||||
ClassBuilder("Object", "Value").
|
ClassBuilder("Object", "Value").
|
||||||
defineSingletonMethod("New", &New).
|
defineSingletonMethod("New", &New).
|
||||||
|
@ -28,15 +26,9 @@ void Object::Init() {
|
||||||
defineEnumConst("PROHIBITS_OVERWRITING", v8::PROHIBITS_OVERWRITING);
|
defineEnumConst("PROHIBITS_OVERWRITING", v8::PROHIBITS_OVERWRITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Object::convert(v8::Handle<v8::Object> object) {
|
|
||||||
return Object::create(object, Class);
|
|
||||||
}
|
|
||||||
VALUE Object::wrap(v8::Handle<v8::Object> object) {
|
|
||||||
return convert(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
VALUE Object::New(VALUE self) {
|
VALUE Object::New(VALUE self) {
|
||||||
return Object::create(v8::Object::New(), self);
|
return Object::create(v8::Object::New());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Allow setting of property attributes
|
//TODO: Allow setting of property attributes
|
||||||
|
|
16
ext/v8/rr.h
16
ext/v8/rr.h
|
@ -63,8 +63,8 @@ public:
|
||||||
virtual operator v8::Handle<T>() {
|
virtual operator v8::Handle<T>() {
|
||||||
return holder->handle;
|
return holder->handle;
|
||||||
}
|
}
|
||||||
static Ref<T> create(v8::Handle<T> handle, VALUE klass) {
|
static Ref<T> create(v8::Handle<T> handle) {
|
||||||
return Ref<T>(new Holder(handle, klass));
|
return Ref<T>(new Holder(handle, Class));
|
||||||
}
|
}
|
||||||
inline v8::Handle<T> operator->() const { return holder->handle; }
|
inline v8::Handle<T> operator->() const { return holder->handle; }
|
||||||
v8::Handle<T> GetHandle() {return holder->handle;}
|
v8::Handle<T> GetHandle() {return holder->handle;}
|
||||||
|
@ -92,7 +92,9 @@ public:
|
||||||
this->holder = holder;
|
this->holder = holder;
|
||||||
};
|
};
|
||||||
Holder* holder;
|
Holder* holder;
|
||||||
|
static VALUE Class;
|
||||||
};
|
};
|
||||||
|
template <class T> VALUE Ref<T>::Class;
|
||||||
|
|
||||||
class Handles {
|
class Handles {
|
||||||
public:
|
public:
|
||||||
|
@ -136,7 +138,6 @@ public:
|
||||||
static VALUE AllowCodeGenerationFromStrings(VALUE self, VALUE allow);
|
static VALUE AllowCodeGenerationFromStrings(VALUE self, VALUE allow);
|
||||||
static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
|
static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
|
||||||
|
|
||||||
static VALUE Class;
|
|
||||||
inline Context(VALUE value) : Ref<v8::Context>(value) {}
|
inline Context(VALUE value) : Ref<v8::Context>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,7 +150,6 @@ public:
|
||||||
|
|
||||||
static v8::Handle<v8::External> wrap(VALUE data);
|
static v8::Handle<v8::External> wrap(VALUE data);
|
||||||
static VALUE unwrap(v8::Handle<v8::External> external);
|
static VALUE unwrap(v8::Handle<v8::External> external);
|
||||||
static VALUE Class;
|
|
||||||
private:
|
private:
|
||||||
static void release(v8::Persistent<v8::Value> object, void* parameter);
|
static void release(v8::Persistent<v8::Value> object, void* parameter);
|
||||||
struct Data {
|
struct Data {
|
||||||
|
@ -184,10 +184,7 @@ public:
|
||||||
static VALUE Utf8Value(VALUE self);
|
static VALUE Utf8Value(VALUE self);
|
||||||
static VALUE Concat(VALUE self, VALUE left, VALUE right);
|
static VALUE Concat(VALUE self, VALUE left, VALUE right);
|
||||||
|
|
||||||
static VALUE convert(v8::Handle<v8::String> value);
|
|
||||||
inline String(VALUE value) : Ref<v8::String>(value) {}
|
inline String(VALUE value) : Ref<v8::String>(value) {}
|
||||||
private:
|
|
||||||
static VALUE Class;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PropertyAttribute: public Enum<v8::PropertyAttribute> {
|
class PropertyAttribute: public Enum<v8::PropertyAttribute> {
|
||||||
|
@ -252,11 +249,6 @@ public:
|
||||||
static VALUE ForceDelete(VALUE self, VALUE key);
|
static VALUE ForceDelete(VALUE self, VALUE key);
|
||||||
static VALUE SetAccessor(int argc, VALUE* argv, VALUE self);
|
static VALUE SetAccessor(int argc, VALUE* argv, VALUE self);
|
||||||
|
|
||||||
static VALUE Class;
|
|
||||||
static VALUE convert(v8::Handle<v8::Object> value);
|
|
||||||
static VALUE wrap(v8::Handle<v8::Object> value);
|
|
||||||
static v8::Handle<v8::Value> getter(v8::Local<v8::String> property, const v8::AccessorInfo& info);
|
|
||||||
static void setter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
|
|
||||||
inline Object(VALUE value) : Ref<v8::Object>(value) {}
|
inline Object(VALUE value) : Ref<v8::Object>(value) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ void Script::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Script::New(VALUE klass, VALUE source, VALUE filename) {
|
VALUE Script::New(VALUE klass, VALUE source, VALUE filename) {
|
||||||
return Script::create(v8::Script::New(String(source), Value(filename)), klass);
|
return Script::create(v8::Script::New(String(source), Value(filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE Script::Run(VALUE self) {
|
VALUE Script::Run(VALUE self) {
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace rr {
|
namespace rr {
|
||||||
|
|
||||||
VALUE String::Class;
|
|
||||||
|
|
||||||
void String::Init() {
|
void String::Init() {
|
||||||
ClassBuilder("String", "Value").
|
ClassBuilder("String", "Value").
|
||||||
defineSingletonMethod("New", &New).
|
defineSingletonMethod("New", &New).
|
||||||
|
@ -13,7 +11,7 @@ void String::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE String::New(VALUE StringClass, VALUE string) {
|
VALUE String::New(VALUE StringClass, VALUE string) {
|
||||||
return String::convert(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
return String::create(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE String::Utf8Value(VALUE self) {
|
VALUE String::Utf8Value(VALUE self) {
|
||||||
|
@ -25,8 +23,4 @@ VALUE String::Concat(VALUE self, VALUE left, VALUE right) {
|
||||||
return Convert(v8::String::Concat(String(left), String(right)));
|
return Convert(v8::String::Concat(String(left), String(right)));
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE String::convert(v8::Handle<v8::String> string) {
|
|
||||||
return String::create(string, Class);
|
|
||||||
}
|
|
||||||
|
|
||||||
} //namespace rr
|
} //namespace rr
|
Loading…
Add table
Reference in a new issue