11// -*- mode: c++ -*-
2- #ifndef RR_PROPERTY_CALLBACK_H
3- #define RR_PROPERTY_CALLBACK_H
2+ #ifndef RR_PROPERTY_CALLBACK_INFO_H
3+ #define RR_PROPERTY_CALLBACK_INFO_H
44
55namespace rr {
66
@@ -16,30 +16,6 @@ namespace rr {
1616
1717 inline Base (VALUE self) : Wrapper<v8::PropertyCallbackInfo<T>>(self) {}
1818
19- /* *
20- * Package up the callback data for this object so that it can
21- * invoke Ruby callables.
22- *
23- * Each accessor can have one `v8::Value` associated with it
24- * that is passed to the `SetAccessor` method. To support this
25- * same API from ruby, we take the passed data constructor *and*
26- * the callbacks and store them *both* in a single `v8::Object`
27- * which we use for the C++ level callback data.
28- */
29- static v8::Local<v8::Value> wrapData (v8::Isolate* isolate, VALUE r_getter, VALUE r_setter, VALUE r_data) {
30- v8::Local<v8::Object> holder = v8::Object::New (isolate);
31-
32- v8::Local<v8::String> getter_key = v8::String::NewFromUtf8 (isolate, " rr::getter" );
33- v8::Local<v8::String> setter_key = v8::String::NewFromUtf8 (isolate, " rr::setter" );
34- v8::Local<v8::String> data_key = v8::String::NewFromUtf8 (isolate, " rr::data" );
35-
36- holder->SetHiddenValue (getter_key, External::wrap (isolate, r_getter));
37- holder->SetHiddenValue (setter_key, External::wrap (isolate, r_setter));
38- holder->SetHiddenValue (data_key, rr::Value (r_data));
39-
40- return holder;
41- }
42-
4319 static VALUE This (VALUE self) {
4420 Base<T> info (self);
4521 Locker lock (info->GetIsolate ());
@@ -51,11 +27,7 @@ namespace rr {
5127 Isolate isolate (info->GetIsolate ());
5228 Locker lock (isolate);
5329
54- v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast<v8::Value>(info->Data ());
55- v8::Local<v8::String> data_key = v8::String::NewFromUtf8 (isolate, " rr::data" );
56- v8::Local<v8::Value> data (holder->GetHiddenValue (data_key));
57-
58- return rr::Value::handleToRubyObject (info->GetIsolate (), data);
30+ return PropertyCallback::unwrapData (isolate, info->Data ()) ;
5931 }
6032
6133 static VALUE GetIsolate (VALUE self) {
@@ -73,32 +45,6 @@ namespace rr {
7345
7446 inline Value (VALUE self) : Base<v8::Value>(self) {}
7547
76- /* *
77- * Call the Ruby code associated with this callback.
78- *
79- * Unpack the Ruby code, and the callback data from the C++
80- * callback data, and then invoke that code.
81- *
82- * Note: This function implements the `v8::AccessorNameGetterCallback` API.
83- */
84- static void invoke (v8::Local<v8::Name> property, const v8::PropertyCallbackInfo<v8::Value>& info) {
85- v8::Isolate* isolate = info.GetIsolate ();
86- v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast<v8::Value>(info.Data ());
87- v8::Local<v8::String> callback_key = v8::String::NewFromUtf8 (isolate, " rr::getter" );
88-
89- VALUE code (External::unwrap (holder->GetHiddenValue (callback_key)));
90-
91- VALUE rb_property;
92- if (property->IsSymbol ()) {
93- rb_property = Symbol (isolate, v8::Local<v8::Symbol>::Cast (property));
94- } else {
95- rb_property = String (isolate, property->ToString ());
96- }
97-
98- Unlocker unlock (info.GetIsolate ());
99- rb_funcall (code, rb_intern (" call" ), 2 , rb_property, (VALUE)Value (info));
100- }
101-
10248 static VALUE GetReturnValue (VALUE self) {
10349 Value info (self);
10450 Locker lock (info->GetIsolate ());
@@ -124,38 +70,6 @@ namespace rr {
12470
12571 inline Void (VALUE self) : Base<void>(self) {}
12672
127- /* *
128- * Call the Ruby code associated with this callback.
129- *
130- * Unpack the Ruby code, and the callback data from the C++
131- * callback data, and then invoke that code.
132- *
133- * Note: This function implements the `v8::AccessorNameSetterCallback` API.
134- */
135- static void invoke (v8::Local<v8::Name> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void >& info) {
136- v8::Isolate* isolate = info.GetIsolate ();
137-
138- v8::Local<v8::Object> holder = v8::Local<v8::Object>::Cast<v8::Value>(info.Data ());
139- v8::Local<v8::String> callback_key = v8::String::NewFromUtf8 (isolate, " rr::setter" );
140-
141- VALUE code (External::unwrap (holder->GetHiddenValue (callback_key)));
142-
143- VALUE rb_property;
144- if (property->IsSymbol ()) {
145- rb_property = Symbol (isolate, v8::Local<v8::Symbol>::Cast (property));
146- } else {
147- rb_property = String (isolate, property->ToString ());
148- }
149-
150- Unlocker unlock (info.GetIsolate ());
151- rb_funcall (
152- code, rb_intern (" call" ), 3 ,
153- rb_property,
154- (VALUE)rr::Value::handleToRubyObject (isolate, value),
155- (VALUE)Void (info)
156- );
157- }
158-
15973 static VALUE GetReturnValue (VALUE self) {
16074 Value info (self);
16175 Locker lock (info->GetIsolate ());
@@ -187,4 +101,4 @@ namespace rr {
187101
188102}
189103
190- #endif /* RR_PROPERTY_CALLBACK_H */
104+ #endif /* RR_PROPERTY_CALLBACK_INFO_H */
0 commit comments