therubyracer-tmpfork 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.travis.yml +14 -0
  4. data/Changelog.md +263 -0
  5. data/Gemfile +15 -0
  6. data/README.md +224 -0
  7. data/Rakefile +42 -0
  8. data/benchmarks.rb +218 -0
  9. data/ext/v8/accessor.cc +181 -0
  10. data/ext/v8/array.cc +26 -0
  11. data/ext/v8/backref.cc +45 -0
  12. data/ext/v8/constants.cc +34 -0
  13. data/ext/v8/constraints.cc +52 -0
  14. data/ext/v8/context.cc +130 -0
  15. data/ext/v8/date.cc +18 -0
  16. data/ext/v8/exception.cc +38 -0
  17. data/ext/v8/extconf.rb +34 -0
  18. data/ext/v8/external.cc +43 -0
  19. data/ext/v8/function.cc +58 -0
  20. data/ext/v8/gc.cc +43 -0
  21. data/ext/v8/handles.cc +34 -0
  22. data/ext/v8/heap.cc +35 -0
  23. data/ext/v8/init.cc +39 -0
  24. data/ext/v8/invocation.cc +86 -0
  25. data/ext/v8/locker.cc +77 -0
  26. data/ext/v8/message.cc +51 -0
  27. data/ext/v8/object.cc +335 -0
  28. data/ext/v8/primitive.cc +8 -0
  29. data/ext/v8/rr.cc +83 -0
  30. data/ext/v8/rr.h +934 -0
  31. data/ext/v8/script.cc +115 -0
  32. data/ext/v8/signature.cc +18 -0
  33. data/ext/v8/stack.cc +76 -0
  34. data/ext/v8/string.cc +47 -0
  35. data/ext/v8/template.cc +175 -0
  36. data/ext/v8/trycatch.cc +87 -0
  37. data/ext/v8/v8.cc +87 -0
  38. data/ext/v8/value.cc +239 -0
  39. data/lib/therubyracer.rb +1 -0
  40. data/lib/v8.rb +30 -0
  41. data/lib/v8/access.rb +5 -0
  42. data/lib/v8/access/indices.rb +40 -0
  43. data/lib/v8/access/invocation.rb +47 -0
  44. data/lib/v8/access/names.rb +65 -0
  45. data/lib/v8/array.rb +26 -0
  46. data/lib/v8/context.rb +258 -0
  47. data/lib/v8/conversion.rb +36 -0
  48. data/lib/v8/conversion/array.rb +11 -0
  49. data/lib/v8/conversion/class.rb +119 -0
  50. data/lib/v8/conversion/code.rb +38 -0
  51. data/lib/v8/conversion/fixnum.rb +11 -0
  52. data/lib/v8/conversion/fundamental.rb +11 -0
  53. data/lib/v8/conversion/hash.rb +11 -0
  54. data/lib/v8/conversion/indentity.rb +31 -0
  55. data/lib/v8/conversion/method.rb +26 -0
  56. data/lib/v8/conversion/object.rb +28 -0
  57. data/lib/v8/conversion/primitive.rb +7 -0
  58. data/lib/v8/conversion/proc.rb +5 -0
  59. data/lib/v8/conversion/reference.rb +16 -0
  60. data/lib/v8/conversion/string.rb +12 -0
  61. data/lib/v8/conversion/symbol.rb +7 -0
  62. data/lib/v8/conversion/time.rb +13 -0
  63. data/lib/v8/error.rb +169 -0
  64. data/lib/v8/function.rb +28 -0
  65. data/lib/v8/object.rb +79 -0
  66. data/lib/v8/stack.rb +85 -0
  67. data/lib/v8/version.rb +3 -0
  68. data/lib/v8/weak.rb +82 -0
  69. data/spec/c/array_spec.rb +17 -0
  70. data/spec/c/constants_spec.rb +20 -0
  71. data/spec/c/exception_spec.rb +26 -0
  72. data/spec/c/external_spec.rb +9 -0
  73. data/spec/c/function_spec.rb +46 -0
  74. data/spec/c/handles_spec.rb +35 -0
  75. data/spec/c/locker_spec.rb +38 -0
  76. data/spec/c/object_spec.rb +46 -0
  77. data/spec/c/script_spec.rb +28 -0
  78. data/spec/c/string_spec.rb +16 -0
  79. data/spec/c/template_spec.rb +30 -0
  80. data/spec/c/trycatch_spec.rb +51 -0
  81. data/spec/mem/blunt_spec.rb +42 -0
  82. data/spec/redjs_spec.rb +10 -0
  83. data/spec/spec_helper.rb +45 -0
  84. data/spec/threading_spec.rb +64 -0
  85. data/spec/v8/context_spec.rb +19 -0
  86. data/spec/v8/conversion_spec.rb +52 -0
  87. data/spec/v8/error_spec.rb +167 -0
  88. data/spec/v8/function_spec.rb +9 -0
  89. data/spec/v8/object_spec.rb +15 -0
  90. data/thefrontside.png +0 -0
  91. data/therubyracer-tmpfork.gemspec +22 -0
  92. metadata +186 -0
@@ -0,0 +1,8 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ void Primitive::Init() {
5
+ ClassBuilder("Primitive", Value::Class).
6
+ store(&Class);
7
+ }
8
+ }
@@ -0,0 +1,83 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ VALUE defineClass(const char *name, VALUE superclass = rb_cObject) {
5
+ VALUE V8 = rb_define_module("V8");
6
+ VALUE V8_C = rb_define_module_under(V8, "C");
7
+ VALUE klass = rb_define_class_under(V8_C, name, superclass);
8
+ rb_funcall(klass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
9
+ return klass;
10
+ }
11
+
12
+ VALUE defineModule(const char *name) {
13
+ VALUE V8 = rb_define_module("V8");
14
+ VALUE V8_C = rb_define_module_under(V8, "C");
15
+ return rb_define_module_under(V8_C, name);
16
+ }
17
+
18
+ VALUE not_implemented(const char* message) {
19
+ Void(rb_raise(rb_eStandardError, "not yet implemented %s", message));
20
+ }
21
+
22
+ ClassBuilder::ClassBuilder(const char* name, VALUE superclass) {
23
+ this->value = defineClass(name, superclass);
24
+ }
25
+
26
+ ClassBuilder::ClassBuilder(const char* name, const char* supername) {
27
+ VALUE superclass = defineClass(supername);
28
+ this->value = defineClass(name, superclass);
29
+ }
30
+ ClassBuilder& ClassBuilder::defineConst(const char* name, VALUE value) {
31
+ rb_define_const(this->value, name, value);
32
+ return *this;
33
+ }
34
+ ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(int, VALUE*, VALUE)) {
35
+ rb_define_method(this->value, name, (VALUE (*)(...))impl, -1);
36
+ return *this;
37
+ }
38
+ ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE)) {
39
+ rb_define_method(this->value, name, (VALUE (*)(...))impl, 0);
40
+ return *this;
41
+ }
42
+ ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE)) {
43
+ rb_define_method(this->value, name, (VALUE (*)(...))impl, 1);
44
+ return *this;
45
+ }
46
+ ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) {
47
+ rb_define_method(this->value, name, (VALUE (*)(...))impl, 2);
48
+ return *this;
49
+ }
50
+ ClassBuilder& ClassBuilder::defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE, VALUE)) {
51
+ rb_define_method(this->value, name, (VALUE (*)(...))impl, 3);
52
+ return *this;
53
+ }
54
+ ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(int, VALUE*, VALUE)) {
55
+ rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, -1);
56
+ return *this;
57
+ }
58
+ ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE)) {
59
+ rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 0);
60
+ return *this;
61
+ }
62
+ ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE)) {
63
+ rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 1);
64
+ return *this;
65
+ }
66
+ ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE)) {
67
+ rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 2);
68
+ return *this;
69
+ }
70
+ ClassBuilder& ClassBuilder::defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE, VALUE)) {
71
+ rb_define_singleton_method(this->value, name, (VALUE (*)(...))impl, 3);
72
+ return *this;
73
+ }
74
+ ClassBuilder& ClassBuilder::defineEnumConst(const char* name, int value) {
75
+ rb_define_const(this->value, name, INT2FIX(value));
76
+ return *this;
77
+ }
78
+ ClassBuilder& ClassBuilder::store(VALUE* storage) {
79
+ rb_gc_register_address(storage);
80
+ *storage = this->value;
81
+ return *this;
82
+ }
83
+ }
@@ -0,0 +1,934 @@
1
+ #ifndef THE_RUBY_RACER
2
+ #define THE_RUBY_RACER
3
+
4
+ #include <v8.h>
5
+ #include <ruby.h>
6
+ #include <vector>
7
+ #ifdef HAVE_RUBY_ENCODING_H
8
+ #include "ruby/encoding.h"
9
+ #endif
10
+
11
+ #if !defined(RARRAY_LENINT)
12
+ # define RARRAY_LENINT(v) (int)RARRAY_LEN(v)
13
+ #endif /* ! defined(RARRAY_LENINT) */
14
+
15
+ #if !defined(SIZET2NUM)
16
+ # if SIZEOF_SIZE_T == SIZEOF_LONG
17
+ # define SIZET2NUM(n) ULONG2NUM(n)
18
+ # else
19
+ # define SIZET2NUM(n) ULL2NUM(n)
20
+ # endif
21
+ #endif /* ! defined(SIZET2NUM) */
22
+
23
+ #if !defined(NUM2SIZET)
24
+ # if SIZEOF_SIZE_T == SIZEOF_LONG
25
+ # define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
26
+ # else
27
+ # define NUM2SIZET(n) ((size_t)NUM2ULL(n))
28
+ # endif
29
+ #endif /* ! defined(NUM2SIZET) */
30
+
31
+ namespace rr {
32
+
33
+ #define Void(expr) expr; return Qnil;
34
+ VALUE not_implemented(const char* message);
35
+
36
+ class Equiv {
37
+ public:
38
+ Equiv(VALUE val) : value(val) {}
39
+ inline operator VALUE() {return value;}
40
+ protected:
41
+ VALUE value;
42
+ };
43
+
44
+ class Bool : public Equiv {
45
+ public:
46
+ Bool(VALUE val) : Equiv(val) {}
47
+ Bool(bool b) : Equiv(b ? Qtrue : Qfalse) {}
48
+ Bool(v8::Handle<v8::Boolean> b) : Equiv(b->Value() ? Qtrue : Qfalse) {}
49
+ inline operator bool() {return RTEST(value);}
50
+ };
51
+
52
+ class UInt32 : public Equiv {
53
+ public:
54
+ UInt32(VALUE val) : Equiv(val) {}
55
+ UInt32(uint32_t ui) : Equiv(UINT2NUM(ui)) {}
56
+ inline operator uint32_t() {return RTEST(value) ? NUM2UINT(value) : 0;}
57
+ };
58
+
59
+ class GC {
60
+ public:
61
+ class Queue {
62
+ public:
63
+ Queue();
64
+ void Enqueue(void* phantom);
65
+ void* Dequeue();
66
+ private:
67
+ struct Node {
68
+ Node(void* val ) : value(val), next(NULL) { }
69
+ void* value;
70
+ Node* next;
71
+ };
72
+ Node* first; // for producer only
73
+ Node* divider;
74
+ Node* last;
75
+ };
76
+ static void Finalize(void* phantom);
77
+ static void Drain(v8::GCType type, v8::GCCallbackFlags flags);
78
+ static void Init();
79
+ };
80
+
81
+ /**
82
+ * A V8 Enum
83
+ */
84
+
85
+ template <class T> class Enum : public Equiv {
86
+ public:
87
+ Enum<T>(VALUE value, T defaultValue = 0) : Equiv(value) {
88
+ this->defaultValue = defaultValue;
89
+ }
90
+ inline operator T() {
91
+ return (T)(RTEST(value) ? NUM2INT(value) : defaultValue);
92
+ }
93
+ private:
94
+ T defaultValue;
95
+ };
96
+
97
+ /**
98
+ * A pointer to V8 object managed by Ruby
99
+ *
100
+ * You deal with V8 objects as either pointers or handles.
101
+ * While handles are managed by the V8 garbage collector, pointers
102
+ * must be explicitly created and destroyed by your code.
103
+ *
104
+ * The pointer class provides a handly way to wrap V8 pointers
105
+ * into Ruby objects so that they will be deleted when the
106
+ * Ruby object is garbage collected. Automatic type coercion is
107
+ * used to make wrapping and unwrapping painless.
108
+ *
109
+ * To create Ruby VALUE:
110
+ *
111
+ * Pointer<v8::ScriptOrigin> ptr(new v8::ScriptOrigin());
112
+ * VALUE value = ptr; //automatically wraps in Data_Wrap_Struct
113
+ *
114
+ * Conversely, the pointer can be unwrapped from a struct
115
+ * created in this way and the underlying methods can be
116
+ * invoked:
117
+ *
118
+ * VALUE value = ...;
119
+ * Pointer<v8::ScriptOrigin> ptr(value);
120
+ * ptr->CallMethod();
121
+ */
122
+
123
+ template <class T> class Pointer {
124
+ public:
125
+ inline Pointer(T* t) : pointer(t) {};
126
+ inline Pointer(VALUE v) {
127
+ if (RTEST(v)) {
128
+ this->unwrap(v);
129
+ } else {
130
+ this->pointer = NULL;
131
+ }
132
+ };
133
+ inline operator T*() {return pointer;}
134
+ inline T* operator ->() {return pointer;}
135
+ inline operator VALUE() {
136
+ return Data_Wrap_Struct(Class, 0, &release, pointer);
137
+ }
138
+ void unwrap(VALUE value);
139
+ static void release(T* pointer) {
140
+ delete pointer;
141
+ }
142
+ static VALUE Class;
143
+ protected:
144
+ T* pointer;
145
+ };
146
+ template <class T> VALUE Pointer<T>::Class;
147
+
148
+ /**
149
+ * A Reference to a V8 managed object
150
+ *
151
+ * Uses type coercion to quickly convert from a v8 handle
152
+ * to a ruby object and back again. Suppose we have a v8 handle
153
+ * that we want to return to Ruby. We can put it into a Ref:
154
+ *
155
+ * v8::Handle<v8::Object> object = v8::Object::New();
156
+ * VALUE val = Ref<v8::Object>(object);
157
+ *
158
+ * this will create a `v8::Persistent` handle for the object
159
+ * so that it will not be garbage collected by v8. It then
160
+ * stuffs this new persistent handle into a Data_Wrap_Struct
161
+ * which can then be passed to Ruby code. When this struct
162
+ * is garbage collected by Ruby, it enqueues the corresponding
163
+ * v8 handle to be released during v8 gc.
164
+ *
165
+ * By the same token, you can use Refs to unwrap a Data_Wrap_Struct
166
+ * which has been generated in this fashion and call through to
167
+ * the underlying v8 methods. Suppose we are passed a VALUE `val`
168
+ * wrapping a v8::Object:
169
+ *
170
+ * Ref<v8::Object> object(val);
171
+ * object->Get(v8::String::New("foo"));
172
+ *
173
+ */
174
+ template <class T> class Ref {
175
+ public:
176
+ Ref(VALUE value) {
177
+ this->value = value;
178
+ }
179
+ Ref(v8::Handle<T> handle, const char* label = "v8::Handle<void>") {
180
+ this->handle = handle;
181
+ }
182
+ virtual ~Ref() {}
183
+ /*
184
+ * Coerce a Ref into a Ruby VALUE
185
+ */
186
+ virtual operator VALUE() const {
187
+ return handle.IsEmpty() ? Qnil : Data_Wrap_Struct(Class, 0, &Holder::enqueue, new Holder(handle));
188
+ }
189
+ /*
190
+ * Coerce a Ref into a v8::Handle.
191
+ */
192
+ virtual operator v8::Handle<T>() const {
193
+ if (RTEST(this->value)) {
194
+ Holder* holder = NULL;
195
+ Data_Get_Struct(this->value, class Holder, holder);
196
+ return holder->handle;
197
+ } else {
198
+ return v8::Handle<T>();
199
+ }
200
+ }
201
+ void dispose() {
202
+ Holder* holder = NULL;
203
+ Data_Get_Struct(this->value, class Holder, holder);
204
+ holder->dispose();
205
+ }
206
+
207
+ /*
208
+ * Pointer de-reference operators, this lets you use a ref to
209
+ * call through to underlying v8 methods. e.g
210
+ *
211
+ * Ref<v8::Object>(value)->ToString();
212
+ */
213
+ inline v8::Handle<T> operator->() const { return *this;}
214
+ inline v8::Handle<T> operator*() const {return *this;}
215
+
216
+ template <class C> class array {
217
+ public:
218
+ inline array(VALUE ary) : argv(ary), vector(RARRAY_LENINT(argv)) {}
219
+ inline operator v8::Handle<T>*() {
220
+ for (uint32_t i = 0; i < vector.size(); i++) {
221
+ vector[i] = C(rb_ary_entry(argv, i));
222
+ }
223
+ return &vector[0];
224
+ }
225
+ private:
226
+ VALUE argv;
227
+ std::vector< v8::Handle<T> > vector;
228
+ };
229
+
230
+ class Holder {
231
+ friend class Ref;
232
+ public:
233
+ Holder(v8::Handle<T> handle) {
234
+ this->disposed_p = false;
235
+ this->handle = v8::Persistent<T>::New(handle);
236
+ }
237
+ virtual ~Holder() {
238
+ this->dispose();
239
+ }
240
+ void dispose() {
241
+ if (!this->disposed_p) {
242
+ handle.Dispose();
243
+ this->disposed_p = true;
244
+ }
245
+ }
246
+ protected:
247
+ v8::Persistent<T> handle;
248
+ bool disposed_p;
249
+
250
+ static void enqueue(Holder* holder) {
251
+ GC::Finalize(holder);
252
+ }
253
+ };
254
+
255
+ VALUE value;
256
+ v8::Handle<T> handle;
257
+ static VALUE Class;
258
+ };
259
+ template <class T> VALUE Ref<T>::Class;
260
+
261
+ class Backref {
262
+ public:
263
+ static void Init();
264
+ Backref(VALUE value);
265
+ virtual ~Backref();
266
+ VALUE get();
267
+ VALUE set(VALUE value);
268
+ v8::Handle<v8::Value> toExternal();
269
+ static void release(v8::Persistent<v8::Value> handle, void* data);
270
+ private:
271
+ VALUE storage;
272
+ static VALUE Storage;
273
+ static ID _new;
274
+ static ID object;
275
+ };
276
+ class Handles {
277
+ public:
278
+ static void Init();
279
+ static VALUE HandleScope(int argc, VALUE* argv, VALUE self);
280
+ private:
281
+ static VALUE SetupAndCall(int* state, VALUE code);
282
+ static VALUE DoCall(VALUE code);
283
+ };
284
+
285
+ class Phantom {
286
+ public:
287
+ inline Phantom(void* reference) : holder((Ref<void>::Holder*)reference) {}
288
+ inline bool NotNull() {
289
+ return this->holder != NULL;
290
+ }
291
+ inline void destroy() {
292
+ delete holder;
293
+ }
294
+ Ref<void>::Holder* holder;
295
+ };
296
+
297
+ class ExtensionConfiguration : public Pointer<v8::ExtensionConfiguration> {
298
+ public:
299
+ static VALUE initialize(VALUE self, VALUE names);
300
+ inline ExtensionConfiguration(v8::ExtensionConfiguration* config) : Pointer<v8::ExtensionConfiguration>(config) {}
301
+ inline ExtensionConfiguration(VALUE value) : Pointer<v8::ExtensionConfiguration>(value) {}
302
+ };
303
+
304
+ class Context : public Ref<v8::Context> {
305
+ public:
306
+ static void Init();
307
+ static VALUE New(int argc, VALUE argv[], VALUE self);
308
+ static VALUE Dispose(VALUE self);
309
+ static VALUE Enter(VALUE self);
310
+ static VALUE Exit(VALUE self);
311
+ static VALUE Global(VALUE self);
312
+ static VALUE DetachGlobal(VALUE self);
313
+ static VALUE ReattachGlobal(VALUE self, VALUE global);
314
+ static VALUE GetEntered(VALUE self);
315
+ static VALUE GetCurrent(VALUE self);
316
+ static VALUE GetCalling(VALUE self);
317
+ static VALUE SetSecurityToken(VALUE self, VALUE token);
318
+ static VALUE UseDefaultSecurityToken(VALUE self);
319
+ static VALUE GetSecurityToken(VALUE self);
320
+ static VALUE HasOutOfMemoryException(VALUE self);
321
+ static VALUE InContext(VALUE self);
322
+ static VALUE SetEmbedderData(VALUE self, VALUE index, VALUE data);
323
+ static VALUE GetEmbedderData(VALUE self, VALUE index);
324
+ static VALUE AllowCodeGenerationFromStrings(VALUE self, VALUE allow);
325
+ static VALUE IsCodeGenerationFromStringsAllowed(VALUE self);
326
+
327
+ inline Context(VALUE value) : Ref<v8::Context>(value) {}
328
+ inline Context(v8::Handle<v8::Context> cxt) : Ref<v8::Context>(cxt) {}
329
+ };
330
+
331
+ class External: public Ref<v8::External> {
332
+ public:
333
+ static void Init();
334
+ static VALUE New(VALUE self, VALUE data);
335
+ static VALUE Value(VALUE self);
336
+
337
+ inline External(VALUE value) : Ref<v8::External>(value) {}
338
+ inline External(v8::Handle<v8::External> ext) : Ref<v8::External>(ext) {}
339
+ static v8::Handle<v8::External> wrap(VALUE data);
340
+ static VALUE unwrap(v8::Handle<v8::External> external);
341
+ private:
342
+ static void release(v8::Persistent<v8::Value> object, void* parameter);
343
+ struct Data {
344
+ Data(VALUE data);
345
+ ~Data();
346
+ VALUE value;
347
+ };
348
+ };
349
+
350
+ class ScriptOrigin : public Pointer<v8::ScriptOrigin> {
351
+ public:
352
+ inline ScriptOrigin(v8::ScriptOrigin* o) : Pointer<v8::ScriptOrigin>(o) {};
353
+ inline ScriptOrigin(VALUE value) : Pointer<v8::ScriptOrigin>(value) {}
354
+
355
+ static VALUE initialize(int argc, VALUE argv[], VALUE self);
356
+ };
357
+
358
+ class ScriptData : public Pointer<v8::ScriptData> {
359
+ public:
360
+ inline ScriptData(v8::ScriptData* d) : Pointer<v8::ScriptData>(d) {};
361
+ inline ScriptData(VALUE value) : Pointer<v8::ScriptData>(value) {}
362
+
363
+ static VALUE PreCompile(VALUE self, VALUE input, VALUE length);
364
+ static VALUE New(VALUE self, VALUE data, VALUE length);
365
+ static VALUE Length(VALUE self);
366
+ static VALUE Data(VALUE self);
367
+ static VALUE HasError(VALUE self);
368
+ };
369
+
370
+ class Script : public Ref<v8::Script> {
371
+ public:
372
+ static void Init();
373
+ static VALUE New(int argc, VALUE argv[], VALUE self);
374
+ static VALUE Run(VALUE self);
375
+ static VALUE RunWithTimeout(VALUE self, VALUE timeout);
376
+
377
+ inline Script(VALUE value) : Ref<v8::Script>(value) {}
378
+ inline Script(v8::Handle<v8::Script> script) : Ref<v8::Script>(script) {}
379
+ };
380
+
381
+ class Value : public Ref<v8::Value> {
382
+ public:
383
+ static void Init();
384
+ static VALUE IsUndefined(VALUE self);
385
+ static VALUE IsNull(VALUE self);
386
+ static VALUE IsTrue(VALUE self);
387
+ static VALUE IsFalse(VALUE self);
388
+ static VALUE IsString(VALUE self);
389
+ static VALUE IsFunction(VALUE self);
390
+ static VALUE IsArray(VALUE self);
391
+ static VALUE IsObject(VALUE self);
392
+ static VALUE IsBoolean(VALUE self);
393
+ static VALUE IsNumber(VALUE self);
394
+ static VALUE IsExternal(VALUE self);
395
+ static VALUE IsInt32(VALUE self);
396
+ static VALUE IsUint32(VALUE self);
397
+ static VALUE IsDate(VALUE self);
398
+ static VALUE IsBooleanObject(VALUE self);
399
+ static VALUE IsNumberObject(VALUE self);
400
+ static VALUE IsStringObject(VALUE self);
401
+ static VALUE IsNativeError(VALUE self);
402
+ static VALUE IsRegExp(VALUE self);
403
+ // VALUE ToBoolean(VALUE self);
404
+ // VALUE ToNumber(VALUE self);
405
+ static VALUE ToString(VALUE self);
406
+ static VALUE ToDetailString(VALUE self);
407
+ static VALUE ToObject(VALUE self);
408
+ // static VALUE ToInteger(VALUE self);
409
+ // static VALUE ToUint32(VALUE self);
410
+ // static VALUE ToInt32(VALUE self);
411
+ // static VALUE ToArrayIndex(VALUE self);
412
+ static VALUE BooleanValue(VALUE self);
413
+ static VALUE NumberValue(VALUE self);
414
+ static VALUE IntegerValue(VALUE self);
415
+ static VALUE Uint32Value(VALUE self);
416
+ static VALUE Int32Value(VALUE self);
417
+
418
+ static VALUE Equals(VALUE self, VALUE other);
419
+ static VALUE StrictEquals(VALUE self, VALUE other);
420
+ inline Value(VALUE value) : Ref<v8::Value>(value) {}
421
+ inline Value(v8::Handle<v8::Value> value) : Ref<v8::Value>(value) {}
422
+ virtual operator VALUE();
423
+ virtual operator v8::Handle<v8::Value>() const;
424
+ static VALUE Empty;
425
+ };
426
+
427
+ class Primitive: public Ref<v8::Primitive> {
428
+ public:
429
+ static void Init();
430
+ inline Primitive(VALUE value) : Ref<v8::Primitive>(value) {}
431
+ inline Primitive(v8::Handle<v8::Primitive> primitive) : Ref<v8::Primitive>(primitive) {}
432
+ };
433
+
434
+ class String: public Ref<v8::String> {
435
+ public:
436
+ static void Init();
437
+ static VALUE New(VALUE self, VALUE value);
438
+ static VALUE NewSymbol(VALUE self, VALUE string);
439
+ static VALUE Utf8Value(VALUE self);
440
+ static VALUE Concat(VALUE self, VALUE left, VALUE right);
441
+
442
+ inline String(VALUE value) : Ref<v8::String>(value) {}
443
+ inline String(v8::Handle<v8::String> string) : Ref<v8::String>(string) {}
444
+ virtual operator v8::Handle<v8::String>() const;
445
+ };
446
+
447
+ class PropertyAttribute: public Enum<v8::PropertyAttribute> {
448
+ public:
449
+ inline PropertyAttribute(VALUE value) : Enum<v8::PropertyAttribute>(value, v8::None) {}
450
+ };
451
+ class AccessControl: public Enum<v8::AccessControl> {
452
+ public:
453
+ inline AccessControl(VALUE value) : Enum<v8::AccessControl>(value, v8::DEFAULT) {}
454
+ };
455
+
456
+ class Accessor {
457
+ public:
458
+ static void Init();
459
+ Accessor(VALUE get, VALUE set, VALUE data);
460
+ Accessor(VALUE get, VALUE set, VALUE query, VALUE deleter, VALUE enumerator, VALUE data);
461
+ Accessor(v8::Handle<v8::Value> value);
462
+
463
+ inline v8::AccessorGetter accessorGetter() {return &AccessorGetter;}
464
+ inline v8::AccessorSetter accessorSetter() {return RTEST(set) ? &AccessorSetter : 0;}
465
+
466
+ inline v8::NamedPropertyGetter namedPropertyGetter() {return &NamedPropertyGetter;}
467
+ inline v8::NamedPropertySetter namedPropertySetter() {return RTEST(set) ? &NamedPropertySetter : 0;}
468
+ inline v8::NamedPropertyQuery namedPropertyQuery() {return RTEST(query) ? &NamedPropertyQuery : 0;}
469
+ inline v8::NamedPropertyDeleter namedPropertyDeleter() {return RTEST(deleter) ? &NamedPropertyDeleter : 0;}
470
+ inline v8::NamedPropertyEnumerator namedPropertyEnumerator() {return RTEST(enumerator) ? &NamedPropertyEnumerator : 0;}
471
+
472
+ inline v8::IndexedPropertyGetter indexedPropertyGetter() {return &IndexedPropertyGetter;}
473
+ inline v8::IndexedPropertySetter indexedPropertySetter() {return RTEST(set) ? &IndexedPropertySetter : 0;}
474
+ inline v8::IndexedPropertyQuery indexedPropertyQuery() {return RTEST(query) ? &IndexedPropertyQuery : 0;}
475
+ inline v8::IndexedPropertyDeleter indexedPropertyDeleter() {return RTEST(deleter) ? &IndexedPropertyDeleter : 0;}
476
+ inline v8::IndexedPropertyEnumerator indexedPropertyEnumerator() {return RTEST(enumerator) ? &IndexedPropertyEnumerator : 0;}
477
+
478
+ operator v8::Handle<v8::Value>();
479
+
480
+ class Info {
481
+ public:
482
+ Info(const v8::AccessorInfo& info);
483
+ Info(VALUE value);
484
+ static VALUE This(VALUE self);
485
+ static VALUE Holder(VALUE self);
486
+ static VALUE Data(VALUE self);
487
+ operator VALUE();
488
+ inline const v8::AccessorInfo* operator->() {return this->info;}
489
+ v8::Handle<v8::Value> get(v8::Local<v8::String> property);
490
+ v8::Handle<v8::Value> set(v8::Local<v8::String> property, v8::Local<v8::Value> value);
491
+ v8::Handle<v8::Integer> query(v8::Local<v8::String> property);
492
+ v8::Handle<v8::Boolean> remove(v8::Local<v8::String> property);
493
+ v8::Handle<v8::Array> enumerateNames();
494
+ v8::Handle<v8::Value> get(uint32_t index);
495
+ v8::Handle<v8::Value> set(uint32_t index, v8::Local<v8::Value> value);
496
+ v8::Handle<v8::Integer> query(uint32_t index);
497
+ v8::Handle<v8::Boolean> remove(uint32_t index);
498
+ v8::Handle<v8::Array> enumerateIndices();
499
+
500
+ static VALUE Class;
501
+ private:
502
+ const v8::AccessorInfo* info;
503
+ };
504
+ friend class Info;
505
+ private:
506
+ static v8::Handle<v8::Value> AccessorGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info);
507
+ static void AccessorSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
508
+
509
+ static v8::Handle<v8::Value> NamedPropertyGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info);
510
+ static v8::Handle<v8::Value> NamedPropertySetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
511
+ static v8::Handle<v8::Integer> NamedPropertyQuery(v8::Local<v8::String> property, const v8::AccessorInfo& info);
512
+ static v8::Handle<v8::Boolean> NamedPropertyDeleter(v8::Local<v8::String> property, const v8::AccessorInfo& info);
513
+ static v8::Handle<v8::Array> NamedPropertyEnumerator(const v8::AccessorInfo& info);
514
+
515
+ static v8::Handle<v8::Value> IndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info);
516
+ static v8::Handle<v8::Value> IndexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info);
517
+ static v8::Handle<v8::Integer> IndexedPropertyQuery(uint32_t index, const v8::AccessorInfo& info);
518
+ static v8::Handle<v8::Boolean> IndexedPropertyDeleter(uint32_t index, const v8::AccessorInfo& info);
519
+ static v8::Handle<v8::Array> IndexedPropertyEnumerator(const v8::AccessorInfo& info);
520
+
521
+ void wrap(v8::Handle<v8::Object> wrapper, int index, VALUE value);
522
+ VALUE unwrap(v8::Handle<v8::Object> wrapper, int index);
523
+ VALUE get;
524
+ VALUE set;
525
+ VALUE query;
526
+ VALUE deleter;
527
+ VALUE enumerator;
528
+ VALUE data;
529
+ };
530
+
531
+ class Invocation {
532
+ public:
533
+ static void Init();
534
+ Invocation(VALUE code, VALUE data);
535
+ Invocation(v8::Handle<v8::Value> wrapper);
536
+ operator v8::InvocationCallback();
537
+ operator v8::Handle<v8::Value>();
538
+ static v8::Handle<v8::Value> Callback(const v8::Arguments& args);
539
+
540
+ class Arguments {
541
+ public:
542
+ static void Init();
543
+ Arguments(const v8::Arguments& args);
544
+ Arguments(VALUE value);
545
+ inline const v8::Arguments* operator->() {return this->args;}
546
+ inline const v8::Arguments operator*() {return *this->args;}
547
+ v8::Handle<v8::Value> Call();
548
+
549
+ static VALUE Length(VALUE self);
550
+ static VALUE Get(VALUE self, VALUE index);
551
+ static VALUE Callee(VALUE self);
552
+ static VALUE This(VALUE self);
553
+ static VALUE Holder(VALUE self);
554
+ static VALUE IsConstructCall(VALUE self);
555
+ static VALUE Data(VALUE self);
556
+ private:
557
+ const v8::Arguments* args;
558
+ static VALUE Class;
559
+ };
560
+ private:
561
+ VALUE code;
562
+ VALUE data;
563
+ friend class Arguments;
564
+ };
565
+
566
+ class Object : public Ref<v8::Object> {
567
+ public:
568
+ static void Init();
569
+ static VALUE New(VALUE self);
570
+ static VALUE Set(VALUE self, VALUE key, VALUE value);
571
+ static VALUE ForceSet(VALUE self, VALUE key, VALUE value);
572
+ static VALUE Get(VALUE self, VALUE key);
573
+ static VALUE GetPropertyAttributes(VALUE self, VALUE key);
574
+ static VALUE Has(VALUE self, VALUE key);
575
+ static VALUE Delete(VALUE self, VALUE key);
576
+ static VALUE ForceDelete(VALUE self, VALUE key);
577
+ static VALUE SetAccessor(int argc, VALUE* argv, VALUE self);
578
+ static VALUE GetPropertyNames(VALUE self);
579
+ static VALUE GetOwnPropertyNames(VALUE self);
580
+ static VALUE GetPrototype(VALUE self);
581
+ static VALUE SetPrototype(VALUE self, VALUE prototype);
582
+ static VALUE FindInstanceInPrototypeChain(VALUE self, VALUE impl);
583
+ static VALUE ObjectProtoToString(VALUE self);
584
+ static VALUE GetConstructorName(VALUE self);
585
+ static VALUE InternalFieldCount(VALUE self);
586
+ static VALUE GetInternalField(VALUE self, VALUE idx);
587
+ static VALUE SetInternalField(VALUE self, VALUE idx, VALUE value);
588
+ static VALUE HasOwnProperty(VALUE self, VALUE key);
589
+ static VALUE HasRealNamedProperty(VALUE self, VALUE key);
590
+ static VALUE HasRealIndexedProperty(VALUE self, VALUE idx);
591
+ static VALUE HasRealNamedCallbackProperty(VALUE self, VALUE key);
592
+ static VALUE GetRealNamedPropertyInPrototypeChain(VALUE self, VALUE key);
593
+ static VALUE GetRealNamedProperty(VALUE self, VALUE key);
594
+ static VALUE HasNamedLookupInterceptor(VALUE self);
595
+ static VALUE HasIndexedLookupInterceptor(VALUE self);
596
+ static VALUE TurnOnAccessCheck(VALUE self);
597
+ static VALUE GetIdentityHash(VALUE self);
598
+ static VALUE SetHiddenValue(VALUE self, VALUE key, VALUE value);
599
+ static VALUE GetHiddenValue(VALUE self, VALUE key);
600
+ static VALUE DeleteHiddenValue(VALUE self, VALUE key);
601
+ static VALUE IsDirty(VALUE self);
602
+ static VALUE Clone(VALUE self);
603
+ static VALUE CreationContext(VALUE self);
604
+ static VALUE SetIndexedPropertiesToPixelData(VALUE self, VALUE data, VALUE length);
605
+ static VALUE GetIndexedPropertiesPixelData(VALUE self);
606
+ static VALUE HasIndexedPropertiesInPixelData(VALUE self);
607
+ static VALUE GetIndexedPropertiesPixelDataLength(VALUE self);
608
+ static VALUE SetIndexedPropertiesToExternalArrayData(VALUE self);
609
+ static VALUE HasIndexedPropertiesInExternalArrayData(VALUE self);
610
+ static VALUE GetIndexedPropertiesExternalArrayData(VALUE self);
611
+ static VALUE GetIndexedPropertiesExternalArrayDataType(VALUE self);
612
+ static VALUE GetIndexedPropertiesExternalArrayDataLength(VALUE self);
613
+ static VALUE IsCallable(VALUE self);
614
+ static VALUE CallAsFunction(VALUE self, VALUE recv, VALUE argv);
615
+ static VALUE CallAsConstructor(VALUE self, VALUE argv);
616
+
617
+ inline Object(VALUE value) : Ref<v8::Object>(value) {}
618
+ inline Object(v8::Handle<v8::Object> object) : Ref<v8::Object>(object) {}
619
+ virtual operator VALUE();
620
+
621
+ protected:
622
+ VALUE downcast();
623
+ };
624
+
625
+ class Array : public Ref<v8::Array> {
626
+ public:
627
+ static void Init();
628
+ static VALUE New(int argc, VALUE argv[], VALUE self);
629
+ static VALUE Length(VALUE self);
630
+ static VALUE CloneElementAt(VALUE self, VALUE index);
631
+
632
+ inline Array(v8::Handle<v8::Array> array) : Ref<v8::Array>(array) {}
633
+ inline Array(VALUE value) : Ref<v8::Array>(value) {}
634
+ };
635
+
636
+ class Function : public Ref<v8::Function> {
637
+ public:
638
+ static void Init();
639
+ static VALUE NewInstance(int argc, VALUE argv[], VALUE self);
640
+ static VALUE Call(VALUE self, VALUE receiver, VALUE argv);
641
+ static VALUE SetName(VALUE self, VALUE name);
642
+ static VALUE GetName(VALUE self);
643
+ static VALUE GetInferredName(VALUE self);
644
+ static VALUE GetScriptLineNumber(VALUE self);
645
+ static VALUE GetScriptColumnNumber(VALUE self);
646
+ static VALUE GetScriptId(VALUE self);
647
+ static VALUE GetScriptOrigin(VALUE self);
648
+
649
+ inline Function(VALUE value) : Ref<v8::Function>(value) {}
650
+ inline Function(v8::Handle<v8::Function> function) : Ref<v8::Function>(function) {}
651
+ };
652
+
653
+ class Date : public Ref<v8::Date> {
654
+ public:
655
+ static void Init();
656
+ static VALUE New(VALUE self, VALUE time);
657
+ static VALUE NumberValue(VALUE self);
658
+
659
+ inline Date(VALUE value) : Ref<v8::Date>(value) {}
660
+ inline Date(v8::Handle<v8::Date> date) : Ref<v8::Date>(date) {}
661
+ };
662
+
663
+ class Signature : public Ref<v8::Signature> {
664
+ public:
665
+ static void Init();
666
+ static VALUE New(int argc, VALUE argv[], VALUE self);
667
+
668
+ inline Signature(v8::Handle<v8::Signature> sig) : Ref<v8::Signature>(sig) {}
669
+ inline Signature(VALUE value) : Ref<v8::Signature>(value) {}
670
+ };
671
+
672
+ class Template : public Ref<v8::Template> {
673
+ public:
674
+ static void Init();
675
+ static VALUE Set(int argc, VALUE argv[], VALUE self);
676
+ inline Template(v8::Handle<v8::Template> t) : Ref<v8::Template>(t) {}
677
+ inline Template(VALUE value) : Ref<v8::Template>(value) {}
678
+ };
679
+
680
+ class ObjectTemplate : public Ref<v8::ObjectTemplate> {
681
+ public:
682
+ static void Init();
683
+ static VALUE New(VALUE self);
684
+ static VALUE NewInstance(VALUE self);
685
+ static VALUE SetAccessor(int argc, VALUE argv[], VALUE self);
686
+ static VALUE SetNamedPropertyHandler(int argc, VALUE argv[], VALUE self);
687
+ static VALUE SetIndexedPropertyHandler(int argc, VALUE argv[], VALUE self);
688
+ static VALUE SetCallAsFunctionHandler(int argc, VALUE argv[], VALUE self);
689
+ static VALUE MarkAsUndetectable(VALUE self);
690
+ static VALUE SetAccessCheckCallbacks(int argc, VALUE argv[], VALUE self);
691
+ static VALUE InternalFieldCount(VALUE self);
692
+ static VALUE SetInternalFieldCount(VALUE self, VALUE count);
693
+
694
+ inline ObjectTemplate(VALUE value) : Ref<v8::ObjectTemplate>(value) {}
695
+ inline ObjectTemplate(v8::Handle<v8::ObjectTemplate> t) : Ref<v8::ObjectTemplate>(t) {}
696
+ };
697
+
698
+ class FunctionTemplate : public Ref<v8::FunctionTemplate> {
699
+ public:
700
+ static void Init();
701
+ static VALUE New(int argc, VALUE argv[], VALUE self);
702
+ static VALUE GetFunction(VALUE self);
703
+ static VALUE SetCallHandler(int argc, VALUE argv[], VALUE self);
704
+ static VALUE InstanceTemplate(VALUE self);
705
+ static VALUE Inherit(VALUE self, VALUE parent);
706
+ static VALUE PrototypeTemplate(VALUE self);
707
+ static VALUE SetClassName(VALUE self, VALUE name);
708
+ static VALUE SetHiddenPrototype(VALUE self, VALUE value);
709
+ static VALUE ReadOnlyPrototype(VALUE self);
710
+ static VALUE HasInstance(VALUE self, VALUE object);
711
+
712
+ inline FunctionTemplate(VALUE value) : Ref<v8::FunctionTemplate>(value) {}
713
+ inline FunctionTemplate(v8::Handle<v8::FunctionTemplate> t) : Ref<v8::FunctionTemplate>(t) {}
714
+ };
715
+
716
+ class Message : public Ref<v8::Message> {
717
+ public:
718
+ static void Init();
719
+ inline Message(v8::Handle<v8::Message> message) : Ref<v8::Message>(message) {}
720
+ inline Message(VALUE value) : Ref<v8::Message>(value) {}
721
+
722
+ static VALUE Get(VALUE self);
723
+ static VALUE GetSourceLine(VALUE self);
724
+ static VALUE GetScriptResourceName(VALUE self);
725
+ static VALUE GetScriptData(VALUE self);
726
+ static VALUE GetStackTrace(VALUE self);
727
+ static VALUE GetLineNumber(VALUE self);
728
+ static VALUE GetStartPosition(VALUE self);
729
+ static VALUE GetEndPosition(VALUE self);
730
+ static VALUE GetStartColumn(VALUE self);
731
+ static VALUE GetEndColumn(VALUE self);
732
+ static inline VALUE kNoLineNumberInfo(VALUE self) {return INT2FIX(v8::Message::kNoLineNumberInfo);}
733
+ static inline VALUE kNoColumnInfo(VALUE self) {return INT2FIX(v8::Message::kNoColumnInfo);}
734
+ };
735
+
736
+ class Stack {
737
+ public:
738
+ static void Init();
739
+
740
+ class Trace : public Ref<v8::StackTrace> {
741
+ public:
742
+ class StackTraceOptions : public Enum<v8::StackTrace::StackTraceOptions> {
743
+ public:
744
+ inline StackTraceOptions(VALUE value) : Enum<v8::StackTrace::StackTraceOptions>(value, v8::StackTrace::kOverview) {}
745
+ };
746
+ public:
747
+ inline Trace(v8::Handle<v8::StackTrace> trace) : Ref<v8::StackTrace>(trace) {}
748
+ inline Trace(VALUE value) : Ref<v8::StackTrace>(value) {}
749
+ static inline VALUE kLineNumber(VALUE self) {return INT2FIX(v8::StackTrace::kLineNumber);}
750
+ static inline VALUE kColumnOffset(VALUE self) {return INT2FIX(v8::StackTrace::kColumnOffset);}
751
+ static inline VALUE kScriptName(VALUE self) {return INT2FIX(v8::StackTrace::kScriptName);}
752
+ static inline VALUE kFunctionName(VALUE self) {return INT2FIX(v8::StackTrace::kFunctionName);}
753
+ static inline VALUE kIsEval(VALUE self) {return INT2FIX(v8::StackTrace::kIsEval);}
754
+ static inline VALUE kIsConstructor(VALUE self) {return INT2FIX(v8::StackTrace::kIsConstructor);}
755
+ static inline VALUE kScriptNameOrSourceURL(VALUE self) {return INT2FIX(v8::StackTrace::kScriptNameOrSourceURL);}
756
+ static inline VALUE kOverview(VALUE self) {return INT2FIX(v8::StackTrace::kOverview);}
757
+ static inline VALUE kDetailed(VALUE self) {return INT2FIX(v8::StackTrace::kDetailed);}
758
+
759
+ static VALUE GetFrame(VALUE self, VALUE index);
760
+ static VALUE GetFrameCount(VALUE self);
761
+ static VALUE AsArray(VALUE self);
762
+ static VALUE CurrentStackTrace(int argc, VALUE argv[], VALUE self);
763
+ };
764
+ class Frame : public Ref<v8::StackFrame> {
765
+ public:
766
+ inline Frame(v8::Handle<v8::StackFrame> frame) : Ref<v8::StackFrame>(frame) {}
767
+ inline Frame(VALUE value) : Ref<v8::StackFrame>(value) {}
768
+ static VALUE GetLineNumber(VALUE self);
769
+ static VALUE GetColumn(VALUE self);
770
+ static VALUE GetScriptName(VALUE self);
771
+ static VALUE GetScriptNameOrSourceURL(VALUE self);
772
+ static VALUE GetFunctionName(VALUE self);
773
+ static VALUE IsEval(VALUE self);
774
+ static VALUE IsConstructor(VALUE self);
775
+ };
776
+ };
777
+
778
+ class TryCatch {
779
+ public:
780
+ static void Init();
781
+ TryCatch(v8::TryCatch*);
782
+ TryCatch(VALUE value);
783
+ operator VALUE();
784
+ inline v8::TryCatch* operator->() {return this->impl;}
785
+ static VALUE HasCaught(VALUE self);
786
+ static VALUE CanContinue(VALUE self);
787
+ static VALUE ReThrow(VALUE self);
788
+ static VALUE Exception(VALUE self);
789
+ static VALUE StackTrace(VALUE self);
790
+ static VALUE Message(VALUE self);
791
+ static VALUE Reset(VALUE self);
792
+ static VALUE SetVerbose(VALUE self, VALUE value);
793
+ static VALUE SetCaptureMessage(VALUE self, VALUE value);
794
+ private:
795
+ static VALUE doTryCatch(int argc, VALUE argv[], VALUE self);
796
+ static VALUE setupAndCall(int* state, VALUE code);
797
+ static VALUE doCall(VALUE code);
798
+ static VALUE Class;
799
+ v8::TryCatch* impl;
800
+ };
801
+
802
+ class Locker {
803
+ public:
804
+ static void Init();
805
+ static VALUE StartPreemption(VALUE self, VALUE every_n_ms);
806
+ static VALUE StopPreemption(VALUE self);
807
+ static VALUE IsLocked(VALUE self);
808
+ static VALUE IsActive(VALUE self);
809
+ static VALUE doLock(int argc, VALUE* argv, VALUE self);
810
+ static VALUE setupLockAndCall(int* state, VALUE code);
811
+ static VALUE doLockCall(VALUE code);
812
+ static VALUE doUnlock(int argc, VALUE* argv, VALUE self);
813
+ static VALUE setupUnlockAndCall(int* state, VALUE code);
814
+ static VALUE doUnlockCall(VALUE code);
815
+ };
816
+
817
+ class HeapStatistics : public Pointer<v8::HeapStatistics> {
818
+ public:
819
+ static void Init();
820
+ static VALUE initialize(VALUE self);
821
+ static VALUE total_heap_size(VALUE self);
822
+ static VALUE total_heap_size_executable(VALUE self);
823
+ static VALUE total_physical_size(VALUE self);
824
+ static VALUE used_heap_size(VALUE self);
825
+ static VALUE heap_size_limit(VALUE self);
826
+
827
+ inline HeapStatistics(v8::HeapStatistics* stats) : Pointer<v8::HeapStatistics>(stats) {}
828
+ inline HeapStatistics(VALUE value) : Pointer<v8::HeapStatistics>(value) {}
829
+ };
830
+
831
+ class ResourceConstraints : Pointer<v8::ResourceConstraints> {
832
+ public:
833
+ static void Init();
834
+ static VALUE initialize(VALUE self);
835
+ static VALUE max_young_space_size(VALUE self);
836
+ static VALUE set_max_young_space_size(VALUE self, VALUE value);
837
+ static VALUE max_old_space_size(VALUE self);
838
+ static VALUE set_max_old_space_size(VALUE self, VALUE value);
839
+ static VALUE max_executable_size(VALUE self);
840
+ static VALUE set_max_executable_size(VALUE self, VALUE value);
841
+
842
+ static VALUE SetResourceConstraints(VALUE self, VALUE constraints);
843
+
844
+ inline ResourceConstraints(v8::ResourceConstraints* o) : Pointer<v8::ResourceConstraints>(o) {};
845
+ inline ResourceConstraints(VALUE value) : Pointer<v8::ResourceConstraints>(value) {}
846
+ };
847
+
848
+ class Exception {
849
+ public:
850
+ static void Init();
851
+ static VALUE ThrowException(VALUE self, VALUE exception);
852
+ static VALUE RangeError(VALUE self, VALUE message);
853
+ static VALUE ReferenceError(VALUE self, VALUE message);
854
+ static VALUE SyntaxError(VALUE self, VALUE message);
855
+ static VALUE TypeError(VALUE self, VALUE message);
856
+ static VALUE Error(VALUE self, VALUE message);
857
+ };
858
+
859
+ class Constants {
860
+ public:
861
+ static void Init();
862
+ static VALUE Undefined(VALUE self);
863
+ static VALUE Null(VALUE self);
864
+ static VALUE True(VALUE self);
865
+ static VALUE False(VALUE self);
866
+
867
+ private:
868
+ template <class R, class V> static VALUE cached(VALUE* storage, v8::Handle<V> value) {
869
+ if (!RTEST(*storage)) {
870
+ *storage = R(value);
871
+ }
872
+ return *storage;
873
+ }
874
+ static VALUE _Undefined;
875
+ static VALUE _Null;
876
+ static VALUE _True;
877
+ static VALUE _False;
878
+ };
879
+
880
+ class V8 {
881
+ public:
882
+ static void Init();
883
+ static VALUE IdleNotification(int argc, VALUE argv[], VALUE self);
884
+ static VALUE SetFlagsFromString(VALUE self, VALUE string);
885
+ static VALUE SetFlagsFromCommandLine(VALUE self, VALUE args, VALUE remove_flags);
886
+ static VALUE AdjustAmountOfExternalAllocatedMemory(VALUE self, VALUE change_in_bytes);
887
+ static VALUE PauseProfiler(VALUE self);
888
+ static VALUE ResumeProfiler(VALUE self);
889
+ static VALUE IsProfilerPaused(VALUE self);
890
+ static VALUE GetCurrentThreadId(VALUE self);
891
+ static VALUE TerminateExecution(VALUE self, VALUE thread_id);
892
+ static VALUE IsExecutionTerminating(VALUE self);
893
+ static VALUE Dispose(VALUE self);
894
+ static VALUE LowMemoryNotification(VALUE self);
895
+ static VALUE ContextDisposedNotification(VALUE self);
896
+
897
+ static VALUE SetCaptureStackTraceForUncaughtExceptions(int argc, VALUE argv[], VALUE self);
898
+ static VALUE GetHeapStatistics(VALUE self, VALUE statistics_ptr);
899
+ static VALUE GetVersion(VALUE self);
900
+ };
901
+
902
+ class ClassBuilder {
903
+ public:
904
+ ClassBuilder() {};
905
+ ClassBuilder(const char* name, VALUE superclass = rb_cObject);
906
+ ClassBuilder(const char* name, const char* supername);
907
+ ClassBuilder& defineConst(const char* name, VALUE value);
908
+ ClassBuilder& defineMethod(const char* name, VALUE (*impl)(int, VALUE*, VALUE));
909
+ ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE));
910
+ ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE));
911
+ ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE));
912
+ ClassBuilder& defineMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE, VALUE));
913
+ ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(int, VALUE*, VALUE));
914
+ ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE));
915
+ ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE));
916
+ ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE));
917
+ ClassBuilder& defineSingletonMethod(const char* name, VALUE (*impl)(VALUE, VALUE, VALUE, VALUE));
918
+ ClassBuilder& defineEnumConst(const char* name, int value);
919
+ ClassBuilder& store(VALUE* storage);
920
+ inline operator VALUE() {return this->value;}
921
+ protected:
922
+ VALUE value;
923
+ };
924
+
925
+ class ModuleBuilder : public ClassBuilder {
926
+ public:
927
+ inline ModuleBuilder(const char* name) {
928
+ this->value = rb_eval_string(name);
929
+ }
930
+ };
931
+
932
+ }
933
+
934
+ #endif