therubyracer 0.10.2 → 0.11.0beta1

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

Potentially problematic release.


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

Files changed (159) hide show
  1. data/.gitignore +21 -11
  2. data/.travis.yml +2 -1
  3. data/Changelog.md +46 -0
  4. data/Gemfile +16 -1
  5. data/README.md +31 -13
  6. data/Rakefile +42 -23
  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 +56 -0
  11. data/ext/v8/build.rb +51 -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 +14 -18
  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 +878 -36
  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 +30 -22
  40. data/lib/v8/access.rb +5 -87
  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 +19 -10
  45. data/lib/v8/context.rb +85 -78
  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 +18 -123
  62. data/lib/v8/error/protect.rb +20 -0
  63. data/lib/v8/error/try.rb +15 -0
  64. data/lib/v8/function.rb +18 -34
  65. data/lib/v8/object.rb +48 -52
  66. data/lib/v8/util/weakcell.rb +29 -0
  67. data/lib/v8/version.rb +2 -2
  68. data/spec/c/array_spec.rb +17 -0
  69. data/spec/c/constants_spec.rb +20 -0
  70. data/spec/c/exception_spec.rb +26 -0
  71. data/spec/c/external_spec.rb +9 -0
  72. data/spec/c/function_spec.rb +46 -0
  73. data/spec/c/handles_spec.rb +35 -0
  74. data/spec/c/locker_spec.rb +38 -0
  75. data/spec/c/object_spec.rb +46 -0
  76. data/spec/c/script_spec.rb +28 -0
  77. data/spec/c/string_spec.rb +16 -0
  78. data/spec/c/template_spec.rb +30 -0
  79. data/spec/c/trycatch_spec.rb +51 -0
  80. data/spec/mem/blunt_spec.rb +42 -0
  81. data/spec/redjs_spec.rb +10 -0
  82. data/spec/spec_helper.rb +40 -4
  83. data/spec/threading_spec.rb +52 -0
  84. data/spec/v8/context_spec.rb +19 -0
  85. data/spec/v8/conversion_spec.rb +9 -0
  86. data/spec/v8/error_spec.rb +15 -125
  87. data/spec/v8/function_spec.rb +9 -0
  88. data/therubyracer.gemspec +15 -24
  89. metadata +102 -135
  90. data/.gitmodules +0 -3
  91. data/.rspec +0 -1
  92. data/.yardopts +0 -1
  93. data/bin/therubyracer +0 -11
  94. data/ext/v8/rr.cpp +0 -189
  95. data/ext/v8/v8.cpp +0 -48
  96. data/ext/v8/v8_array.cpp +0 -48
  97. data/ext/v8/v8_array.h +0 -8
  98. data/ext/v8/v8_callbacks.cpp +0 -81
  99. data/ext/v8/v8_callbacks.h +0 -8
  100. data/ext/v8/v8_context.cpp +0 -92
  101. data/ext/v8/v8_context.h +0 -6
  102. data/ext/v8/v8_date.cpp +0 -34
  103. data/ext/v8/v8_date.h +0 -6
  104. data/ext/v8/v8_debug.cpp +0 -17
  105. data/ext/v8/v8_debug.h +0 -6
  106. data/ext/v8/v8_exception.cpp +0 -133
  107. data/ext/v8/v8_exception.h +0 -11
  108. data/ext/v8/v8_external.cpp +0 -70
  109. data/ext/v8/v8_external.h +0 -8
  110. data/ext/v8/v8_function.cpp +0 -69
  111. data/ext/v8/v8_function.h +0 -11
  112. data/ext/v8/v8_handle.cpp +0 -186
  113. data/ext/v8/v8_handle.h +0 -48
  114. data/ext/v8/v8_locker.cpp +0 -139
  115. data/ext/v8/v8_locker.h +0 -6
  116. data/ext/v8/v8_message.cpp +0 -67
  117. data/ext/v8/v8_message.h +0 -10
  118. data/ext/v8/v8_object.cpp +0 -122
  119. data/ext/v8/v8_object.h +0 -10
  120. data/ext/v8/v8_script.cpp +0 -36
  121. data/ext/v8/v8_script.h +0 -8
  122. data/ext/v8/v8_string.cpp +0 -52
  123. data/ext/v8/v8_string.h +0 -9
  124. data/ext/v8/v8_template.cpp +0 -344
  125. data/ext/v8/v8_template.h +0 -8
  126. data/ext/v8/v8_try_catch.cpp +0 -70
  127. data/ext/v8/v8_try_catch.h +0 -5
  128. data/ext/v8/v8_v8.cpp +0 -35
  129. data/ext/v8/v8_v8.h +0 -6
  130. data/ext/v8/v8_value.cpp +0 -175
  131. data/ext/v8/v8_value.h +0 -10
  132. data/ext/v8/v8_weakref.cpp +0 -61
  133. data/ext/v8/v8_weakref.h +0 -29
  134. data/lib/v8/c/locker.rb +0 -18
  135. data/lib/v8/cli.rb +0 -133
  136. data/lib/v8/portal.rb +0 -86
  137. data/lib/v8/portal/caller.rb +0 -37
  138. data/lib/v8/portal/constructor.rb +0 -98
  139. data/lib/v8/portal/function.rb +0 -63
  140. data/lib/v8/portal/interceptors.rb +0 -152
  141. data/lib/v8/portal/proxies.rb +0 -151
  142. data/lib/v8/portal/templates.rb +0 -73
  143. data/lib/v8/stack.rb +0 -66
  144. data/lib/v8/tap.rb +0 -9
  145. data/spec/ext/array_spec.rb +0 -15
  146. data/spec/ext/cxt_spec.rb +0 -57
  147. data/spec/ext/ext_spec_helper.rb +0 -27
  148. data/spec/ext/func_spec.rb +0 -64
  149. data/spec/ext/object_spec.rb +0 -10
  150. data/spec/ext/string_spec.rb +0 -11
  151. data/spec/ext/try_catch_spec.rb +0 -60
  152. data/spec/redjs_helper.rb +0 -3
  153. data/spec/v8/portal/proxies_spec.rb +0 -106
  154. data/specmem/handle_memspec.rb +0 -41
  155. data/specmem/object_memspec.rb +0 -14
  156. data/specmem/proxies_memspec.rb +0 -49
  157. data/specmem/spec_helper.rb +0 -24
  158. data/specthread/spec_helper.rb +0 -2
  159. data/specthread/threading_spec.rb +0 -13
data/ext/v8/v8_template.h DELETED
@@ -1,8 +0,0 @@
1
- #ifndef _RUBY_V8_TEMPLATE_
2
- #define _RUBY_V8_TEMPLATE_
3
-
4
- #include "rr.h"
5
-
6
- void rr_init_template();
7
-
8
- #endif
@@ -1,70 +0,0 @@
1
- #include "rr.h"
2
- #include "v8_try_catch.h"
3
- #include "v8_message.h"
4
-
5
- using namespace v8;
6
-
7
- namespace {
8
- VALUE TryCatchClass;
9
-
10
- TryCatch *unwrap(VALUE self) {
11
- TryCatch *tc = 0;
12
- Data_Get_Struct(self, class TryCatch, tc);
13
- if (RTEST(rb_iv_get(self, "dead"))) {
14
- rb_raise(rb_eScriptError, "out of scope access of %s", RSTRING_PTR(rb_inspect(self)));
15
- return false;
16
- } else {
17
- return tc;
18
- }
19
- }
20
-
21
- VALUE Try(int argc, VALUE *argv, VALUE self) {
22
- if (rb_block_given_p()) {
23
- HandleScope scope;
24
- TryCatch tc;
25
- VALUE try_catch = Data_Wrap_Struct(TryCatchClass, 0, 0, &tc);
26
- rb_iv_set(try_catch, "dead", Qfalse);
27
- VALUE result = rb_yield(try_catch);
28
- rb_iv_set(try_catch, "dead", Qtrue);
29
- tc.Reset();
30
- return result;
31
- } else {
32
- return Qnil;
33
- }
34
- }
35
-
36
- VALUE HasCaught(VALUE self) {
37
- TryCatch *tc = unwrap(self);
38
- return tc ? rr_v82rb(tc->HasCaught()) : Qnil;
39
- }
40
-
41
- VALUE _Exception(VALUE self) {
42
- TryCatch *tc = unwrap(self);
43
- return tc ? rr_v82rb(tc->Exception()) : Qnil;
44
- }
45
-
46
- VALUE _StackTrace(VALUE self) {
47
- TryCatch *tc = unwrap(self);
48
- return tc ? rr_v82rb(tc->StackTrace()) : Qnil;
49
- }
50
-
51
- VALUE _Message(VALUE self) {
52
- TryCatch *tc = unwrap(self);
53
- return tc ? rr_v82rb(tc->Message()) : Qnil;
54
- }
55
-
56
- VALUE CanContinue(VALUE self) {
57
- TryCatch *tc = unwrap(self);
58
- return tc ? rr_v82rb(tc->CanContinue()) : Qnil;
59
- }
60
- }
61
-
62
- void rr_init_v8_try_catch() {
63
- TryCatchClass = rr_define_class("TryCatch");
64
- rr_define_singleton_method(TryCatchClass, "try", Try, -1);
65
- rr_define_method(TryCatchClass, "HasCaught", HasCaught, 0);
66
- rr_define_method(TryCatchClass, "Exception", _Exception, 0);
67
- rr_define_method(TryCatchClass, "StackTrace", _StackTrace, 0);
68
- rr_define_method(TryCatchClass, "Message", _Message, 0);
69
- rr_define_method(TryCatchClass, "CanContinue", CanContinue, 0);
70
- }
@@ -1,5 +0,0 @@
1
- #ifndef _RR_V8_TRY_CATCH_
2
- #define _RR_V8_TRY_CATCH_
3
-
4
- void rr_init_v8_try_catch();
5
- #endif
data/ext/v8/v8_v8.cpp DELETED
@@ -1,35 +0,0 @@
1
-
2
- #include "rr.h"
3
-
4
- using namespace v8;
5
-
6
- namespace {
7
-
8
- VALUE IsDead(VALUE self) {
9
- return rr_v82rb(V8::IsDead());
10
- }
11
-
12
- VALUE AdjustAmountOfExternalAllocatedMemory(VALUE self, VALUE bytes) {
13
- V8::AdjustAmountOfExternalAllocatedMemory(NUM2INT(bytes));
14
- return Qnil;
15
- }
16
-
17
- VALUE IdleNotification(VALUE self) {
18
- return rr_v82rb(V8::IdleNotification());
19
- }
20
-
21
- VALUE SetFlagsFromString(VALUE self, VALUE string) {
22
- V8::SetFlagsFromString(RSTRING_PTR(string), RSTRING_LEN(string));
23
- return Qnil;
24
- }
25
-
26
- }
27
-
28
-
29
- void rr_init_v8_v8() {
30
- VALUE V8Module = rr_define_module("V8");
31
- rr_define_singleton_method(V8Module, "IsDead", IsDead, 0);
32
- rr_define_singleton_method(V8Module, "AdjustAmountOfExternalAllocatedMemory", AdjustAmountOfExternalAllocatedMemory, 1);
33
- rr_define_singleton_method(V8Module, "IdleNotification", IdleNotification, 0);
34
- rr_define_singleton_method(V8Module, "SetFlagsFromString", SetFlagsFromString, 1);
35
- }
data/ext/v8/v8_v8.h DELETED
@@ -1,6 +0,0 @@
1
- #ifndef _RR_V8_V8_
2
- #define _RR_V8_V8_
3
-
4
- void rr_init_v8_v8();
5
-
6
- #endif
data/ext/v8/v8_value.cpp DELETED
@@ -1,175 +0,0 @@
1
- #include "v8_handle.h"
2
- #include "v8_value.h"
3
-
4
- using namespace v8;
5
- namespace {
6
-
7
- VALUE ValueClass;
8
-
9
- Persistent<Value>& unwrap(VALUE value) {
10
- return rr_v8_handle<Value>(value);
11
- }
12
- VALUE IsEmpty(VALUE value) {
13
- return value == rr_v8_value_empty() ? Qtrue : Qfalse;
14
- }
15
- VALUE IsUndefined(VALUE self) {
16
- HandleScope scope;
17
- return rr_v82rb(unwrap(self)->IsUndefined());
18
- }
19
- VALUE IsNull(VALUE self) {
20
- HandleScope scope;
21
- return rr_v82rb(unwrap(self)->IsNull());
22
- }
23
- VALUE IsTrue(VALUE self) {
24
- HandleScope scope;
25
- return rr_v82rb(unwrap(self)->IsTrue());
26
- }
27
- VALUE IsFalse(VALUE self) {
28
- HandleScope scope;
29
- return rr_v82rb(unwrap(self)->IsFalse());
30
- }
31
- VALUE IsString(VALUE self) {
32
- HandleScope scope;
33
- return rr_v82rb(unwrap(self)->IsString());
34
- }
35
- VALUE IsFunction(VALUE self) {
36
- HandleScope scope;
37
- return rr_v82rb(unwrap(self)->IsFunction());
38
- }
39
- VALUE IsArray(VALUE self) {
40
- HandleScope scope;
41
- return rr_v82rb(unwrap(self)->IsArray());
42
- }
43
- VALUE IsObject(VALUE self) {
44
- HandleScope scope;
45
- return rr_v82rb(unwrap(self)->IsObject());
46
- }
47
- VALUE IsBoolean(VALUE self) {
48
- HandleScope scope;
49
- return rr_v82rb(unwrap(self)->IsBoolean());
50
- }
51
- VALUE IsNumber(VALUE self) {
52
- HandleScope scope;
53
- return rr_v82rb(unwrap(self)->IsNumber());
54
- }
55
- VALUE IsExternal(VALUE self) {
56
- HandleScope scope;
57
- return rr_v82rb(unwrap(self)->IsExternal());
58
- }
59
- VALUE IsInt32(VALUE self) {
60
- HandleScope scope;
61
- return rr_v82rb(unwrap(self)->IsInt32());
62
- }
63
- VALUE IsUint32(VALUE self) {
64
- HandleScope scope;
65
- return rr_v82rb(unwrap(self)->IsUint32());
66
- }
67
- VALUE IsDate(VALUE self) {
68
- HandleScope scope;
69
- return rr_v82rb(unwrap(self)->IsDate());
70
- }
71
-
72
- VALUE ToBoolean(VALUE self) {
73
- HandleScope scope;
74
- return rr_v82rb(unwrap(self)->ToBoolean());
75
- }
76
- VALUE ToNumber(VALUE self) {
77
- HandleScope scope;
78
- return rr_v82rb(unwrap(self)->ToNumber());
79
- }
80
- VALUE ToString(VALUE self) {
81
- HandleScope scope;
82
- return rr_v82rb(unwrap(self)->ToString());
83
- }
84
- VALUE ToDetailString(VALUE self) {
85
- HandleScope scope;
86
- return rr_v82rb(unwrap(self)->ToDetailString());
87
- }
88
- VALUE ToObject(VALUE self) {
89
- HandleScope scope;
90
- return rr_v82rb(unwrap(self)->ToObject());
91
- }
92
- VALUE ToInteger(VALUE self) {
93
- HandleScope scope;
94
- return rr_v82rb(unwrap(self)->ToInteger());
95
- }
96
- VALUE ToUint32(VALUE self) {
97
- HandleScope scope;
98
- return rr_v82rb(unwrap(self)->ToUint32());
99
- }
100
- VALUE ToInt32(VALUE self) {
101
- HandleScope scope;
102
- return rr_v82rb(unwrap(self)->ToInt32());
103
- }
104
- VALUE ToArrayIndex(VALUE self) {
105
- HandleScope scope;
106
- return rr_v82rb(unwrap(self)->ToArrayIndex());
107
- }
108
-
109
- VALUE Equals(VALUE self, VALUE that) {
110
- HandleScope scope;
111
- return rr_v82rb(unwrap(self)->Equals(unwrap(that)));
112
- }
113
- VALUE StrictEquals(VALUE self, VALUE that) {
114
- HandleScope scope;
115
- return rr_v82rb(unwrap(self)->StrictEquals(unwrap(that)));
116
- }
117
-
118
- VALUE BooleanValue(VALUE self) {
119
- HandleScope scope;
120
- return rr_v82rb(unwrap(self)->BooleanValue());
121
- }
122
-
123
- VALUE NumberValue(VALUE self) {
124
- HandleScope scope;
125
- return rr_v82rb(unwrap(self)->NumberValue());
126
- }
127
- }
128
-
129
- VALUE rr_v8_value_class() {
130
- return ValueClass;
131
- }
132
-
133
- VALUE rr_v8_value_empty() {
134
- return rr_const_get("Empty");
135
- }
136
-
137
- void rr_init_value() {
138
- ValueClass = rr_define_class("Value", rr_v8_handle_class());
139
- rr_define_const("Empty", rr_v8_handle_new(ValueClass, Handle<Value>()));
140
-
141
- rr_define_method(ValueClass, "IsEmpty", IsEmpty, 0);
142
- rr_define_method(ValueClass, "IsUndefined", IsUndefined, 0);
143
- rr_define_method(ValueClass, "IsNull", IsNull, 0);
144
- rr_define_method(ValueClass, "IsTrue", IsTrue, 0);
145
- rr_define_method(ValueClass, "IsFalse", IsFalse, 0);
146
- rr_define_method(ValueClass, "IsString", IsString, 0);
147
- rr_define_method(ValueClass, "IsFunction", IsFunction, 0);
148
- rr_define_method(ValueClass, "IsArray", IsArray, 0);
149
- rr_define_method(ValueClass, "IsObject", IsObject, 0);
150
- rr_define_method(ValueClass, "IsBoolean", IsBoolean, 0);
151
- rr_define_method(ValueClass, "IsNumber", IsNumber, 0);
152
- rr_define_method(ValueClass, "IsExternal", IsExternal, 0);
153
- rr_define_method(ValueClass, "IsInt32", IsInt32, 0);
154
- rr_define_method(ValueClass, "IsUint32", IsUint32, 0);
155
- rr_define_method(ValueClass, "IsDate", IsDate, 0);
156
-
157
- rr_define_method(ValueClass, "ToBoolean", ToBoolean, 0);
158
- rr_define_method(ValueClass, "ToNumber", ToNumber, 0);
159
- rr_define_method(ValueClass, "ToString", ToString, 0);
160
- rr_define_method(ValueClass, "ToDetailString", ToDetailString, 0);
161
- rr_define_method(ValueClass, "ToObject", ToObject, 0);
162
- rr_define_method(ValueClass, "ToInteger", ToInteger, 0);
163
- rr_define_method(ValueClass, "ToUint32", ToUint32, 0);
164
- rr_define_method(ValueClass, "ToArrayIndex", ToArrayIndex, 0);
165
-
166
- rr_define_method(ValueClass, "Equals", Equals, 1);
167
- rr_define_method(ValueClass, "StrictEquals", StrictEquals, 1);
168
-
169
- rr_define_method(ValueClass, "BooleanValue", BooleanValue, 0);
170
- rr_define_method(ValueClass, "NumberValue", NumberValue, 0);
171
- }
172
-
173
- VALUE rr_wrap_v8_value(Handle<Value>& value) {
174
- return rr_v8_handle_new(ValueClass, value);
175
- }
data/ext/v8/v8_value.h DELETED
@@ -1,10 +0,0 @@
1
- #ifndef _RR_V8_VALUE_
2
- #define _RR_V8_VALUE_
3
-
4
- #include "rr.h"
5
-
6
- void rr_init_value();
7
- VALUE rr_wrap_v8_value(v8::Handle<v8::Value>& value);
8
- VALUE rr_v8_value_class();
9
- VALUE rr_v8_value_empty();
10
- #endif
@@ -1,61 +0,0 @@
1
- #include "v8.h"
2
- #include "v8_weakref.h"
3
-
4
- using namespace v8;
5
-
6
- v8_weakref::v8_weakref(VALUE object) {
7
- this->v8_active = true;
8
- this->rb_active = true;
9
- this->external = Persistent<External>::New(External::New((void *)this));
10
- this->external.MakeWeak(this, v8_weakref_dispose);
11
- this->set(object);
12
- }
13
-
14
- void v8_weakref::set(VALUE value) {
15
- this->object_id = rb_obj_id(value);
16
- this->rb_active = true;
17
- VALUE data = Data_Wrap_Struct(rb_cObject, 0, 0, this);
18
- rr_define_finalizer(value,(void*)v8_weakref_finalize, data);
19
- }
20
-
21
- VALUE v8_weakref::get() {
22
- if (this->object_id) {
23
- return rb_rescue((VALUE (*)(...))v8_weakref_id2ref, this->object_id, (VALUE (*)(...))v8_weakref_nil, Qnil);
24
- } else {
25
- return Qnil;
26
- }
27
- }
28
-
29
- VALUE v8_weakref_finalize(VALUE object_id, VALUE data) {
30
- v8_weakref* weakref = 0;
31
- Data_Get_Struct(data, struct v8_weakref, weakref);
32
- weakref->object_id = Qnil;
33
- weakref->rb_active = false;
34
- if (!weakref->v8_active) {
35
- delete weakref;
36
- }
37
- return Qnil;
38
- }
39
-
40
- void v8_weakref_dispose(Persistent<Value> value, void* data) {
41
- value.Dispose();
42
- value.Clear();
43
- v8_weakref* weakref = (v8_weakref*)data;
44
- weakref->v8_active = false;
45
- if (!weakref->rb_active) {
46
- delete weakref;
47
- }
48
- }
49
-
50
- VALUE v8_weakref_nil(VALUE nil, VALUE exception) {
51
- return nil;
52
- }
53
-
54
- VALUE v8_weakref_objectspace() {
55
- return rb_const_get(rb_cObject, rb_intern("ObjectSpace"));
56
- }
57
-
58
- VALUE v8_weakref_id2ref(VALUE id) {
59
- return rb_funcall(v8_weakref_objectspace(), rb_intern("_id2ref"), 1, id);
60
- }
61
-
data/ext/v8/v8_weakref.h DELETED
@@ -1,29 +0,0 @@
1
- #ifndef _RR_V8_WEAKREF_
2
- #define _RR_V8_WEAKREF_
3
-
4
- #include <v8.h>
5
- #include "ruby.h"
6
- #include "rr.h"
7
-
8
- struct v8_weakref {
9
- v8_weakref(VALUE object);
10
- VALUE get();
11
- void set(VALUE object);
12
- void retain();
13
- void release();
14
-
15
- VALUE object_id;
16
- bool v8_active;
17
- bool rb_active;
18
- v8::Persistent<v8::External> external;
19
- };
20
-
21
- void v8_weakref_dispose(v8::Persistent<v8::Value> value, void* weakref);
22
- VALUE v8_weakref_finalize(VALUE self, VALUE object_id);
23
- VALUE v8_weakref_objectspace();
24
- VALUE v8_weakref_nil(VALUE nil, VALUE exception);
25
- VALUE v8_weakref_id2ref(VALUE id);
26
-
27
- // extern "C" VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
28
-
29
- #endif
data/lib/v8/c/locker.rb DELETED
@@ -1,18 +0,0 @@
1
- module V8
2
- module C
3
- # Shim to support the old style locking syntax. We don't currently
4
- # deprecate this because it might make a comeback at some point.
5
- #
6
- # to synchronize access to V8, and to associate V8 with this thread:
7
- #
8
- # Locker() do
9
- # #... interact with v8
10
- # end
11
- def self.Locker
12
- lock = Locker.new
13
- yield
14
- ensure
15
- lock.delete
16
- end
17
- end
18
- end
data/lib/v8/cli.rb DELETED
@@ -1,133 +0,0 @@
1
- require 'optparse'
2
- require 'ostruct'
3
-
4
- module V8
5
- module CLI
6
- def self.run(exename = 'v8', args = [])
7
- options = OpenStruct.new
8
- options.libs = []
9
- options.libdirs = []
10
- parser = OptionParser.new
11
- parser.banner = "Usage: #{exename} [options]"
12
- parser.on("-r", "--require FILE", "load and execute FILE as JavaScript source") {|r| options.libs << r}
13
- parser.on("-i", "--interactive", "interactive mode") {options.interactive = true}
14
- parser.on("-e", "--execute JAVASCRIPT", String, "evaluate JAVASCRIPT and exit") {|src| options.execute = src}
15
- parser.on("--selftest", "check that therubyracer is functioning properly") {options.selftest = true}
16
- parser.on_tail("-v", "--version", "Show version and exit") {options.version_info = true}
17
- parser.on_tail("-h", "--help", "Show this message") do
18
- puts parser
19
- exit
20
- end
21
- begin
22
- parser.parse!(args.dup)
23
- rescue OptionParser::InvalidOption => e
24
- puts "#{exename}: #{e.message}"
25
- exit(1)
26
- end
27
- if options.version_info
28
- require 'libv8'
29
- puts "The Ruby Racer #{V8::VERSION}"
30
- puts "V8 Version #{Libv8::V8_VERSION}"
31
- exit
32
- elsif options.selftest
33
- self.test
34
- end
35
- Context.new(:with => Shell.new) do |cxt|
36
- for libfile in options.libs do
37
- load(cxt,libfile)
38
- end
39
- if options.interactive
40
- repl(cxt, exename)
41
- elsif options.execute
42
- cxt.eval(options.execute, '<execute>')
43
- else
44
- begin
45
- cxt.eval($stdin, '<stdin>')
46
- rescue Interrupt => e
47
- puts; exit
48
- end
49
- end
50
- end
51
- end
52
-
53
- def self.load(cxt, libfile)
54
- begin
55
- cxt.load(libfile)
56
- rescue V8::JSError => e
57
- puts e.message
58
- puts e.backtrace(:javascript)
59
- rescue StandardError => e
60
- puts e
61
- end
62
- end
63
-
64
- def self.test
65
- begin
66
- require 'rspec'
67
- specs = File.expand_path('../../../spec', __FILE__)
68
- $:.unshift specs
69
- ARGV.clear
70
- ARGV << specs
71
- ::RSpec::Core::Runner.autorun
72
- exit(0)
73
- rescue LoadError => e
74
- puts "selftest requires rspec to be installed (gem install rspec)"
75
- exit(1)
76
- end
77
-
78
- end
79
-
80
- def self.repl(cxt, exename)
81
- require 'readline'
82
- puts "help() for help. quit() to quit."
83
- puts "The Ruby Racer #{V8::VERSION}"
84
- puts "Vroom Vroom!"
85
- trap("SIGINT") do
86
- puts "^C"
87
- end
88
- loop do
89
- line = Readline.readline("#{exename}> ", true)
90
- begin
91
- result = cxt.eval(line, '<shell>')
92
- puts(result) unless result.nil?
93
- rescue V8::JSError => e
94
- puts e.message
95
- puts e.backtrace(:javascript)
96
- rescue StandardError => e
97
- puts e
98
- puts e.backtrace.join("\n")
99
- end
100
- end
101
- end
102
-
103
- class Shell
104
- def to_s
105
- "[object Shell]"
106
- end
107
-
108
- def print(string)
109
- puts string
110
- end
111
-
112
- def exit(status = 0)
113
- Kernel.exit(status)
114
- end
115
-
116
- alias_method :quit, :exit
117
-
118
- def help(*args)
119
- <<-HELP
120
- print(msg)
121
- print msg to STDOUT
122
-
123
- exit(status = 0)
124
- exit the shell
125
- also: quit()
126
-
127
- evalrb(source)
128
- evaluate some ruby source
129
- HELP
130
- end
131
- end
132
- end
133
- end