therubyracer-st 0.11.0beta5-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.gitignore +23 -0
  2. data/.travis.yml +10 -0
  3. data/Changelog.md +242 -0
  4. data/Gemfile +15 -0
  5. data/README.md +185 -0
  6. data/Rakefile +58 -0
  7. data/benchmarks.rb +217 -0
  8. data/ext/v8/accessor.cc +181 -0
  9. data/ext/v8/array.cc +26 -0
  10. data/ext/v8/backref.cc +54 -0
  11. data/ext/v8/build.rb +53 -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 +23 -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 +31 -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 +334 -0
  28. data/ext/v8/primitive.cc +8 -0
  29. data/ext/v8/rr.cc +83 -0
  30. data/ext/v8/rr.h +883 -0
  31. data/ext/v8/script.cc +80 -0
  32. data/ext/v8/signature.cc +18 -0
  33. data/ext/v8/stack.cc +75 -0
  34. data/ext/v8/string.cc +47 -0
  35. data/ext/v8/template.cc +175 -0
  36. data/ext/v8/trycatch.cc +86 -0
  37. data/ext/v8/v8.cc +87 -0
  38. data/ext/v8/value.cc +239 -0
  39. data/lib/v8.rb +36 -0
  40. data/lib/v8/access.rb +5 -0
  41. data/lib/v8/access/indices.rb +40 -0
  42. data/lib/v8/access/invocation.rb +47 -0
  43. data/lib/v8/access/names.rb +65 -0
  44. data/lib/v8/array.rb +26 -0
  45. data/lib/v8/context.rb +243 -0
  46. data/lib/v8/conversion.rb +35 -0
  47. data/lib/v8/conversion/array.rb +11 -0
  48. data/lib/v8/conversion/class.rb +120 -0
  49. data/lib/v8/conversion/code.rb +38 -0
  50. data/lib/v8/conversion/fundamental.rb +11 -0
  51. data/lib/v8/conversion/hash.rb +11 -0
  52. data/lib/v8/conversion/indentity.rb +31 -0
  53. data/lib/v8/conversion/method.rb +26 -0
  54. data/lib/v8/conversion/object.rb +28 -0
  55. data/lib/v8/conversion/primitive.rb +7 -0
  56. data/lib/v8/conversion/proc.rb +5 -0
  57. data/lib/v8/conversion/reference.rb +16 -0
  58. data/lib/v8/conversion/string.rb +12 -0
  59. data/lib/v8/conversion/symbol.rb +7 -0
  60. data/lib/v8/conversion/time.rb +13 -0
  61. data/lib/v8/error.rb +25 -0
  62. data/lib/v8/error/protect.rb +20 -0
  63. data/lib/v8/error/try.rb +15 -0
  64. data/lib/v8/function.rb +28 -0
  65. data/lib/v8/helper.rb +30 -0
  66. data/lib/v8/object.rb +79 -0
  67. data/lib/v8/util/weakcell.rb +29 -0
  68. data/lib/v8/version.rb +3 -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 +52 -0
  85. data/spec/v8/context_spec.rb +19 -0
  86. data/spec/v8/conversion_spec.rb +9 -0
  87. data/spec/v8/error_spec.rb +21 -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.gemspec +20 -0
  92. data/vendor/v8.dll +0 -0
  93. metadata +161 -0
@@ -0,0 +1,58 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ void Function::Init() {
5
+ ClassBuilder("Function", Object::Class).
6
+ defineMethod("NewInstance", &NewInstance).
7
+ defineMethod("Call", &Call).
8
+ defineMethod("SetName", &SetName).
9
+ defineMethod("GetName", &GetName).
10
+ defineMethod("GetInferredName", &GetInferredName).
11
+ defineMethod("GetScriptLineNumber", &GetScriptLineNumber).
12
+ defineMethod("GetScriptColumnNumber", &GetScriptColumnNumber).
13
+ defineMethod("GetScriptId", &GetScriptId).
14
+ defineMethod("GetScriptOrigin", &GetScriptOrigin).
15
+ store(&Class);
16
+ }
17
+
18
+ VALUE Function::NewInstance(int argc, VALUE argv[], VALUE self) {
19
+ VALUE args;
20
+ rb_scan_args(argc,argv,"01", &args);
21
+ if (RTEST(args)) {
22
+ return Object(Function(self)->NewInstance(RARRAY_LENINT(args), Value::array<Value>(args)));
23
+ } else {
24
+ return Object(Function(self)->NewInstance());
25
+ }
26
+ }
27
+ VALUE Function::Call(VALUE self, VALUE receiver, VALUE argv) {
28
+ return Value(Function(self)->Call(Object(receiver), RARRAY_LENINT(argv), Value::array<Value>(argv)));
29
+ }
30
+
31
+ VALUE Function::SetName(VALUE self, VALUE name) {
32
+ Void(Function(self)->SetName(String(name)));
33
+ }
34
+
35
+ VALUE Function::GetName(VALUE self) {
36
+ return Value(Function(self)->GetName());
37
+ }
38
+
39
+ VALUE Function::GetInferredName(VALUE self) {
40
+ return Value(Function(self)->GetInferredName());
41
+ }
42
+
43
+ VALUE Function::GetScriptLineNumber(VALUE self) {
44
+ return INT2FIX(Function(self)->GetScriptLineNumber());
45
+ }
46
+
47
+ VALUE Function::GetScriptColumnNumber(VALUE self) {
48
+ return INT2FIX(Function(self)->GetScriptColumnNumber());
49
+ }
50
+
51
+ VALUE Function::GetScriptId(VALUE self) {
52
+ return Value(Function(self)->GetScriptId());
53
+ }
54
+
55
+ VALUE Function::GetScriptOrigin(VALUE self) {
56
+ return not_implemented("GetScriptOrigin");
57
+ }
58
+ }
@@ -0,0 +1,43 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ GC::Queue* queue;
5
+
6
+ GC::Queue::Queue() : first(0), divider(0), last(0){
7
+ first = new GC::Queue::Node(NULL);
8
+ divider = first;
9
+ last = first;
10
+ }
11
+
12
+ void GC::Queue::Enqueue(void* reference) {
13
+ last->next = new Node(reference);
14
+ last = last->next;
15
+ while (first != divider) {
16
+ Node* tmp = first;
17
+ first = first->next;
18
+ delete tmp;
19
+ }
20
+ }
21
+
22
+ void* GC::Queue::Dequeue() {
23
+ void* result = NULL;
24
+ if (divider != last) {
25
+ result = divider->next->value;
26
+ divider = divider->next;
27
+ }
28
+ return result;
29
+ }
30
+
31
+ void GC::Finalize(void* phantom) {
32
+ queue->Enqueue(phantom);
33
+ }
34
+ void GC::Drain(v8::GCType type, v8::GCCallbackFlags flags) {
35
+ for(Phantom phantom = queue->Dequeue(); phantom.NotNull(); phantom = queue->Dequeue()) {
36
+ phantom.destroy();
37
+ }
38
+ }
39
+ void GC::Init() {
40
+ queue = new GC::Queue();
41
+ v8::V8::AddGCPrologueCallback(GC::Drain);
42
+ }
43
+ }
@@ -0,0 +1,34 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ void Handles::Init() {
6
+ VALUE v8 = rb_define_module("V8");
7
+ VALUE c = rb_define_module_under(v8, "C");
8
+ rb_define_singleton_method(c, "HandleScope", (VALUE (*)(...))&HandleScope, -1);
9
+ }
10
+
11
+ VALUE Handles::HandleScope(int argc, VALUE* argv, VALUE self) {
12
+ if (!rb_block_given_p()) {
13
+ return Qnil;
14
+ }
15
+ int state = 0;
16
+ VALUE code;
17
+ rb_scan_args(argc,argv,"00&", &code);
18
+ VALUE result = SetupAndCall(&state, code);
19
+ if (state != 0) {
20
+ rb_jump_tag(state);
21
+ }
22
+ return result;
23
+ }
24
+
25
+ VALUE Handles::SetupAndCall(int* state, VALUE code) {
26
+ v8::HandleScope scope;
27
+ return rb_protect(&DoCall, code, state);
28
+ }
29
+
30
+ VALUE Handles::DoCall(VALUE code) {
31
+ return rb_funcall(code, rb_intern("call"), 0);
32
+ }
33
+
34
+ }
@@ -0,0 +1,31 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ void HeapStatistics::Init() {
5
+ ClassBuilder("HeapStatistics").
6
+ defineSingletonMethod("new", &initialize).
7
+ defineMethod("total_heap_size", &total_heap_size).
8
+ defineMethod("total_heap_size_executable", &total_heap_size_executable).
9
+ defineMethod("used_heap_size", &used_heap_size).
10
+ defineMethod("heap_size_limit", &heap_size_limit).
11
+ store(&Class);
12
+ }
13
+ VALUE HeapStatistics::initialize(VALUE self) {
14
+ return HeapStatistics(new v8::HeapStatistics());
15
+ }
16
+ VALUE HeapStatistics::total_heap_size(VALUE self) {
17
+ return SIZET2NUM(HeapStatistics(self)->total_heap_size());
18
+ }
19
+ VALUE HeapStatistics::total_heap_size_executable(VALUE self) {
20
+ return SIZET2NUM(HeapStatistics(self)->total_heap_size_executable());
21
+ }
22
+ VALUE HeapStatistics::used_heap_size(VALUE self) {
23
+ return SIZET2NUM(HeapStatistics(self)->used_heap_size());
24
+ }
25
+ VALUE HeapStatistics::heap_size_limit(VALUE self) {
26
+ return SIZET2NUM(HeapStatistics(self)->heap_size_limit());
27
+ }
28
+ template <> void Pointer<v8::HeapStatistics>::unwrap(VALUE value) {
29
+ Data_Get_Struct(value, class v8::HeapStatistics, pointer);
30
+ }
31
+ }
@@ -0,0 +1,39 @@
1
+ #include "rr.h"
2
+
3
+ extern "C" {
4
+ void Init_init();
5
+ }
6
+
7
+ using namespace rr;
8
+
9
+ extern "C" {
10
+ void Init_init() {
11
+ v8::Locker lock();
12
+ GC::Init();
13
+ V8::Init();
14
+ Handles::Init();
15
+ Accessor::Init();
16
+ Context::Init();
17
+ Invocation::Init();
18
+ Signature::Init();
19
+ Value::Init();
20
+ Primitive::Init();
21
+ String::Init();
22
+ Object::Init();
23
+ Array::Init();
24
+ Function::Init();
25
+ Date::Init();
26
+ Constants::Init();
27
+ External::Init();
28
+ Script::Init();
29
+ Template::Init();
30
+ Stack::Init();
31
+ Message::Init();
32
+ TryCatch::Init();
33
+ Exception::Init();
34
+ Locker::Init();
35
+ ResourceConstraints::Init();
36
+ HeapStatistics::Init();
37
+ Backref::Init();
38
+ }
39
+ }
@@ -0,0 +1,86 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ VALUE Invocation::Arguments::Class;
6
+
7
+ void Invocation::Init() {
8
+ Arguments::Init();
9
+ }
10
+
11
+ void Invocation::Arguments::Init() {
12
+ ClassBuilder("Arguments").
13
+ defineMethod("Length", &Length).
14
+ defineMethod("[]", &Get).
15
+ defineMethod("Callee", &Callee).
16
+ defineMethod("This", &This).
17
+ defineMethod("Holder", &Holder).
18
+ defineMethod("IsConstructCall", &IsConstructCall).
19
+ defineMethod("Data", &Data).
20
+ store(&Invocation::Arguments::Class);
21
+ }
22
+
23
+ Invocation::Invocation(VALUE code, VALUE data) {
24
+ this->code = code;
25
+ this->data = data;
26
+ }
27
+ Invocation::Invocation(v8::Handle<v8::Value> value) {
28
+ v8::Local<v8::Object> wrapper = value->ToObject();
29
+ this->code = External::unwrap((v8::Handle<v8::External>)v8::External::Cast(*wrapper->Get(0)));
30
+ this->data = Value(wrapper->Get(1));
31
+ }
32
+ Invocation::operator v8::InvocationCallback() {
33
+ return &Callback;
34
+ }
35
+ Invocation::operator v8::Handle<v8::Value>() {
36
+ v8::Local<v8::Object> wrapper = v8::Object::New();
37
+ wrapper->Set(0, External::wrap(this->code));
38
+ wrapper->Set(1, Value(this->data));
39
+ return wrapper;
40
+ }
41
+
42
+ v8::Handle<v8::Value> Invocation::Callback(const v8::Arguments& args) {
43
+ return Arguments(args).Call();
44
+ }
45
+
46
+ Invocation::Arguments::Arguments(const v8::Arguments& args) {
47
+ this->args = &args;
48
+ }
49
+
50
+ Invocation::Arguments::Arguments(VALUE value) {
51
+ Data_Get_Struct(value, class v8::Arguments, args);
52
+ }
53
+
54
+ v8::Handle<v8::Value> Invocation::Arguments::Call() {
55
+ Invocation invocation(args->Data());
56
+ return Value(rb_funcall(invocation.code, rb_intern("call"), 1, Data_Wrap_Struct(Class, 0, 0, (void*)this->args)));
57
+ }
58
+
59
+ VALUE Invocation::Arguments::Length(VALUE self) {
60
+ return INT2FIX(Arguments(self)->Length());
61
+ }
62
+
63
+ VALUE Invocation::Arguments::Get(VALUE self, VALUE index) {
64
+ return Value((*Arguments(self))[NUM2INT(index)]);
65
+ }
66
+
67
+ VALUE Invocation::Arguments::Callee(VALUE self) {
68
+ return Function(Arguments(self)->Callee());
69
+ }
70
+
71
+ VALUE Invocation::Arguments::This(VALUE self) {
72
+ return Object(Arguments(self)->This());
73
+ }
74
+
75
+ VALUE Invocation::Arguments::Holder(VALUE self) {
76
+ return Object(Arguments(self)->Holder());
77
+ }
78
+
79
+ VALUE Invocation::Arguments::IsConstructCall(VALUE self) {
80
+ return Bool(Arguments(self)->IsConstructCall());
81
+ }
82
+
83
+ VALUE Invocation::Arguments::Data(VALUE self) {
84
+ return Invocation(Arguments(self)->Data()).data;
85
+ }
86
+ }
@@ -0,0 +1,77 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ void Locker::Init() {
5
+ ClassBuilder("Locker").
6
+ defineSingletonMethod("StartPreemption", &StartPreemption).
7
+ defineSingletonMethod("StopPreemption", &StopPreemption).
8
+ defineSingletonMethod("IsLocked", &IsLocked).
9
+ defineSingletonMethod("IsActive", &IsActive);
10
+ VALUE v8 = rb_define_module("V8");
11
+ VALUE c = rb_define_module_under(v8, "C");
12
+ rb_define_singleton_method(c, "Locker", (VALUE (*)(...))&doLock, -1);
13
+ rb_define_singleton_method(c, "Unlocker",(VALUE (*)(...))&doUnlock, -1);
14
+ }
15
+
16
+ VALUE Locker::StartPreemption(VALUE self, VALUE every_n_ms) {
17
+ Void(v8::Locker::StartPreemption(NUM2INT(every_n_ms)));
18
+ }
19
+
20
+ VALUE Locker::StopPreemption(VALUE self) {
21
+ Void(v8::Locker::StopPreemption());
22
+ }
23
+
24
+ VALUE Locker::IsLocked(VALUE self) {
25
+ return Bool(v8::Locker::IsLocked());
26
+ }
27
+
28
+ VALUE Locker::IsActive(VALUE self) {
29
+ return Bool(v8::Locker::IsActive());
30
+ }
31
+
32
+ VALUE Locker::doLock(int argc, VALUE* argv, VALUE self) {
33
+ if (!rb_block_given_p()) {
34
+ return Qnil;
35
+ }
36
+ int state = 0;
37
+ VALUE code;
38
+ rb_scan_args(argc,argv,"00&", &code);
39
+ VALUE result = setupLockAndCall(&state, code);
40
+ if (state != 0) {
41
+ rb_jump_tag(state);
42
+ }
43
+ return result;
44
+ }
45
+
46
+ VALUE Locker::setupLockAndCall(int* state, VALUE code) {
47
+ v8::Locker locker;
48
+ return rb_protect(&doLockCall, code, state);
49
+ }
50
+
51
+ VALUE Locker::doLockCall(VALUE code) {
52
+ return rb_funcall(code, rb_intern("call"), 0);
53
+ }
54
+
55
+ VALUE Locker::doUnlock(int argc, VALUE* argv, VALUE self) {
56
+ if (!rb_block_given_p()) {
57
+ return Qnil;
58
+ }
59
+ int state = 0;
60
+ VALUE code;
61
+ rb_scan_args(argc,argv,"00&", &code);
62
+ VALUE result = setupUnlockAndCall(&state, code);
63
+ if (state != 0) {
64
+ rb_jump_tag(state);
65
+ }
66
+ return result;
67
+ }
68
+
69
+ VALUE Locker::setupUnlockAndCall(int* state, VALUE code) {
70
+ v8::Unlocker unlocker;
71
+ return rb_protect(&doUnlockCall, code, state);
72
+ }
73
+
74
+ VALUE Locker::doUnlockCall(VALUE code) {
75
+ return rb_funcall(code, rb_intern("call"), 0);
76
+ }
77
+ }
@@ -0,0 +1,51 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ void Message::Init() {
6
+ ClassBuilder("Message").
7
+ defineMethod("Get", &Get).
8
+ defineMethod("GetSourceLine", &GetSourceLine).
9
+ defineMethod("GetScriptResourceName", &GetScriptResourceName).
10
+ defineMethod("GetScriptData", &GetScriptData).
11
+ defineMethod("GetStackTrace", &GetStackTrace).
12
+ defineMethod("GetLineNumber", &GetLineNumber).
13
+ defineMethod("GetStartPosition", &GetStartPosition).
14
+ defineMethod("GetEndPosition", &GetEndPosition).
15
+ defineMethod("GetStartColumn", &GetEndColumn).
16
+ defineSingletonMethod("kNoLineNumberInfo", &kNoLineNumberInfo).
17
+ defineSingletonMethod("kNoColumnInfo", &kNoColumnInfo).
18
+ store(&Class);
19
+ }
20
+
21
+ VALUE Message::Get(VALUE self) {
22
+ return String(Message(self)->Get());
23
+ }
24
+ VALUE Message::GetSourceLine(VALUE self) {
25
+ return String(Message(self)->GetSourceLine());
26
+ }
27
+ VALUE Message::GetScriptResourceName(VALUE self) {
28
+ return Value(Message(self)->GetScriptResourceName());
29
+ }
30
+ VALUE Message::GetScriptData(VALUE self) {
31
+ return Value(Message(self)->GetScriptData());
32
+ }
33
+ VALUE Message::GetStackTrace(VALUE self) {
34
+ return Stack::Trace(Message(self)->GetStackTrace());
35
+ }
36
+ VALUE Message::GetLineNumber(VALUE self) {
37
+ return INT2FIX(Message(self)->GetLineNumber());
38
+ }
39
+ VALUE Message::GetStartPosition(VALUE self) {
40
+ return INT2FIX(Message(self)->GetStartPosition());
41
+ }
42
+ VALUE Message::GetEndPosition(VALUE self) {
43
+ return INT2FIX(Message(self)->GetEndPosition());
44
+ }
45
+ VALUE Message::GetStartColumn(VALUE self) {
46
+ return INT2FIX(Message(self)->GetStartColumn());
47
+ }
48
+ VALUE Message::GetEndColumn(VALUE self) {
49
+ return INT2FIX(Message(self)->GetEndColumn());
50
+ }
51
+ }
@@ -0,0 +1,334 @@
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 accessor(get, set, data);
124
+ return Bool(Object(self)->SetAccessor(
125
+ String(name),
126
+ accessor.accessorGetter(),
127
+ accessor.accessorSetter(),
128
+ accessor,
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
+ backref = (Backref*)v8::External::Unwrap(external);
148
+ value = backref->get();
149
+ if (!RTEST(value)) {
150
+ value = downcast();
151
+ backref->set(value);
152
+ }
153
+ }
154
+ return value;
155
+ }
156
+
157
+ VALUE Object::downcast() {
158
+ if (handle->IsFunction()) {
159
+ return Function((v8::Handle<v8::Function>) v8::Function::Cast(*handle));
160
+ }
161
+ if (handle->IsArray()) {
162
+ return Array((v8::Handle<v8::Array>)v8::Array::Cast(*handle));
163
+ }
164
+ if (handle->IsDate()) {
165
+ // return Date(handle);
166
+ }
167
+ if (handle->IsBooleanObject()) {
168
+ // return BooleanObject(handle);
169
+ }
170
+ if (handle->IsNumberObject()) {
171
+ // return NumberObject(handle);
172
+ }
173
+ if (handle->IsStringObject()) {
174
+ // return StringObject(handle);
175
+ }
176
+ if (handle->IsRegExp()) {
177
+ // return RegExp(handle);
178
+ }
179
+ return Ref<v8::Object>::operator VALUE();
180
+ }
181
+
182
+ VALUE Object::GetPropertyNames(VALUE self) {
183
+ return Array(Object(self)->GetPropertyNames());
184
+ }
185
+
186
+ VALUE Object::GetOwnPropertyNames(VALUE self) {
187
+ return Array(Object(self)->GetOwnPropertyNames());
188
+ }
189
+
190
+ VALUE Object::GetPrototype(VALUE self) {
191
+ return Value(Object(self)->GetPrototype());
192
+ }
193
+
194
+ VALUE Object::SetPrototype(VALUE self, VALUE prototype) {
195
+ return Bool(Object(self)->SetPrototype(Value(prototype)));
196
+ }
197
+
198
+ VALUE Object::FindInstanceInPrototypeChain(VALUE self, VALUE impl) {
199
+ return Object(Object(self)->FindInstanceInPrototypeChain(FunctionTemplate(impl)));
200
+ }
201
+
202
+ VALUE Object::ObjectProtoToString(VALUE self) {
203
+ return String(Object(self)->ObjectProtoToString());
204
+ }
205
+
206
+ VALUE Object::GetConstructorName(VALUE self) {
207
+ return String(Object(self)->GetConstructorName());
208
+ }
209
+
210
+ VALUE Object::InternalFieldCount(VALUE self) {
211
+ return INT2FIX(Object(self)->InternalFieldCount());
212
+ }
213
+
214
+ VALUE Object::GetInternalField(VALUE self, VALUE idx) {
215
+ return Value(Object(self)->GetInternalField(NUM2INT(idx)));
216
+ }
217
+
218
+ VALUE Object::SetInternalField(VALUE self, VALUE idx, VALUE value) {
219
+ Void(Object(self)->SetInternalField(NUM2INT(idx), Value(value)));
220
+ }
221
+
222
+ VALUE Object::HasOwnProperty(VALUE self, VALUE key) {
223
+ return Bool(Object(self)->HasOwnProperty(String(key)));
224
+ }
225
+
226
+ VALUE Object::HasRealNamedProperty(VALUE self, VALUE key) {
227
+ return Bool(Object(self)->HasRealNamedProperty(String(key)));
228
+ }
229
+
230
+ VALUE Object::HasRealIndexedProperty(VALUE self, VALUE idx) {
231
+ return Bool(Object(self)->HasRealIndexedProperty(UInt32(idx)));
232
+ }
233
+
234
+ VALUE Object::HasRealNamedCallbackProperty(VALUE self, VALUE key) {
235
+ return Bool(Object(self)->HasRealNamedCallbackProperty(String(key)));
236
+ }
237
+
238
+ VALUE Object::GetRealNamedPropertyInPrototypeChain(VALUE self, VALUE key) {
239
+ return Value(Object(self)->GetRealNamedPropertyInPrototypeChain(String(key)));
240
+ }
241
+
242
+ VALUE Object::GetRealNamedProperty(VALUE self, VALUE key) {
243
+ return Value(Object(self)->GetRealNamedProperty(String(key)));
244
+ }
245
+
246
+ VALUE Object::HasNamedLookupInterceptor(VALUE self) {
247
+ return Bool(Object(self)->HasNamedLookupInterceptor());
248
+ }
249
+
250
+ VALUE Object::HasIndexedLookupInterceptor(VALUE self) {
251
+ return Bool(Object(self)->HasIndexedLookupInterceptor());
252
+ }
253
+
254
+ VALUE Object::TurnOnAccessCheck(VALUE self) {
255
+ Void(Object(self)->TurnOnAccessCheck());
256
+ }
257
+
258
+ VALUE Object::GetIdentityHash(VALUE self) {
259
+ return INT2FIX(Object(self)->GetIdentityHash());
260
+ }
261
+
262
+ VALUE Object::SetHiddenValue(VALUE self, VALUE key, VALUE value) {
263
+ return Bool(Object(self)->SetHiddenValue(String(key), Value(value)));
264
+ }
265
+
266
+ VALUE Object::GetHiddenValue(VALUE self, VALUE key) {
267
+ return Value(Object(self)->GetHiddenValue(String(key)));
268
+ }
269
+
270
+ VALUE Object::DeleteHiddenValue(VALUE self, VALUE key) {
271
+ return Bool(Object(self)->DeleteHiddenValue(String(key)));
272
+ }
273
+
274
+ VALUE Object::IsDirty(VALUE self) {
275
+ return Bool(Object(self)->IsDirty());
276
+ }
277
+
278
+ VALUE Object::Clone(VALUE self) {
279
+ return Object(Object(self)->Clone());
280
+ }
281
+
282
+ VALUE Object::CreationContext(VALUE self) {
283
+ return Context(Object(self)->CreationContext());
284
+ }
285
+
286
+ VALUE Object::SetIndexedPropertiesToPixelData(VALUE self, VALUE data, VALUE length) {
287
+ return not_implemented("SetIndexedPropertiesToPixelData");
288
+ }
289
+
290
+ VALUE Object::GetIndexedPropertiesPixelData(VALUE self) {
291
+ return not_implemented("GetIndexedPropertiesPixelData");
292
+ }
293
+
294
+ VALUE Object::HasIndexedPropertiesInPixelData(VALUE self) {
295
+ return Bool(Object(self)->HasIndexedPropertiesInPixelData());
296
+ }
297
+
298
+ VALUE Object::GetIndexedPropertiesPixelDataLength(VALUE self) {
299
+ return INT2FIX(Object(self)->GetIndexedPropertiesPixelDataLength());
300
+ }
301
+
302
+ VALUE Object::SetIndexedPropertiesToExternalArrayData(VALUE self) {
303
+ return not_implemented("SetIndexedPropertiesToExternalArrayData");
304
+ }
305
+
306
+ VALUE Object::HasIndexedPropertiesInExternalArrayData(VALUE self) {
307
+ return Bool(Object(self)->HasIndexedPropertiesInExternalArrayData());
308
+ }
309
+
310
+ VALUE Object::GetIndexedPropertiesExternalArrayData(VALUE self) {
311
+ return not_implemented("GetIndexedPropertiesExternalArrayData");
312
+ }
313
+
314
+ VALUE Object::GetIndexedPropertiesExternalArrayDataType(VALUE self) {
315
+ return not_implemented("GetIndexedPropertiesExternalArrayDataType");
316
+ }
317
+
318
+ VALUE Object::GetIndexedPropertiesExternalArrayDataLength(VALUE self) {
319
+ return INT2FIX(Object(self)->GetIndexedPropertiesExternalArrayDataLength());
320
+ }
321
+
322
+ VALUE Object::IsCallable(VALUE self) {
323
+ return Bool(Object(self)->IsCallable());
324
+ }
325
+
326
+ VALUE Object::CallAsFunction(VALUE self, VALUE recv, VALUE argv) {
327
+ return Value(Object(self)->CallAsFunction(Object(recv), RARRAY_LENINT(argv), Value::array<Value>(argv)));
328
+ }
329
+
330
+ VALUE Object::CallAsConstructor(VALUE self, VALUE argv) {
331
+ return Value(Object(self)->CallAsConstructor(RARRAY_LENINT(argv), Value::array<Value>(argv)));
332
+ }
333
+
334
+ }