1
0
Fork 0
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:
Charles Lowell 2012-05-15 11:46:14 -05:00
parent 1e6afe7484
commit 356b47a86f
8 changed files with 16 additions and 42 deletions

View file

@ -13,8 +13,8 @@ namespace rr {
}
Accessor::Accessor(const v8::AccessorInfo& info) {
this->thisObject = Object::wrap(info.This());
this->holder = Object::wrap(info.Holder());
this->thisObject = Object::create(info.This());
this->holder = Object::create(info.Holder());
this->value = Data_Wrap_Struct(Class, &mark, &sweep, this);
this->info = new Info(info.Data());
}

View file

@ -2,8 +2,6 @@
namespace rr {
VALUE Context::Class;
void Context::Init() {
ClassBuilder("Context").
defineSingletonMethod("New", &New).
@ -42,15 +40,15 @@ VALUE Context::ReattachGlobal(VALUE self, VALUE global) {
}
VALUE Context::GetEntered(VALUE self) {
return Context::create(v8::Context::GetEntered(), Class);
return Context::create(v8::Context::GetEntered());
}
VALUE Context::GetCurrent(VALUE self) {
return Context::create(v8::Context::GetCurrent(), Class);
return Context::create(v8::Context::GetCurrent());
}
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) {
@ -95,7 +93,7 @@ VALUE Context::IsCodeGenerationFromStringsAllowed(VALUE self) {
VALUE Context::New(VALUE ContextClass) {
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();
return ref;
}

View file

@ -28,7 +28,7 @@ VALUE Convert(v8::Handle<v8::Value> value) {
return rb_float_new(value->NumberValue());
}
if (value->IsString()) {
return String::convert(value->ToString());
return String::create(value->ToString());
}
if (value->IsFunction()) {
// return Function(value);
@ -40,7 +40,7 @@ VALUE Convert(v8::Handle<v8::Value> value) {
// return rr_reflect_v8_date(value);
}
if (value->IsObject()) {
return Object::convert(value->ToObject());
return Object::create(value->ToObject());
}
return Qnil;
}

View file

@ -2,8 +2,6 @@
namespace rr {
VALUE External::Class;
void External::Init() {
ClassBuilder("External", "Value").
defineSingletonMethod("New", &New).
@ -11,7 +9,7 @@ void External::Init() {
store(&Class);
}
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) {

View file

@ -2,8 +2,6 @@
namespace rr {
VALUE Object::Class;
void Object::Init() {
ClassBuilder("Object", "Value").
defineSingletonMethod("New", &New).
@ -28,15 +26,9 @@ void Object::Init() {
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) {
return Object::create(v8::Object::New(), self);
return Object::create(v8::Object::New());
}
//TODO: Allow setting of property attributes

View file

@ -63,8 +63,8 @@ public:
virtual operator v8::Handle<T>() {
return holder->handle;
}
static Ref<T> create(v8::Handle<T> handle, VALUE klass) {
return Ref<T>(new Holder(handle, klass));
static Ref<T> create(v8::Handle<T> handle) {
return Ref<T>(new Holder(handle, Class));
}
inline v8::Handle<T> operator->() const { return holder->handle; }
v8::Handle<T> GetHandle() {return holder->handle;}
@ -92,7 +92,9 @@ public:
this->holder = holder;
};
Holder* holder;
static VALUE Class;
};
template <class T> VALUE Ref<T>::Class;
class Handles {
public:
@ -136,7 +138,6 @@ public:
static VALUE AllowCodeGenerationFromStrings(VALUE self, VALUE allow);
static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
static VALUE Class;
inline Context(VALUE value) : Ref<v8::Context>(value) {}
};
@ -149,7 +150,6 @@ public:
static v8::Handle<v8::External> wrap(VALUE data);
static VALUE unwrap(v8::Handle<v8::External> external);
static VALUE Class;
private:
static void release(v8::Persistent<v8::Value> object, void* parameter);
struct Data {
@ -184,10 +184,7 @@ public:
static VALUE Utf8Value(VALUE self);
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) {}
private:
static VALUE Class;
};
class PropertyAttribute: public Enum<v8::PropertyAttribute> {
@ -252,11 +249,6 @@ public:
static VALUE ForceDelete(VALUE self, VALUE key);
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) {}
};

View file

@ -9,7 +9,7 @@ void Script::Init() {
}
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) {

View file

@ -2,8 +2,6 @@
namespace rr {
VALUE String::Class;
void String::Init() {
ClassBuilder("String", "Value").
defineSingletonMethod("New", &New).
@ -13,7 +11,7 @@ void String::Init() {
}
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) {
@ -25,8 +23,4 @@ VALUE String::Concat(VALUE self, VALUE left, VALUE 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