further simplify reference construction.

References no longer require an explicit call to
::convert(). They can be created in a call to the
constructor.
This commit is contained in:
Charles Lowell 2012-05-15 12:23:06 -05:00
parent 356b47a86f
commit 5a35c2bcd5
8 changed files with 22 additions and 18 deletions

View File

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

View File

@ -40,15 +40,15 @@ VALUE Context::ReattachGlobal(VALUE self, VALUE global) {
}
VALUE Context::GetEntered(VALUE self) {
return Context::create(v8::Context::GetEntered());
return Context(v8::Context::GetEntered());
}
VALUE Context::GetCurrent(VALUE self) {
return Context::create(v8::Context::GetCurrent());
return Context(v8::Context::GetCurrent());
}
VALUE Context::GetCalling(VALUE self) {
return Context::create(v8::Context::GetCalling());
return Context(v8::Context::GetCalling());
}
VALUE Context::SetSecurityToken(VALUE self, VALUE token) {
@ -93,9 +93,9 @@ 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);
Context reference(context);
context.Dispose();
return ref;
return reference;
}
VALUE Context::Enter(VALUE self) {

View File

@ -28,7 +28,7 @@ VALUE Convert(v8::Handle<v8::Value> value) {
return rb_float_new(value->NumberValue());
}
if (value->IsString()) {
return String::create(value->ToString());
return String(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::create(value->ToObject());
return Object(value->ToObject());
}
return Qnil;
}

View File

@ -9,7 +9,7 @@ void External::Init() {
store(&Class);
}
VALUE External::New(VALUE self, VALUE data) {
return External::create(wrap(data));
return External(wrap(data));
}
v8::Handle<v8::External> External::wrap(VALUE data) {

View File

@ -28,7 +28,7 @@ void Object::Init() {
VALUE Object::New(VALUE self) {
return Object::create(v8::Object::New());
return Object(v8::Object::New());
}
//TODO: Allow setting of property attributes

View File

@ -57,15 +57,15 @@ public:
Data_Get_Struct(wrapper, class Holder, holder) ;
this->holder = holder;
}
Ref<T>(v8::Handle<T> handle) {
this->holder = new Holder(handle, Class);
}
virtual operator VALUE() {
return holder->value;
}
virtual operator v8::Handle<T>() {
return holder->handle;
}
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;}
@ -139,15 +139,17 @@ public:
static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
inline Context(VALUE value) : Ref<v8::Context>(value) {}
inline Context(v8::Handle<v8::Context> cxt) : Ref<v8::Context>(cxt) {}
};
class External: public Ref<v8::External> {
public:
inline External(VALUE value) : Ref<v8::External>(value) {}
static void Init();
static VALUE New(VALUE self, VALUE data);
static VALUE Value(VALUE self);
inline External(VALUE value) : Ref<v8::External>(value) {}
inline External(v8::Handle<v8::External> ext) : Ref<v8::External>(ext) {}
static v8::Handle<v8::External> wrap(VALUE data);
static VALUE unwrap(v8::Handle<v8::External> external);
private:
@ -165,8 +167,8 @@ public:
static VALUE New(VALUE klass, VALUE source, VALUE filename);
static VALUE Run(VALUE self);
private:
inline Script(VALUE value) : Ref<v8::Script>(value) {}
inline Script(v8::Handle<v8::Script> script) : Ref<v8::Script>(script) {}
};
class Value : public Ref<v8::Value> {
@ -185,6 +187,7 @@ public:
static VALUE Concat(VALUE self, VALUE left, VALUE right);
inline String(VALUE value) : Ref<v8::String>(value) {}
inline String(v8::Handle<v8::String> string) : Ref<v8::String>(string) {}
};
class PropertyAttribute: public Enum<v8::PropertyAttribute> {
@ -250,6 +253,7 @@ public:
static VALUE SetAccessor(int argc, VALUE* argv, VALUE self);
inline Object(VALUE value) : Ref<v8::Object>(value) {}
inline Object(v8::Handle<v8::Object> object) : Ref<v8::Object>(object) {}
};
class V8 {

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)));
return Script(v8::Script::New(String(source), Value(filename)));
}
VALUE Script::Run(VALUE self) {

View File

@ -11,7 +11,7 @@ void String::Init() {
}
VALUE String::New(VALUE StringClass, VALUE string) {
return String::create(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
return String(v8::String::New(RSTRING_PTR(string), (int)RSTRING_LEN(string)));
}
VALUE String::Utf8Value(VALUE self) {