therubyracer-xcode 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +14 -0
- data/Changelog.md +263 -0
- data/Gemfile +12 -0
- data/README.md +227 -0
- data/Rakefile +42 -0
- data/benchmarks.rb +218 -0
- data/ext/v8/accessor.cc +181 -0
- data/ext/v8/array.cc +26 -0
- data/ext/v8/backref.cc +45 -0
- data/ext/v8/constants.cc +34 -0
- data/ext/v8/constraints.cc +52 -0
- data/ext/v8/context.cc +130 -0
- data/ext/v8/date.cc +18 -0
- data/ext/v8/exception.cc +38 -0
- data/ext/v8/extconf.rb +34 -0
- data/ext/v8/external.cc +43 -0
- data/ext/v8/function.cc +58 -0
- data/ext/v8/gc.cc +43 -0
- data/ext/v8/handles.cc +34 -0
- data/ext/v8/heap.cc +35 -0
- data/ext/v8/init.cc +39 -0
- data/ext/v8/invocation.cc +86 -0
- data/ext/v8/locker.cc +77 -0
- data/ext/v8/message.cc +51 -0
- data/ext/v8/object.cc +335 -0
- data/ext/v8/primitive.cc +8 -0
- data/ext/v8/rr.cc +83 -0
- data/ext/v8/rr.h +934 -0
- data/ext/v8/script.cc +115 -0
- data/ext/v8/signature.cc +18 -0
- data/ext/v8/stack.cc +76 -0
- data/ext/v8/string.cc +47 -0
- data/ext/v8/template.cc +175 -0
- data/ext/v8/trycatch.cc +87 -0
- data/ext/v8/v8.cc +87 -0
- data/ext/v8/value.cc +239 -0
- data/lib/therubyracer.rb +1 -0
- data/lib/v8/access/indices.rb +40 -0
- data/lib/v8/access/invocation.rb +47 -0
- data/lib/v8/access/names.rb +65 -0
- data/lib/v8/access.rb +5 -0
- data/lib/v8/array.rb +26 -0
- data/lib/v8/context.rb +258 -0
- data/lib/v8/conversion/array.rb +11 -0
- data/lib/v8/conversion/class.rb +119 -0
- data/lib/v8/conversion/code.rb +38 -0
- data/lib/v8/conversion/fixnum.rb +11 -0
- data/lib/v8/conversion/fundamental.rb +11 -0
- data/lib/v8/conversion/hash.rb +11 -0
- data/lib/v8/conversion/indentity.rb +31 -0
- data/lib/v8/conversion/method.rb +26 -0
- data/lib/v8/conversion/object.rb +28 -0
- data/lib/v8/conversion/primitive.rb +7 -0
- data/lib/v8/conversion/proc.rb +5 -0
- data/lib/v8/conversion/reference.rb +16 -0
- data/lib/v8/conversion/string.rb +12 -0
- data/lib/v8/conversion/symbol.rb +7 -0
- data/lib/v8/conversion/time.rb +13 -0
- data/lib/v8/conversion.rb +36 -0
- data/lib/v8/error.rb +169 -0
- data/lib/v8/function.rb +28 -0
- data/lib/v8/object.rb +79 -0
- data/lib/v8/stack.rb +85 -0
- data/lib/v8/version.rb +3 -0
- data/lib/v8/weak.rb +82 -0
- data/lib/v8.rb +30 -0
- data/spec/c/array_spec.rb +19 -0
- data/spec/c/constants_spec.rb +22 -0
- data/spec/c/exception_spec.rb +28 -0
- data/spec/c/external_spec.rb +11 -0
- data/spec/c/function_spec.rb +48 -0
- data/spec/c/handles_spec.rb +31 -0
- data/spec/c/locker_spec.rb +36 -0
- data/spec/c/object_spec.rb +47 -0
- data/spec/c/script_spec.rb +30 -0
- data/spec/c/string_spec.rb +18 -0
- data/spec/c/template_spec.rb +31 -0
- data/spec/c/trycatch_spec.rb +52 -0
- data/spec/mem/blunt_spec.rb +42 -0
- data/spec/redjs_spec.rb +10 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/threading_spec.rb +64 -0
- data/spec/v8/context_spec.rb +19 -0
- data/spec/v8/conversion_spec.rb +52 -0
- data/spec/v8/error_spec.rb +167 -0
- data/spec/v8/function_spec.rb +9 -0
- data/spec/v8/object_spec.rb +15 -0
- data/thefrontside.png +0 -0
- data/therubyracer.gemspec +22 -0
- metadata +186 -0
data/ext/v8/object.cc
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
#include "rr.h"
|
2
|
+
|
3
|
+
namespace rr {
|
4
|
+
|
5
|
+
void Object::Init() {
|
6
|
+
ClassBuilder("Object", Value::Class).
|
7
|
+
defineSingletonMethod("New", &New).
|
8
|
+
defineMethod("Set", &Set).
|
9
|
+
defineMethod("ForceSet", &ForceSet).
|
10
|
+
defineMethod("Get", &Get).
|
11
|
+
defineMethod("GetPropertyAttributes", &GetPropertyAttributes).
|
12
|
+
defineMethod("Has", &Has).
|
13
|
+
defineMethod("Delete", &Delete).
|
14
|
+
defineMethod("ForceDelete", &ForceDelete).
|
15
|
+
defineMethod("SetAccessor", &SetAccessor).
|
16
|
+
defineMethod("GetPropertyNames", &GetPropertyNames).
|
17
|
+
defineMethod("GetOwnPropertyNames", &GetOwnPropertyNames).
|
18
|
+
defineMethod("GetPrototype", &GetPrototype).
|
19
|
+
defineMethod("SetPrototype", &SetPrototype).
|
20
|
+
defineMethod("FindInstanceInPrototypeChain", &FindInstanceInPrototypeChain).
|
21
|
+
defineMethod("ObjectProtoToString", &ObjectProtoToString).
|
22
|
+
defineMethod("GetConstructorName", &GetConstructorName).
|
23
|
+
defineMethod("InternalFieldCount", &InternalFieldCount).
|
24
|
+
defineMethod("GetInternalField", &GetInternalField).
|
25
|
+
defineMethod("SetInternalField", &SetInternalField).
|
26
|
+
defineMethod("HasOwnProperty", &HasOwnProperty).
|
27
|
+
defineMethod("HasRealNamedProperty", &HasRealNamedProperty).
|
28
|
+
defineMethod("HasRealIndexedProperty", &HasRealIndexedProperty).
|
29
|
+
defineMethod("HasRealNamedCallbackProperty", &HasRealNamedCallbackProperty).
|
30
|
+
defineMethod("GetRealNamedPropertyInPrototypeChain", &GetRealNamedPropertyInPrototypeChain).
|
31
|
+
defineMethod("GetRealNamedProperty", &GetRealNamedProperty).
|
32
|
+
defineMethod("HasNamedLookupInterceptor", &HasNamedLookupInterceptor).
|
33
|
+
defineMethod("HasIndexedLookupInterceptor", &HasIndexedLookupInterceptor).
|
34
|
+
defineMethod("TurnOnAccessCheck", &TurnOnAccessCheck).
|
35
|
+
defineMethod("GetIdentityHash", &GetIdentityHash).
|
36
|
+
defineMethod("SetHiddenValue", &SetHiddenValue).
|
37
|
+
defineMethod("GetHiddenValue", &GetHiddenValue).
|
38
|
+
defineMethod("DeleteHiddenValue", &DeleteHiddenValue).
|
39
|
+
defineMethod("IsDirty", &IsDirty).
|
40
|
+
defineMethod("Clone", &Clone).
|
41
|
+
defineMethod("CreationContext", &CreationContext).
|
42
|
+
defineMethod("SetIndexedPropertiesToPixelData", &SetIndexedPropertiesToPixelData).
|
43
|
+
defineMethod("GetIndexedPropertiesPixelData", &GetIndexedPropertiesPixelData).
|
44
|
+
defineMethod("HasIndexedPropertiesToPixelData", &HasIndexedPropertiesInPixelData).
|
45
|
+
defineMethod("GetIndexedPropertiesPixelDataLength", &GetIndexedPropertiesPixelDataLength).
|
46
|
+
defineMethod("SetIndexedPropertiesToExternalArrayData", &SetIndexedPropertiesToExternalArrayData).
|
47
|
+
defineMethod("HasIndexedPropertiesInExternalArrayData", &HasIndexedPropertiesInExternalArrayData).
|
48
|
+
defineMethod("GetIndexedPropertiesExternalArrayData", &GetIndexedPropertiesExternalArrayData).
|
49
|
+
defineMethod("GetIndexedPropertiesExternalArrayDataType", &GetIndexedPropertiesExternalArrayDataType).
|
50
|
+
defineMethod("GetIndexedPropertiesExternalArrayDataLength", &GetIndexedPropertiesExternalArrayDataLength).
|
51
|
+
defineMethod("IsCallable", &IsCallable).
|
52
|
+
defineMethod("CallAsFunction", &CallAsFunction).
|
53
|
+
defineMethod("CallAsConstructor", &CallAsConstructor).
|
54
|
+
store(&Class);
|
55
|
+
ClassBuilder("PropertyAttribute").
|
56
|
+
defineEnumConst("None", v8::None).
|
57
|
+
defineEnumConst("ReadOnly", v8::ReadOnly).
|
58
|
+
defineEnumConst("DontEnum", v8::DontEnum).
|
59
|
+
defineEnumConst("DontDelete", v8::DontDelete);
|
60
|
+
ClassBuilder("AccessControl").
|
61
|
+
defineEnumConst("DEFAULT", v8::DEFAULT).
|
62
|
+
defineEnumConst("ALL_CAN_READ", v8::ALL_CAN_READ).
|
63
|
+
defineEnumConst("ALL_CAN_WRITE", v8::ALL_CAN_WRITE).
|
64
|
+
defineEnumConst("PROHIBITS_OVERWRITING", v8::PROHIBITS_OVERWRITING);
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
VALUE Object::New(VALUE self) {
|
69
|
+
return Object(v8::Object::New());
|
70
|
+
}
|
71
|
+
|
72
|
+
//TODO: Allow setting of property attributes
|
73
|
+
VALUE Object::Set(VALUE self, VALUE key, VALUE value) {
|
74
|
+
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
75
|
+
return Bool(Object(self)->Set(UInt32(key), Value(value)));
|
76
|
+
} else {
|
77
|
+
return Bool(Object(self)->Set(*Value(key), Value(value)));
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
VALUE Object::ForceSet(VALUE self, VALUE key, VALUE value) {
|
82
|
+
return Bool(Object(self)->ForceSet(Value(key), Value(value)));
|
83
|
+
}
|
84
|
+
|
85
|
+
VALUE Object::Get(VALUE self, VALUE key) {
|
86
|
+
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
87
|
+
return Value(Object(self)->Get(UInt32(key)));
|
88
|
+
} else {
|
89
|
+
return Value(Object(self)->Get(*Value(key)));
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
VALUE Object::GetPropertyAttributes(VALUE self, VALUE key) {
|
94
|
+
return PropertyAttribute(Object(self)->GetPropertyAttributes(Value(key)));
|
95
|
+
}
|
96
|
+
|
97
|
+
VALUE Object::Has(VALUE self, VALUE key) {
|
98
|
+
Object obj(self);
|
99
|
+
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
100
|
+
return Bool(obj->Has(UInt32(key)));
|
101
|
+
} else {
|
102
|
+
return Bool(obj->Has(*String(key)));
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
VALUE Object::Delete(VALUE self, VALUE key) {
|
107
|
+
Object obj(self);
|
108
|
+
if (rb_obj_is_kind_of(key, rb_cNumeric)) {
|
109
|
+
return Bool(obj->Delete(UInt32(key)));
|
110
|
+
} else {
|
111
|
+
return Bool(obj->Delete(*String(key)));
|
112
|
+
}
|
113
|
+
}
|
114
|
+
|
115
|
+
VALUE Object::ForceDelete(VALUE self, VALUE key) {
|
116
|
+
return Bool(Object(self)->ForceDelete(Value(key)));
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
VALUE Object::SetAccessor(int argc, VALUE* argv, VALUE self) {
|
121
|
+
VALUE name; VALUE get; VALUE set; VALUE data; VALUE settings; VALUE attribs;
|
122
|
+
rb_scan_args(argc, argv, "24", &name, &get, &set, &data, &settings, &attribs);
|
123
|
+
Accessor access(get, set, data);
|
124
|
+
return Bool(Object(self)->SetAccessor(
|
125
|
+
String(name),
|
126
|
+
access.accessorGetter(),
|
127
|
+
access.accessorSetter(),
|
128
|
+
access,
|
129
|
+
AccessControl(settings),
|
130
|
+
PropertyAttribute(attribs))
|
131
|
+
);
|
132
|
+
}
|
133
|
+
|
134
|
+
Object::operator VALUE() {
|
135
|
+
if (handle.IsEmpty()) {
|
136
|
+
return Qnil;
|
137
|
+
}
|
138
|
+
Backref* backref;
|
139
|
+
v8::Local<v8::String> key(v8::String::NewSymbol("rr::Backref"));
|
140
|
+
v8::Local<v8::Value> external = handle->GetHiddenValue(key);
|
141
|
+
VALUE value;
|
142
|
+
if (external.IsEmpty()) {
|
143
|
+
value = downcast();
|
144
|
+
backref = new Backref(value);
|
145
|
+
handle->SetHiddenValue(key, backref->toExternal());
|
146
|
+
} else {
|
147
|
+
v8::Local<v8::External> wrapper = v8::External::Cast(*external);
|
148
|
+
backref = (Backref*)wrapper->Value();
|
149
|
+
value = backref->get();
|
150
|
+
if (!RTEST(value)) {
|
151
|
+
value = downcast();
|
152
|
+
backref->set(value);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
return value;
|
156
|
+
}
|
157
|
+
|
158
|
+
VALUE Object::downcast() {
|
159
|
+
if (handle->IsFunction()) {
|
160
|
+
return Function((v8::Handle<v8::Function>) v8::Function::Cast(*handle));
|
161
|
+
}
|
162
|
+
if (handle->IsArray()) {
|
163
|
+
return Array((v8::Handle<v8::Array>)v8::Array::Cast(*handle));
|
164
|
+
}
|
165
|
+
if (handle->IsDate()) {
|
166
|
+
// return Date(handle);
|
167
|
+
}
|
168
|
+
if (handle->IsBooleanObject()) {
|
169
|
+
// return BooleanObject(handle);
|
170
|
+
}
|
171
|
+
if (handle->IsNumberObject()) {
|
172
|
+
// return NumberObject(handle);
|
173
|
+
}
|
174
|
+
if (handle->IsStringObject()) {
|
175
|
+
// return StringObject(handle);
|
176
|
+
}
|
177
|
+
if (handle->IsRegExp()) {
|
178
|
+
// return RegExp(handle);
|
179
|
+
}
|
180
|
+
return Ref<v8::Object>::operator VALUE();
|
181
|
+
}
|
182
|
+
|
183
|
+
VALUE Object::GetPropertyNames(VALUE self) {
|
184
|
+
return Array(Object(self)->GetPropertyNames());
|
185
|
+
}
|
186
|
+
|
187
|
+
VALUE Object::GetOwnPropertyNames(VALUE self) {
|
188
|
+
return Array(Object(self)->GetOwnPropertyNames());
|
189
|
+
}
|
190
|
+
|
191
|
+
VALUE Object::GetPrototype(VALUE self) {
|
192
|
+
return Value(Object(self)->GetPrototype());
|
193
|
+
}
|
194
|
+
|
195
|
+
VALUE Object::SetPrototype(VALUE self, VALUE prototype) {
|
196
|
+
return Bool(Object(self)->SetPrototype(Value(prototype)));
|
197
|
+
}
|
198
|
+
|
199
|
+
VALUE Object::FindInstanceInPrototypeChain(VALUE self, VALUE impl) {
|
200
|
+
return Object(Object(self)->FindInstanceInPrototypeChain(FunctionTemplate(impl)));
|
201
|
+
}
|
202
|
+
|
203
|
+
VALUE Object::ObjectProtoToString(VALUE self) {
|
204
|
+
return String(Object(self)->ObjectProtoToString());
|
205
|
+
}
|
206
|
+
|
207
|
+
VALUE Object::GetConstructorName(VALUE self) {
|
208
|
+
return String(Object(self)->GetConstructorName());
|
209
|
+
}
|
210
|
+
|
211
|
+
VALUE Object::InternalFieldCount(VALUE self) {
|
212
|
+
return INT2FIX(Object(self)->InternalFieldCount());
|
213
|
+
}
|
214
|
+
|
215
|
+
VALUE Object::GetInternalField(VALUE self, VALUE idx) {
|
216
|
+
return Value(Object(self)->GetInternalField(NUM2INT(idx)));
|
217
|
+
}
|
218
|
+
|
219
|
+
VALUE Object::SetInternalField(VALUE self, VALUE idx, VALUE value) {
|
220
|
+
Void(Object(self)->SetInternalField(NUM2INT(idx), Value(value)));
|
221
|
+
}
|
222
|
+
|
223
|
+
VALUE Object::HasOwnProperty(VALUE self, VALUE key) {
|
224
|
+
return Bool(Object(self)->HasOwnProperty(String(key)));
|
225
|
+
}
|
226
|
+
|
227
|
+
VALUE Object::HasRealNamedProperty(VALUE self, VALUE key) {
|
228
|
+
return Bool(Object(self)->HasRealNamedProperty(String(key)));
|
229
|
+
}
|
230
|
+
|
231
|
+
VALUE Object::HasRealIndexedProperty(VALUE self, VALUE idx) {
|
232
|
+
return Bool(Object(self)->HasRealIndexedProperty(UInt32(idx)));
|
233
|
+
}
|
234
|
+
|
235
|
+
VALUE Object::HasRealNamedCallbackProperty(VALUE self, VALUE key) {
|
236
|
+
return Bool(Object(self)->HasRealNamedCallbackProperty(String(key)));
|
237
|
+
}
|
238
|
+
|
239
|
+
VALUE Object::GetRealNamedPropertyInPrototypeChain(VALUE self, VALUE key) {
|
240
|
+
return Value(Object(self)->GetRealNamedPropertyInPrototypeChain(String(key)));
|
241
|
+
}
|
242
|
+
|
243
|
+
VALUE Object::GetRealNamedProperty(VALUE self, VALUE key) {
|
244
|
+
return Value(Object(self)->GetRealNamedProperty(String(key)));
|
245
|
+
}
|
246
|
+
|
247
|
+
VALUE Object::HasNamedLookupInterceptor(VALUE self) {
|
248
|
+
return Bool(Object(self)->HasNamedLookupInterceptor());
|
249
|
+
}
|
250
|
+
|
251
|
+
VALUE Object::HasIndexedLookupInterceptor(VALUE self) {
|
252
|
+
return Bool(Object(self)->HasIndexedLookupInterceptor());
|
253
|
+
}
|
254
|
+
|
255
|
+
VALUE Object::TurnOnAccessCheck(VALUE self) {
|
256
|
+
Void(Object(self)->TurnOnAccessCheck());
|
257
|
+
}
|
258
|
+
|
259
|
+
VALUE Object::GetIdentityHash(VALUE self) {
|
260
|
+
return INT2FIX(Object(self)->GetIdentityHash());
|
261
|
+
}
|
262
|
+
|
263
|
+
VALUE Object::SetHiddenValue(VALUE self, VALUE key, VALUE value) {
|
264
|
+
return Bool(Object(self)->SetHiddenValue(String(key), Value(value)));
|
265
|
+
}
|
266
|
+
|
267
|
+
VALUE Object::GetHiddenValue(VALUE self, VALUE key) {
|
268
|
+
return Value(Object(self)->GetHiddenValue(String(key)));
|
269
|
+
}
|
270
|
+
|
271
|
+
VALUE Object::DeleteHiddenValue(VALUE self, VALUE key) {
|
272
|
+
return Bool(Object(self)->DeleteHiddenValue(String(key)));
|
273
|
+
}
|
274
|
+
|
275
|
+
VALUE Object::IsDirty(VALUE self) {
|
276
|
+
return Bool(Object(self)->IsDirty());
|
277
|
+
}
|
278
|
+
|
279
|
+
VALUE Object::Clone(VALUE self) {
|
280
|
+
return Object(Object(self)->Clone());
|
281
|
+
}
|
282
|
+
|
283
|
+
VALUE Object::CreationContext(VALUE self) {
|
284
|
+
return Context(Object(self)->CreationContext());
|
285
|
+
}
|
286
|
+
|
287
|
+
VALUE Object::SetIndexedPropertiesToPixelData(VALUE self, VALUE data, VALUE length) {
|
288
|
+
return not_implemented("SetIndexedPropertiesToPixelData");
|
289
|
+
}
|
290
|
+
|
291
|
+
VALUE Object::GetIndexedPropertiesPixelData(VALUE self) {
|
292
|
+
return not_implemented("GetIndexedPropertiesPixelData");
|
293
|
+
}
|
294
|
+
|
295
|
+
VALUE Object::HasIndexedPropertiesInPixelData(VALUE self) {
|
296
|
+
return Bool(Object(self)->HasIndexedPropertiesInPixelData());
|
297
|
+
}
|
298
|
+
|
299
|
+
VALUE Object::GetIndexedPropertiesPixelDataLength(VALUE self) {
|
300
|
+
return INT2FIX(Object(self)->GetIndexedPropertiesPixelDataLength());
|
301
|
+
}
|
302
|
+
|
303
|
+
VALUE Object::SetIndexedPropertiesToExternalArrayData(VALUE self) {
|
304
|
+
return not_implemented("SetIndexedPropertiesToExternalArrayData");
|
305
|
+
}
|
306
|
+
|
307
|
+
VALUE Object::HasIndexedPropertiesInExternalArrayData(VALUE self) {
|
308
|
+
return Bool(Object(self)->HasIndexedPropertiesInExternalArrayData());
|
309
|
+
}
|
310
|
+
|
311
|
+
VALUE Object::GetIndexedPropertiesExternalArrayData(VALUE self) {
|
312
|
+
return not_implemented("GetIndexedPropertiesExternalArrayData");
|
313
|
+
}
|
314
|
+
|
315
|
+
VALUE Object::GetIndexedPropertiesExternalArrayDataType(VALUE self) {
|
316
|
+
return not_implemented("GetIndexedPropertiesExternalArrayDataType");
|
317
|
+
}
|
318
|
+
|
319
|
+
VALUE Object::GetIndexedPropertiesExternalArrayDataLength(VALUE self) {
|
320
|
+
return INT2FIX(Object(self)->GetIndexedPropertiesExternalArrayDataLength());
|
321
|
+
}
|
322
|
+
|
323
|
+
VALUE Object::IsCallable(VALUE self) {
|
324
|
+
return Bool(Object(self)->IsCallable());
|
325
|
+
}
|
326
|
+
|
327
|
+
VALUE Object::CallAsFunction(VALUE self, VALUE recv, VALUE argv) {
|
328
|
+
return Value(Object(self)->CallAsFunction(Object(recv), RARRAY_LENINT(argv), Value::array<Value>(argv)));
|
329
|
+
}
|
330
|
+
|
331
|
+
VALUE Object::CallAsConstructor(VALUE self, VALUE argv) {
|
332
|
+
return Value(Object(self)->CallAsConstructor(RARRAY_LENINT(argv), Value::array<Value>(argv)));
|
333
|
+
}
|
334
|
+
|
335
|
+
}
|
data/ext/v8/primitive.cc
ADDED
data/ext/v8/rr.cc
ADDED
@@ -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
|
+
}
|