-
Notifications
You must be signed in to change notification settings - Fork 193
Implement methods for Template, FunctionTemplate & ObjectTemplate #385
base: upgrade-to-v8-4.5
Are you sure you want to change the base?
Changes from 2 commits
4dc7ce4
4819b3e
6b1460d
7f5b890
5bd7bc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include "rr.h" | ||
|
|
||
| namespace rr { | ||
| VALUE AccessorSignature::New(int argc, VALUE argv[], VALUE self) { | ||
| VALUE r_isolate; | ||
| VALUE r_receiver; | ||
| rb_scan_args(argc, argv, "11", &r_isolate, &r_receiver); | ||
|
|
||
| Isolate isolate(r_isolate); | ||
| Locker lock(isolate); | ||
| return AccessorSignature(isolate, v8::AccessorSignature::New(isolate, FunctionTemplate(r_receiver))); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // -*- mode: c++ -*- | ||
| #ifndef RR_ACCESSOR_SIGNATURE_H | ||
| #define RR_ACCESSOR_SIGNATURE_H | ||
|
|
||
| namespace rr { | ||
| class AccessorSignature : public Ref<v8::AccessorSignature> { | ||
| public: | ||
| AccessorSignature(VALUE self) : Ref<v8::AccessorSignature>(self) {} | ||
| AccessorSignature(v8::Isolate* i, v8::Local<v8::AccessorSignature> s) : | ||
| Ref<v8::AccessorSignature>(i, s) {} | ||
|
|
||
| static void Init() { | ||
| ClassBuilder("AccessorSignature"). | ||
| defineSingletonMethod("New", &New). | ||
| store(&Class); | ||
| } | ||
|
|
||
| static VALUE New(int argc, VALUE argv[], VALUE self); | ||
| }; | ||
| } | ||
|
|
||
| #endif /* RR_ACCESSOR_SIGNATURE_H */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| #define RR_OBJECT_TEMPLATE_H | ||
|
|
||
| namespace rr { | ||
| class ObjectTemplate : Ref<v8::ObjectTemplate> { | ||
| class ObjectTemplate : public Ref<v8::ObjectTemplate> { | ||
| public: | ||
| ObjectTemplate(VALUE self) : Ref<v8::ObjectTemplate>(self) {} | ||
| ObjectTemplate(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> tmpl) : | ||
|
|
@@ -13,6 +13,11 @@ namespace rr { | |
| ClassBuilder("ObjectTemplate", Template::Class). | ||
| defineSingletonMethod("New", &New). | ||
| defineMethod("NewInstance", &NewInstance). | ||
| defineMethod("SetAccessor", &SetAccessor). | ||
| defineMethod("SetNamedPropertyHandler", &SetNamedPropertyHandler). | ||
| defineMethod("SetIndexedPropertyHandler", &SetIndexedPropertyHandler). | ||
| defineMethod("SetCallAsFunctionHandler", &SetCallAsFunctionHandler). | ||
| defineMethod("InternalFieldCount", &InternalFieldCount). | ||
| defineMethod("SetInternalFieldCount", &SetInternalFieldCount). | ||
| store(&Class); | ||
| } | ||
|
|
@@ -35,6 +40,13 @@ namespace rr { | |
| return Object::Maybe(isolate, t->NewInstance(context)); | ||
| } | ||
|
|
||
| static VALUE InternalFieldCount(VALUE self) { | ||
| ObjectTemplate t(self); | ||
| Locker lock(t); | ||
|
|
||
| return INT2NUM(t->InternalFieldCount()); | ||
| } | ||
|
|
||
| static VALUE SetInternalFieldCount(VALUE self, VALUE value) { | ||
| ObjectTemplate t(self); | ||
| Locker lock(t); | ||
|
|
@@ -43,6 +55,88 @@ namespace rr { | |
|
|
||
| return Qnil; | ||
| } | ||
|
|
||
| static VALUE SetAccessor(int argc, VALUE argv[], VALUE self) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused about which method we're going to call here and why. The way it is written it looks like it will invoke the C++ method that takes
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, The "Name" one seemed like a better choice because we already have these types of accessor callbacks implemented and it is more generic. The documentation doesn't seem to suggest they have different codepaths and I think the String one may be the older of the two. |
||
| VALUE r_name, r_getter, r_setter, r_data, r_settings, r_attribute, r_signature; | ||
| rb_scan_args( | ||
| argc, argv, "25", | ||
| &r_name, &r_getter, &r_setter, &r_data, &r_settings, &r_attribute, &r_signature | ||
| ); | ||
|
|
||
| ObjectTemplate t(self); | ||
| Isolate isolate(t.getIsolate()); | ||
| Locker lock(isolate); | ||
|
|
||
| t->SetAccessor( | ||
| *Name(r_name), | ||
| &PropertyCallback::invokeGetter, | ||
| RTEST(r_setter) ? &PropertyCallback::invokeSetter : 0, | ||
| PropertyCallback::wrapData(isolate, r_getter, r_setter, r_data), | ||
| Enum<v8::AccessControl>(r_settings, v8::DEFAULT), | ||
| Enum<v8::PropertyAttribute>(r_attribute, v8::None), | ||
| AccessorSignature(r_signature) | ||
| ); | ||
|
|
||
| return Qnil; | ||
| } | ||
|
|
||
| static VALUE SetNamedPropertyHandler(int argc, VALUE argv[], VALUE self) { | ||
| VALUE r_getter, r_setter, r_query, r_deleter, r_enumerator, r_data; | ||
| rb_scan_args( | ||
| argc, argv, "15", | ||
| &r_getter, &r_setter, &r_query, &r_deleter, &r_enumerator, &r_data | ||
| ); | ||
|
|
||
| ObjectTemplate t(self); | ||
| Isolate isolate(t.getIsolate()); | ||
| Locker lock(isolate); | ||
|
|
||
| t->SetNamedPropertyHandler( | ||
| &PropertyCallback::invokeNamedPropertyGetter, | ||
| RTEST(r_setter) ? &PropertyCallback::invokeNamedPropertySetter : 0, | ||
| RTEST(r_query) ? &PropertyCallback::invokeNamedPropertyQuery : 0, | ||
| RTEST(r_deleter) ? &PropertyCallback::invokeNamedPropertyDeleter : 0, | ||
| RTEST(r_enumerator) ? &PropertyCallback::invokeNamedPropertyEnumerator : 0, | ||
| PropertyCallback::wrapData(isolate, r_getter, r_setter, r_query, r_deleter, r_enumerator, r_data) | ||
| ); | ||
|
|
||
| return Qnil; | ||
| } | ||
|
|
||
| static VALUE SetIndexedPropertyHandler(int argc, VALUE argv[], VALUE self) { | ||
| VALUE r_getter, r_setter, r_query, r_deleter, r_enumerator, r_data; | ||
| rb_scan_args( | ||
| argc, argv, "15", | ||
| &r_getter, &r_setter, &r_query, &r_deleter, &r_enumerator, &r_data | ||
| ); | ||
|
|
||
| ObjectTemplate t(self); | ||
| Isolate isolate(t.getIsolate()); | ||
| Locker lock(isolate); | ||
|
|
||
| t->SetIndexedPropertyHandler( | ||
| &PropertyCallback::invokeIndexedPropertyGetter, | ||
| RTEST(r_setter) ? &PropertyCallback::invokeIndexedPropertySetter : 0, | ||
| RTEST(r_query) ? &PropertyCallback::invokeIndexedPropertyQuery : 0, | ||
| RTEST(r_deleter) ? &PropertyCallback::invokeIndexedPropertyDeleter : 0, | ||
| RTEST(r_enumerator) ? &PropertyCallback::invokeIndexedPropertyEnumerator : 0, | ||
| PropertyCallback::wrapData(isolate, r_getter, r_setter, r_query, r_deleter, r_enumerator, r_data) | ||
| ); | ||
|
|
||
| return Qnil; | ||
| } | ||
|
|
||
| static VALUE SetCallAsFunctionHandler(VALUE self, VALUE r_callback, VALUE r_data) { | ||
| ObjectTemplate t(self); | ||
| Isolate isolate(t.getIsolate()); | ||
| Locker lock(isolate); | ||
|
|
||
| FunctionCallback callback(isolate, r_callback, r_data); | ||
|
|
||
| t->SetCallAsFunctionHandler(callback, callback); | ||
|
|
||
| return Qnil; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,81 @@ namespace rr { | |
|
|
||
| }; | ||
|
|
||
| class Integer : public Base<v8::Integer> { | ||
| public: | ||
|
|
||
| inline Integer(v8::PropertyCallbackInfo<v8::Integer> info) : | ||
| Base<v8::Integer>(info) {} | ||
|
|
||
| inline Integer(VALUE self) : Base<v8::Integer>(self) {} | ||
|
|
||
| static VALUE GetReturnValue(VALUE self) { | ||
| Integer info(self); | ||
| Locker lock(info->GetIsolate()); | ||
| return ReturnValue::Integer(info->GetReturnValue()); | ||
| } | ||
|
|
||
| static inline void Init() { | ||
| ClassBuilder("Integer", PropertyCallbackInfo::Class, PropertyCallbackInfo::Class). | ||
| defineMethod("This", &This). | ||
| defineMethod("Data", &Data). | ||
| defineMethod("GetIsolate", &GetIsolate). | ||
| defineMethod("GetReturnValue", &GetReturnValue). | ||
| store(&Class); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| class Array : public Base<v8::Array> { | ||
| public: | ||
|
|
||
| inline Array(v8::PropertyCallbackInfo<v8::Array> info) : | ||
| Base<v8::Array>(info) {} | ||
|
|
||
| inline Array(VALUE self) : Base<v8::Array>(self) {} | ||
|
|
||
| static VALUE GetReturnValue(VALUE self) { | ||
| Array info(self); | ||
| Locker lock(info->GetIsolate()); | ||
| return ReturnValue::Array(info->GetReturnValue()); | ||
| } | ||
|
|
||
| static inline void Init() { | ||
| ClassBuilder("Array", PropertyCallbackInfo::Class, PropertyCallbackInfo::Class). | ||
| defineMethod("This", &This). | ||
| defineMethod("Data", &Data). | ||
| defineMethod("GetIsolate", &GetIsolate). | ||
| defineMethod("GetReturnValue", &GetReturnValue). | ||
| store(&Class); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| class Boolean : public Base<v8::Boolean> { | ||
| public: | ||
|
|
||
| inline Boolean(v8::PropertyCallbackInfo<v8::Boolean> info) : | ||
| Base<v8::Boolean>(info) {} | ||
|
|
||
| inline Boolean(VALUE self) : Base<v8::Boolean>(self) {} | ||
|
|
||
| static VALUE GetReturnValue(VALUE self) { | ||
| Boolean info(self); | ||
| Locker lock(info->GetIsolate()); | ||
| return ReturnValue::Boolean(info->GetReturnValue()); | ||
| } | ||
|
|
||
| static inline void Init() { | ||
| ClassBuilder("Boolean", PropertyCallbackInfo::Class, PropertyCallbackInfo::Class). | ||
| defineMethod("This", &This). | ||
| defineMethod("Data", &Data). | ||
| defineMethod("GetIsolate", &GetIsolate). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will do that.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, actually, is it safe to do that? Since outside of C++ these are all different classes and depending on the template parameter, they wrap different types and pointers.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, you're totally right, they share no common ancestor in c++ land. |
||
| defineMethod("GetReturnValue", &GetReturnValue). | ||
| store(&Class); | ||
| } | ||
|
|
||
| }; | ||
|
|
||
| class Void : public Base<void> { | ||
| public: | ||
|
|
||
|
|
@@ -94,6 +169,9 @@ namespace rr { | |
| store(&Class); | ||
|
|
||
| Value::Init(); | ||
| Integer::Init(); | ||
| Array::Init(); | ||
| Boolean::Init(); | ||
| Void::Init(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use the
Intequiv here.