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,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,35 @@
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("total_physical_size", &total_physical_size).
10
+ defineMethod("used_heap_size", &used_heap_size).
11
+ defineMethod("heap_size_limit", &heap_size_limit).
12
+ store(&Class);
13
+ }
14
+ VALUE HeapStatistics::initialize(VALUE self) {
15
+ return HeapStatistics(new v8::HeapStatistics());
16
+ }
17
+ VALUE HeapStatistics::total_heap_size(VALUE self) {
18
+ return SIZET2NUM(HeapStatistics(self)->total_heap_size());
19
+ }
20
+ VALUE HeapStatistics::total_heap_size_executable(VALUE self) {
21
+ return SIZET2NUM(HeapStatistics(self)->total_heap_size_executable());
22
+ }
23
+ VALUE HeapStatistics::total_physical_size(VALUE self) {
24
+ return SIZET2NUM(HeapStatistics(self)->total_physical_size());
25
+ }
26
+ VALUE HeapStatistics::used_heap_size(VALUE self) {
27
+ return SIZET2NUM(HeapStatistics(self)->used_heap_size());
28
+ }
29
+ VALUE HeapStatistics::heap_size_limit(VALUE self) {
30
+ return SIZET2NUM(HeapStatistics(self)->heap_size_limit());
31
+ }
32
+ template <> void Pointer<v8::HeapStatistics>::unwrap(VALUE value) {
33
+ Data_Get_Struct(value, class v8::HeapStatistics, pointer);
34
+ }
35
+ }
@@ -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(v8::Isolate::GetCurrent()));
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,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
+ }