therubyracer 0.8.2 → 0.9.0beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of therubyracer might be problematic. Click here for more details.

Files changed (53) hide show
  1. data/Changelog.md +1 -1
  2. data/ext/v8/rr.cpp +14 -7
  3. data/ext/v8/rr.h +1 -0
  4. data/ext/v8/v8.cpp +27 -25
  5. data/ext/v8/v8_array.cpp +7 -9
  6. data/ext/v8/v8_callbacks.cpp +1 -1
  7. data/ext/v8/{v8_cxt.cpp → v8_context.cpp} +11 -11
  8. data/ext/v8/{v8_cxt.h → v8_context.h} +1 -1
  9. data/ext/v8/v8_date.cpp +6 -6
  10. data/ext/v8/v8_exception.cpp +10 -11
  11. data/ext/v8/v8_external.cpp +7 -24
  12. data/ext/v8/v8_external.h +0 -1
  13. data/ext/v8/{v8_func.cpp → v8_function.cpp} +14 -14
  14. data/ext/v8/{v8_func.h → v8_function.h} +1 -2
  15. data/ext/v8/v8_handle.cpp +119 -0
  16. data/ext/v8/v8_handle.h +27 -0
  17. data/ext/v8/{v8_msg.cpp → v8_message.cpp} +8 -9
  18. data/ext/v8/{v8_msg.h → v8_message.h} +1 -1
  19. data/ext/v8/{v8_obj.cpp → v8_object.cpp} +51 -29
  20. data/ext/v8/{v8_obj.h → v8_object.h} +3 -4
  21. data/ext/v8/v8_script.cpp +5 -5
  22. data/ext/v8/{v8_str.cpp → v8_string.cpp} +9 -11
  23. data/ext/v8/{v8_str.h → v8_string.h} +1 -1
  24. data/ext/v8/v8_template.cpp +113 -98
  25. data/ext/v8/v8_try_catch.cpp +1 -1
  26. data/ext/v8/v8_v8.cpp +7 -0
  27. data/ext/v8/v8_value.cpp +44 -36
  28. data/ext/v8/v8_value.h +2 -2
  29. data/ext/v8/v8_weakref.cpp +51 -0
  30. data/ext/v8/v8_weakref.h +30 -0
  31. data/lib/v8.rb +6 -1
  32. data/lib/v8/context.rb +13 -3
  33. data/lib/v8/error.rb +1 -1
  34. data/lib/v8/portal.rb +26 -277
  35. data/lib/v8/portal/caller.rb +36 -0
  36. data/lib/v8/portal/constructor.rb +98 -0
  37. data/lib/v8/portal/function.rb +48 -0
  38. data/lib/v8/portal/interceptors.rb +153 -0
  39. data/lib/v8/portal/proxies.rb +102 -0
  40. data/lib/v8/portal/templates.rb +73 -0
  41. data/lib/v8/version.rb +1 -1
  42. data/spec/ext/array_spec.rb +15 -0
  43. data/spec/ext/cxt_spec.rb +4 -4
  44. data/spec/ext/ext_spec_helper.rb +43 -0
  45. data/spec/ext/mem_spec.rb +42 -0
  46. data/spec/ext/object_spec.rb +22 -0
  47. data/spec/redjs/jsapi_spec.rb +4 -4
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/v8/portal/proxies_spec.rb +189 -0
  50. metadata +38 -42
  51. data/ext/v8/v8_ref.cpp +0 -37
  52. data/ext/v8/v8_ref.h +0 -28
  53. data/lib/v8/portal/functions.rb +0 -45
@@ -1,6 +1,6 @@
1
1
  #include "rr.h"
2
- #include "v8_ref.h"
3
- #include "v8_func.h"
2
+ #include "v8_handle.h"
3
+ #include "v8_function.h"
4
4
  #include "v8_template.h"
5
5
  #include "v8_external.h"
6
6
  #include "v8_callbacks.h"
@@ -12,49 +12,98 @@ namespace {
12
12
  VALUE ObjectTemplateClass;
13
13
  VALUE FunctionTemplateClass;
14
14
 
15
- VALUE rb_hash_lookup(VALUE hash, const char *key) {
16
- return rb_funcall(hash, rb_intern("[]"), 1, rb_str_new2(key));
15
+ struct v8_callback_data {
16
+ VALUE handler;
17
+ VALUE getter;
18
+ VALUE setter;
19
+ VALUE query;
20
+ VALUE deleter;
21
+ VALUE enumerator;
22
+ VALUE data;
23
+ };
24
+
25
+ void delete_v8_data(Persistent<Value> value, void* parameter) {
26
+ value.Dispose();
27
+ delete (v8_callback_data*)parameter;
17
28
  }
18
29
 
19
- VALUE rb_hash_aset(VALUE hash, const char *key, VALUE value) {
20
- return ::rb_hash_aset(hash, rb_str_new2(key), value);
30
+ Local<External> make_v8_data(int argc, VALUE *argv, const char* argf) {
31
+ VALUE handler; VALUE data;
32
+ rb_scan_args(argc, argv, argf, &handler, &data);
33
+ v8_callback_data* v8_data = new v8_callback_data();
34
+ v8_data->handler = handler;
35
+ v8_data->data = data;
36
+ Local<External> external = External::New((void*)v8_data);
37
+ Persistent<External>::New(external).MakeWeak((void*)v8_data, delete_v8_data);
38
+ return external;
21
39
  }
22
40
 
23
- Local<Template> tmpl(VALUE self) {
24
- return V8_Ref_Get<Template>(self);
41
+ Persistent<Template> tmpl(VALUE self) {
42
+ return rr_v8_handle<Template>(self);
25
43
  }
26
- Local<ObjectTemplate> obj(VALUE self) {
27
- return V8_Ref_Get<ObjectTemplate>(self);
44
+ Persistent<ObjectTemplate> obj(VALUE self) {
45
+ return rr_v8_handle<ObjectTemplate>(self);
28
46
  }
29
- Local<FunctionTemplate> func(VALUE self) {
30
- return V8_Ref_Get<FunctionTemplate>(self);
47
+ Persistent<FunctionTemplate> func(VALUE self) {
48
+ return rr_v8_handle<FunctionTemplate>(self);
31
49
  }
32
50
 
33
51
  VALUE Set(VALUE self, VALUE name, VALUE value) {
34
52
  HandleScope handles;
35
53
  Local<String> key = rr_rb2v8(name)->ToString();
36
- Local<Data> data = V8_Ref_Get<Data>(value);
54
+ Persistent<Data> data = rr_v8_handle<Data>(value);
37
55
  tmpl(self)->Set(key, data);
38
56
  return Qnil;
39
57
  }
40
58
 
41
59
  Handle<Value> RubyInvocationCallback(const Arguments& args) {
42
- VALUE code = (VALUE)External::Unwrap(args.Data());
60
+ Handle<External> v8_data_wrapper = Handle<External>::Cast(args.Data());
61
+ v8_callback_data* v8_data = (v8_callback_data*)v8_data_wrapper->Value();
43
62
  VALUE rb_args = rr_v82rb(args);
44
- VALUE result = rb_funcall(code, rb_intern("call"), 1, rb_args);
45
- return rr_rb2v8(result);
63
+ rb_iv_set(rb_args, "data", v8_data->data);
64
+ if (RTEST(v8_data->handler)) {
65
+ VALUE result = rb_funcall(v8_data->handler, rb_intern("call"), 1, rb_args);
66
+ return rr_rb2v8(result);
67
+ } else {
68
+ return Handle<Value>();
69
+ }
46
70
  }
47
71
 
48
72
  namespace Obj {
49
73
 
74
+
75
+ v8_callback_data* accessor_info_data(const AccessorInfo& info) {
76
+ Handle<External> v8_data_wrapper = Handle<External>::Cast(info.Data());
77
+ return (v8_callback_data*)v8_data_wrapper->Value();
78
+ }
79
+
80
+ VALUE accessor_info_rb(const AccessorInfo& info) {
81
+ VALUE rb_data = accessor_info_data(info)->data;
82
+ VALUE rb_info = rr_v82rb(info);
83
+ rb_iv_set(rb_info, "data", rb_data);
84
+ return rb_info;
85
+ }
86
+
87
+ Local<External> accessor_info_data(VALUE getter, VALUE setter, VALUE query, VALUE deleter, VALUE enumerator, VALUE data) {
88
+ v8_callback_data* v8_data = new v8_callback_data();
89
+ v8_data->getter = getter;
90
+ v8_data->setter = setter;
91
+ v8_data->query = query;
92
+ v8_data->deleter = deleter;
93
+ v8_data->enumerator = enumerator;
94
+ v8_data->data = data;
95
+ Local<External> external = External::New((void*)v8_data);
96
+ Persistent<External>::New(external).MakeWeak((void*)v8_data, delete_v8_data);
97
+ return external;
98
+ }
99
+
50
100
  /**
51
101
  * NamedProperty[Getter|Setter] are used as interceptors on object.
52
102
  * See ObjectTemplate::SetNamedPropertyHandler.
53
103
  */
54
104
  Handle<Value> RubyNamedPropertyGetter(Local<String> property, const AccessorInfo& info) {
55
- VALUE code = (VALUE)External::Unwrap(info.Data());
56
- VALUE getter = rb_hash_lookup(code, "getter");
57
- return rr_rb2v8(rb_funcall(getter, rb_intern("call"), 2, rr_v82rb(property), rr_v82rb(info)));
105
+ VALUE getter = accessor_info_data(info)->getter;
106
+ return rr_rb2v8(rb_funcall(getter, rb_intern("call"), 2, rr_v82rb(property), accessor_info_rb(info)));
58
107
  }
59
108
 
60
109
  /**
@@ -62,9 +111,8 @@ namespace {
62
111
  * Otherwise, returns an empty handle.
63
112
  */
64
113
  Handle<Value> RubyNamedPropertySetter(Local<String> property, Local<Value> value, const AccessorInfo& info) {
65
- VALUE code = (VALUE)External::Unwrap(info.Data());
66
- VALUE setter = rb_hash_lookup(code, "setter");
67
- VALUE result = rb_funcall(setter, rb_intern("call"), 3, rr_v82rb(property), rr_v82rb(value), rr_v82rb(info));
114
+ VALUE setter = accessor_info_data(info)->setter;
115
+ VALUE result = rb_funcall(setter, rb_intern("call"), 3, rr_v82rb(property), rr_v82rb(value), accessor_info_rb(info));
68
116
  return rr_rb2v8(result);
69
117
  }
70
118
 
@@ -74,9 +122,8 @@ namespace {
74
122
  * The result is true if the property exists and false otherwise.
75
123
  */
76
124
  Handle<Integer> RubyNamedPropertyQuery(Local<String> property, const AccessorInfo& info) {
77
- VALUE code = (VALUE)External::Unwrap(info.Data());
78
- VALUE query = rb_hash_lookup(code, "query");
79
- VALUE result = rb_funcall(query, rb_intern("call"), 2, rr_v82rb(property), rr_v82rb(info));
125
+ VALUE query = accessor_info_data(info)->query;
126
+ VALUE result = rb_funcall(query, rb_intern("call"), 2, rr_v82rb(property), accessor_info_rb(info));
80
127
  Handle<Value> intercepts = rr_rb2v8(result);
81
128
  return intercepts.IsEmpty() ? Handle<Integer>() : Integer::New(None);
82
129
  }
@@ -87,9 +134,8 @@ namespace {
87
134
  * otherwise.
88
135
  */
89
136
  Handle<Boolean> RubyNamedPropertyDeleter(Local<String> property, const AccessorInfo& info) {
90
- VALUE code = (VALUE)External::Unwrap(info.Data());
91
- VALUE deleter = rb_hash_lookup(code, "deleter");
92
- VALUE result = rb_funcall(deleter, rb_intern("call"), 2, rr_v82rb(property), rr_v82rb(info));
137
+ VALUE deleter = accessor_info_data(info)->deleter;
138
+ VALUE result = rb_funcall(deleter, rb_intern("call"), 2, rr_v82rb(property), accessor_info_rb(info));
93
139
  Handle<Value> intercepts = rr_rb2v8(result);
94
140
  return intercepts.IsEmpty() ? Handle<Boolean>() : intercepts->ToBoolean();
95
141
  }
@@ -99,9 +145,8 @@ namespace {
99
145
  * property getter intercepts.
100
146
  */
101
147
  Handle<Array> RubyNamedPropertyEnumerator(const AccessorInfo& info) {
102
- VALUE code = (VALUE)External::Unwrap(info.Data());
103
- VALUE enumerator = rb_hash_lookup(code, "enumerator");
104
- VALUE result = rb_funcall(enumerator, rb_intern("call"), 1, rr_v82rb(info));
148
+ VALUE enumerator = accessor_info_data(info)->enumerator;
149
+ VALUE result = rb_funcall(enumerator, rb_intern("call"), 1, accessor_info_rb(info));
105
150
  Handle<Value> v(rr_rb2v8(result));
106
151
  if (v.IsEmpty()) {
107
152
  return Array::New();
@@ -119,9 +164,8 @@ namespace {
119
164
  * request. Otherwise, returns an empty handle.
120
165
  */
121
166
  Handle<Value> RubyIndexedPropertyGetter(uint32_t index, const AccessorInfo& info) {
122
- VALUE code = (VALUE)External::Unwrap(info.Data());
123
- VALUE getter = rb_hash_lookup(code, "getter");
124
- VALUE result = rb_funcall(getter, rb_intern("call"), 2, UINT2NUM(index), rr_v82rb(info));
167
+ VALUE getter = accessor_info_data(info)->getter;
168
+ VALUE result = rb_funcall(getter, rb_intern("call"), 2, UINT2NUM(index), accessor_info_rb(info));
125
169
  return rr_rb2v8(result);
126
170
  }
127
171
 
@@ -130,9 +174,8 @@ namespace {
130
174
  * Otherwise, returns an empty handle.
131
175
  */
132
176
  Handle<Value> RubyIndexedPropertySetter(uint32_t index, Local<Value> value, const AccessorInfo& info) {
133
- VALUE code = (VALUE)External::Unwrap(info.Data());
134
- VALUE setter = rb_hash_lookup(code, "setter");
135
- VALUE result = rb_funcall(setter, rb_intern("call"), 3, UINT2NUM(index), rr_v82rb(value), rr_v82rb(info));
177
+ VALUE setter = accessor_info_data(info)->setter;
178
+ VALUE result = rb_funcall(setter, rb_intern("call"), 3, UINT2NUM(index), rr_v82rb(value), accessor_info_rb(info));
136
179
  return rr_rb2v8(result);
137
180
  }
138
181
 
@@ -141,9 +184,8 @@ namespace {
141
184
  * The result is true if the property exists and false otherwise.
142
185
  */
143
186
  Handle<Integer> RubyIndexedPropertyQuery(uint32_t index, const AccessorInfo& info) {
144
- VALUE code = (VALUE)External::Unwrap(info.Data());
145
- VALUE query = rb_hash_lookup(code, "query");
146
- VALUE result = rb_funcall(query, rb_intern("call"), 2, UINT2NUM(index), rr_v82rb(info));
187
+ VALUE query = accessor_info_data(info)->query;
188
+ VALUE result = rb_funcall(query, rb_intern("call"), 2, UINT2NUM(index), accessor_info_rb(info));
147
189
  Handle<Value> intercepts = rr_rb2v8(result);
148
190
  return intercepts.IsEmpty() ? Handle<Integer>() : Integer::New(None);
149
191
  }
@@ -154,9 +196,8 @@ namespace {
154
196
  * otherwise.
155
197
  */
156
198
  Handle<Boolean> RubyIndexedPropertyDeleter(uint32_t index, const AccessorInfo& info) {
157
- VALUE code = (VALUE)External::Unwrap(info.Data());
158
- VALUE deleter = rb_hash_lookup(code, "deleter");
159
- VALUE result = rb_funcall(deleter, rb_intern("call"), 2, UINT2NUM(index), rr_v82rb(info));
199
+ VALUE deleter = accessor_info_data(info)->deleter;
200
+ VALUE result = rb_funcall(deleter, rb_intern("call"), 2, UINT2NUM(index), accessor_info_rb(info));
160
201
  Handle<Value> intercepts = rr_rb2v8(result);
161
202
  return intercepts.IsEmpty() ? Handle<Boolean>() : intercepts->ToBoolean();
162
203
  }
@@ -166,9 +207,8 @@ namespace {
166
207
  * indexed property getter intercepts.
167
208
  */
168
209
  Handle<Array> RubyIndexedPropertyEnumerator(const AccessorInfo& info) {
169
- VALUE code = (VALUE)External::Unwrap(info.Data());
170
- VALUE enumerator = rb_hash_lookup(code, "enumerator");
171
- VALUE result = rb_funcall(enumerator, rb_intern("call"), 1, rr_v82rb(info));
210
+ VALUE enumerator = accessor_info_data(info)->enumerator;
211
+ VALUE result = rb_funcall(enumerator, rb_intern("call"), 1, accessor_info_rb(info));
172
212
  Handle<Value> v(rr_rb2v8(result));
173
213
  if (v.IsEmpty()) {
174
214
  return Array::New();
@@ -183,7 +223,7 @@ namespace {
183
223
 
184
224
  VALUE New(VALUE rbclass) {
185
225
  HandleScope handles;
186
- return rr_v8_ref_create(rbclass, ObjectTemplate::New());
226
+ return rr_v8_handle_new(rbclass, ObjectTemplate::New());
187
227
  }
188
228
  VALUE NewInstance(VALUE self) {
189
229
  HandleScope scope;
@@ -198,93 +238,68 @@ namespace {
198
238
  }
199
239
  return rr_v82rb(object);
200
240
  }
201
- VALUE SetNamedPropertyHandler(VALUE self, VALUE getter, VALUE setter, VALUE query, VALUE deleter, VALUE enumerator) {
241
+ VALUE SetNamedPropertyHandler(VALUE self, VALUE getter, VALUE setter, VALUE query, VALUE deleter, VALUE enumerator, VALUE data) {
202
242
  HandleScope handles;
203
243
  if (!RTEST(getter)) {
204
244
  rb_raise(rb_eArgError, "you must supply at least a getter to V8::C::ObjectTemplate#SetNamedPropertyHandler()");
205
245
  return Qnil;
206
246
  }
207
- VALUE data = rb_hash_new();
208
- rb_hash_aset(data, "getter", getter);
209
- rb_hash_aset(data, "setter", setter);
210
- rb_hash_aset(data, "query", query);
211
- rb_hash_aset(data, "deleter", deleter);
212
- rb_hash_aset(data, "enumerator", enumerator);
213
- rr_v8_ref_setref(self, "data", data);
214
247
  obj(self)->SetNamedPropertyHandler(
215
248
  RubyNamedPropertyGetter,
216
249
  RTEST(setter) ? RubyNamedPropertySetter : 0,
217
250
  RTEST(query) ? RubyNamedPropertyQuery : 0,
218
251
  RTEST(deleter) ? RubyNamedPropertyDeleter : 0,
219
252
  RTEST(enumerator) ? RubyNamedPropertyEnumerator : 0,
220
- rr_v8_external_create(data)
253
+ accessor_info_data(getter, setter, query, deleter, enumerator, data)
221
254
  );
222
255
  return Qnil;
223
256
  }
224
- VALUE SetIndexedPropertyHandler(VALUE self, VALUE getter, VALUE setter, VALUE query, VALUE deleter, VALUE enumerator) {
257
+
258
+ VALUE SetIndexedPropertyHandler(VALUE self, VALUE getter, VALUE setter, VALUE query, VALUE deleter, VALUE enumerator, VALUE data) {
225
259
  HandleScope scope;
226
260
  if (!RTEST(getter)) {
227
261
  rb_raise(rb_eArgError, "you must supply at least a getter to V8::C::ObjectTemplate#SetNamedPropertyHandler()");
228
262
  return Qnil;
229
263
  }
230
- VALUE data = rb_hash_new();
231
- rb_hash_aset(data, "getter", getter);
232
- rb_hash_aset(data, "setter", setter);
233
- rb_hash_aset(data, "query", query);
234
- rb_hash_aset(data, "deleter", deleter);
235
- rb_hash_aset(data, "enumerator", enumerator);
236
- //TODO: is this really necessary?
237
- rr_v8_ref_setref(self, "data", data);
238
264
  obj(self)->SetIndexedPropertyHandler(
239
265
  RubyIndexedPropertyGetter,
240
266
  RTEST(setter) ? RubyIndexedPropertySetter : 0,
241
267
  RTEST(query) ? RubyIndexedPropertyQuery : 0,
242
268
  RTEST(deleter) ? RubyIndexedPropertyDeleter : 0,
243
269
  RTEST(enumerator) ? RubyIndexedPropertyEnumerator : 0,
244
- rr_v8_external_create(data)
270
+ accessor_info_data(getter, setter, query, deleter, enumerator, data)
245
271
  );
246
272
  return Qnil;
247
273
  }
248
- VALUE SetCallAsFunctionHandler(VALUE self) {
249
- HandleScope scope;
250
- VALUE code = rb_block_proc();
251
- if (NIL_P(code)) {
252
- return Qnil;
253
- }
254
- obj(self)->SetCallAsFunctionHandler(RubyInvocationCallback, rr_v8_external_create(code));
274
+ VALUE SetCallAsFunctionHandler(int argc, VALUE *argv, VALUE self) {
275
+ Handle<Value> v8_data = make_v8_data(argc, argv, "11");
276
+ obj(self)->SetCallAsFunctionHandler(RubyInvocationCallback, v8_data);
255
277
  return Qnil;
256
278
  }
257
279
  }
258
280
 
259
281
  namespace Func {
260
282
 
261
- VALUE New(VALUE function_template) {
262
- HandleScope handles;
263
- VALUE code = rb_block_proc();
264
- if (NIL_P(code)) {
265
- return Qnil;
266
- }
267
- Local<FunctionTemplate> templ = FunctionTemplate::New(RubyInvocationCallback, rr_v8_external_create(code));
268
- VALUE ref = rr_v8_ref_create(function_template,templ);
269
- rr_v8_ref_setref(ref, "code", code);
270
- return ref;
283
+ VALUE New(int argc, VALUE *argv, VALUE self) {
284
+ HandleScope h;
285
+ Handle<External> v8_data = make_v8_data(argc, argv, "02");
286
+ Local<FunctionTemplate> t = FunctionTemplate::New(RubyInvocationCallback, v8_data);
287
+ VALUE handle = rr_v8_handle_new(self,t);
288
+ return handle;
271
289
  }
272
- VALUE SetCallHandler(VALUE self) {
273
- HandleScope handles;
274
- VALUE code = rb_block_proc();
275
- if (NIL_P(code)) {
276
- return Qnil;
277
- }
278
- func(self)->SetCallHandler(RubyInvocationCallback, rr_v8_external_create(code));
290
+ VALUE SetCallHandler(int argc, VALUE *argv, VALUE self) {
291
+ HandleScope h;
292
+ Handle<Value> v8_data = make_v8_data(argc, argv, "11");
293
+ func(self)->SetCallHandler(RubyInvocationCallback, v8_data);
279
294
  return Qnil;
280
295
  }
281
296
  VALUE PrototypeTemplate(VALUE self) {
282
297
  HandleScope scope;
283
- return rr_v8_ref_create(ObjectTemplateClass, func(self)->PrototypeTemplate());
298
+ return rr_v8_handle_new(ObjectTemplateClass, func(self)->PrototypeTemplate());
284
299
  }
285
300
  VALUE InstanceTemplate(VALUE self) {
286
301
  HandleScope scope;
287
- return rr_v8_ref_create(ObjectTemplateClass, func(self)->InstanceTemplate());
302
+ return rr_v8_handle_new(ObjectTemplateClass, func(self)->InstanceTemplate());
288
303
  }
289
304
  VALUE Inherit(VALUE self, VALUE function_template) {
290
305
  HandleScope scope;
@@ -308,19 +323,19 @@ namespace {
308
323
  }
309
324
 
310
325
  void rr_init_template() {
311
- VALUE Template = rr_define_class("Template");
326
+ VALUE Template = rr_define_class("Template", rr_v8_handle_class());
312
327
  rr_define_method(Template, "Set", Set, 2);
313
328
 
314
329
  ObjectTemplateClass = rr_define_class("ObjectTemplate", Template);
315
330
  rr_define_singleton_method(ObjectTemplateClass, "New", Obj::New, 0);
316
331
  rr_define_method(ObjectTemplateClass, "NewInstance", Obj::NewInstance, 0);
317
- rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 5);
318
- rr_define_method(ObjectTemplateClass, "SetIndexedPropertyHandler", Obj::SetIndexedPropertyHandler, 5);
319
- rr_define_method(ObjectTemplateClass, "SetCallAsFunctionHandler", Obj::SetCallAsFunctionHandler, 0);
332
+ rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 6);
333
+ rr_define_method(ObjectTemplateClass, "SetIndexedPropertyHandler", Obj::SetIndexedPropertyHandler, 6);
334
+ rr_define_method(ObjectTemplateClass, "SetCallAsFunctionHandler", Obj::SetCallAsFunctionHandler, -1);
320
335
 
321
336
  FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
322
- rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, 0);
323
- rr_define_method(FunctionTemplateClass, "SetCallHandler", Func::SetCallHandler, 0);
337
+ rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, -1);
338
+ rr_define_method(FunctionTemplateClass, "SetCallHandler", Func::SetCallHandler, -1);
324
339
  rr_define_method(FunctionTemplateClass, "PrototypeTemplate", Func::PrototypeTemplate, 0);
325
340
  rr_define_method(FunctionTemplateClass, "InstanceTemplate", Func::InstanceTemplate, 0);
326
341
  rr_define_method(FunctionTemplateClass, "Inherit", Func::Inherit, 1);
@@ -1,6 +1,6 @@
1
1
  #include "rr.h"
2
2
  #include "v8_try_catch.h"
3
- #include "v8_msg.h"
3
+ #include "v8_message.h"
4
4
 
5
5
  using namespace v8;
6
6
 
@@ -17,6 +17,12 @@ namespace {
17
17
  VALUE IdleNotification(VALUE self) {
18
18
  return rr_v82rb(V8::IdleNotification());
19
19
  }
20
+
21
+ VALUE SetFlagsFromString(VALUE self, VALUE string) {
22
+ V8::SetFlagsFromString(RSTRING_PTR(string), RSTRING_LEN(string));
23
+ return Qnil;
24
+ }
25
+
20
26
  }
21
27
 
22
28
 
@@ -25,4 +31,5 @@ void rr_init_v8_v8() {
25
31
  rr_define_singleton_method(V8Module, "IsDead", IsDead, 0);
26
32
  rr_define_singleton_method(V8Module, "AdjustAmountOfExternalAllocatedMemory", AdjustAmountOfExternalAllocatedMemory, 1);
27
33
  rr_define_singleton_method(V8Module, "IdleNotification", IdleNotification, 0);
34
+ rr_define_singleton_method(V8Module, "SetFlagsFromString", SetFlagsFromString, 1);
28
35
  }
@@ -1,13 +1,16 @@
1
+ #include "v8_handle.h"
1
2
  #include "v8_value.h"
2
- #include "v8_ref.h"
3
3
 
4
4
  using namespace v8;
5
5
  namespace {
6
- Local<Value> unwrap(VALUE value) {
7
- return V8_Ref_Get<Value>(value);
6
+
7
+ VALUE ValueClass;
8
+
9
+ Persistent<Value>& unwrap(VALUE value) {
10
+ return rr_v8_handle<Value>(value);
8
11
  }
9
12
  VALUE IsEmpty(VALUE value) {
10
- return value == rr_cV8_C_Empty ? Qtrue : Qfalse;
13
+ return value == rr_v8_value_empty() ? Qtrue : Qfalse;
11
14
  }
12
15
  VALUE IsUndefined(VALUE self) {
13
16
  HandleScope scope;
@@ -123,45 +126,50 @@ namespace {
123
126
  }
124
127
  }
125
128
 
126
- VALUE rr_cV8_C_Value;
127
- VALUE rr_cV8_C_Empty;
129
+ VALUE rr_v8_value_class() {
130
+ return ValueClass;
131
+ }
132
+
133
+ VALUE rr_v8_value_empty() {
134
+ return rr_const_get("Empty");
135
+ }
128
136
 
129
137
  void rr_init_value() {
130
- rr_cV8_C_Value = rr_define_class("Value");
131
- rr_cV8_C_Empty = rr_define_const("Empty", rr_v8_ref_create(rr_cV8_C_Value, Handle<Value>()));
138
+ ValueClass = rr_define_class("Value", rr_v8_handle_class());
139
+ rr_define_const("Empty", rr_v8_handle_new(ValueClass, Handle<Value>()));
132
140
 
133
- rr_define_method(rr_cV8_C_Value, "IsEmpty", IsEmpty, 0);
134
- rr_define_method(rr_cV8_C_Value, "IsUndefined", IsUndefined, 0);
135
- rr_define_method(rr_cV8_C_Value, "IsNull", IsNull, 0);
136
- rr_define_method(rr_cV8_C_Value, "IsTrue", IsTrue, 0);
137
- rr_define_method(rr_cV8_C_Value, "IsFalse", IsFalse, 0);
138
- rr_define_method(rr_cV8_C_Value, "IsString", IsString, 0);
139
- rr_define_method(rr_cV8_C_Value, "IsFunction", IsFunction, 0);
140
- rr_define_method(rr_cV8_C_Value, "IsArray", IsArray, 0);
141
- rr_define_method(rr_cV8_C_Value, "IsObject", IsObject, 0);
142
- rr_define_method(rr_cV8_C_Value, "IsBoolean", IsBoolean, 0);
143
- rr_define_method(rr_cV8_C_Value, "IsNumber", IsNumber, 0);
144
- rr_define_method(rr_cV8_C_Value, "IsExternal", IsExternal, 0);
145
- rr_define_method(rr_cV8_C_Value, "IsInt32", IsInt32, 0);
146
- rr_define_method(rr_cV8_C_Value, "IsUint32", IsUint32, 0);
147
- rr_define_method(rr_cV8_C_Value, "IsDate", IsDate, 0);
141
+ rr_define_method(ValueClass, "IsEmpty", IsEmpty, 0);
142
+ rr_define_method(ValueClass, "IsUndefined", IsUndefined, 0);
143
+ rr_define_method(ValueClass, "IsNull", IsNull, 0);
144
+ rr_define_method(ValueClass, "IsTrue", IsTrue, 0);
145
+ rr_define_method(ValueClass, "IsFalse", IsFalse, 0);
146
+ rr_define_method(ValueClass, "IsString", IsString, 0);
147
+ rr_define_method(ValueClass, "IsFunction", IsFunction, 0);
148
+ rr_define_method(ValueClass, "IsArray", IsArray, 0);
149
+ rr_define_method(ValueClass, "IsObject", IsObject, 0);
150
+ rr_define_method(ValueClass, "IsBoolean", IsBoolean, 0);
151
+ rr_define_method(ValueClass, "IsNumber", IsNumber, 0);
152
+ rr_define_method(ValueClass, "IsExternal", IsExternal, 0);
153
+ rr_define_method(ValueClass, "IsInt32", IsInt32, 0);
154
+ rr_define_method(ValueClass, "IsUint32", IsUint32, 0);
155
+ rr_define_method(ValueClass, "IsDate", IsDate, 0);
148
156
 
149
- rr_define_method(rr_cV8_C_Value, "ToBoolean", ToBoolean, 0);
150
- rr_define_method(rr_cV8_C_Value, "ToNumber", ToNumber, 0);
151
- rr_define_method(rr_cV8_C_Value, "ToString", ToString, 0);
152
- rr_define_method(rr_cV8_C_Value, "ToDetailString", ToDetailString, 0);
153
- rr_define_method(rr_cV8_C_Value, "ToObject", ToObject, 0);
154
- rr_define_method(rr_cV8_C_Value, "ToInteger", ToInteger, 0);
155
- rr_define_method(rr_cV8_C_Value, "ToUint32", ToUint32, 0);
156
- rr_define_method(rr_cV8_C_Value, "ToArrayIndex", ToArrayIndex, 0);
157
+ rr_define_method(ValueClass, "ToBoolean", ToBoolean, 0);
158
+ rr_define_method(ValueClass, "ToNumber", ToNumber, 0);
159
+ rr_define_method(ValueClass, "ToString", ToString, 0);
160
+ rr_define_method(ValueClass, "ToDetailString", ToDetailString, 0);
161
+ rr_define_method(ValueClass, "ToObject", ToObject, 0);
162
+ rr_define_method(ValueClass, "ToInteger", ToInteger, 0);
163
+ rr_define_method(ValueClass, "ToUint32", ToUint32, 0);
164
+ rr_define_method(ValueClass, "ToArrayIndex", ToArrayIndex, 0);
157
165
 
158
- rr_define_method(rr_cV8_C_Value, "Equals", Equals, 1);
159
- rr_define_method(rr_cV8_C_Value, "StrictEquals", StrictEquals, 1);
166
+ rr_define_method(ValueClass, "Equals", Equals, 1);
167
+ rr_define_method(ValueClass, "StrictEquals", StrictEquals, 1);
160
168
 
161
- rr_define_method(rr_cV8_C_Value, "BooleanValue", BooleanValue, 0);
162
- rr_define_method(rr_cV8_C_Value, "NumberValue", NumberValue, 0);
169
+ rr_define_method(ValueClass, "BooleanValue", BooleanValue, 0);
170
+ rr_define_method(ValueClass, "NumberValue", NumberValue, 0);
163
171
  }
164
172
 
165
173
  VALUE rr_wrap_v8_value(Handle<Value>& value) {
166
- return rr_v8_ref_create(rr_cV8_C_Value, value);
174
+ return rr_v8_handle_new(ValueClass, value);
167
175
  }