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
@@ -0,0 +1,181 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ VALUE Accessor::Info::Class;
6
+
7
+ void Accessor::Init() {
8
+ ClassBuilder("AccessorInfo").
9
+ defineMethod("This", &Info::This).
10
+ defineMethod("Holder", &Info::Holder).
11
+ defineMethod("Data", &Info::Data).
12
+ store(&Info::Class);
13
+ }
14
+
15
+ Accessor::Accessor(VALUE getter, VALUE setter, VALUE data_) : get(getter), set(setter), data(data_) {}
16
+
17
+ Accessor::Accessor(VALUE get, VALUE set, VALUE query, VALUE deleter, VALUE enumerator, VALUE data) {
18
+ this->get = get;
19
+ this->set = set;
20
+ this->query = query;
21
+ this->deleter = deleter;
22
+ this->enumerator = enumerator;
23
+ this->data = data;
24
+ }
25
+
26
+ Accessor::Accessor(v8::Handle<v8::Value> value) {
27
+ v8::Local<v8::Object> wrapper = value->ToObject();
28
+ this->get = unwrap(wrapper, 0);
29
+ this->set = unwrap(wrapper, 1);
30
+ this->query = unwrap(wrapper, 2);
31
+ this->deleter = unwrap(wrapper, 3);
32
+ this->enumerator = unwrap(wrapper, 4);
33
+ v8::Handle<v8::Value> data = wrapper->Get(5);
34
+ if (!data.IsEmpty()) {
35
+ this->data = Value(data);
36
+ }
37
+ }
38
+
39
+ Accessor::operator v8::Handle<v8::Value>() {
40
+ v8::Local<v8::Object> wrapper = v8::Object::New();
41
+ wrap(wrapper, 0, this->get);
42
+ wrap(wrapper, 1, this->set);
43
+ wrap(wrapper, 2, this->query);
44
+ wrap(wrapper, 3, this->deleter);
45
+ wrap(wrapper, 4, this->enumerator);
46
+ if (RTEST(this->data)) {
47
+ wrapper->Set(5, Value(this->data));
48
+ }
49
+ return wrapper;
50
+ }
51
+
52
+ void Accessor::wrap(v8::Handle<v8::Object> wrapper, int index, VALUE value) {
53
+ if (RTEST(value)) {
54
+ wrapper->Set(index, External::wrap(value));
55
+ }
56
+ }
57
+
58
+ VALUE Accessor::unwrap(v8::Handle<v8::Object> wrapper, int index) {
59
+ v8::Handle<v8::Value> value = wrapper->Get(index);
60
+ if (value.IsEmpty()) {
61
+ return Qnil;
62
+ } else {
63
+ v8::Handle<v8::External> external(v8::External::Cast(*value));
64
+ return External::unwrap(external);
65
+ }
66
+ }
67
+
68
+
69
+ VALUE Accessor::Info::This(VALUE self) {
70
+ return Object(Info(self)->This());
71
+ }
72
+
73
+ VALUE Accessor::Info::Holder(VALUE self) {
74
+ return Object(Info(self)->Holder());
75
+ }
76
+
77
+ VALUE Accessor::Info::Data(VALUE self) {
78
+ return Accessor(Info(self)->Data()).data;
79
+ }
80
+
81
+ v8::Handle<v8::Value> Accessor::AccessorGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
82
+ return Info(info).get(property);
83
+ }
84
+
85
+ void Accessor::AccessorSetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
86
+ Info(info).set(property, value);
87
+ }
88
+ v8::Handle<v8::Value> Accessor::NamedPropertyGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
89
+ return Info(info).get(property);
90
+ }
91
+ v8::Handle<v8::Value> Accessor::NamedPropertySetter(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
92
+ return Info(info).set(property, value);
93
+ }
94
+ v8::Handle<v8::Integer> Accessor::NamedPropertyQuery(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
95
+ return Info(info).query(property);
96
+ }
97
+ v8::Handle<v8::Boolean> Accessor::NamedPropertyDeleter(v8::Local<v8::String> property, const v8::AccessorInfo& info) {
98
+ return Info(info).remove(property);
99
+ }
100
+ v8::Handle<v8::Array> Accessor::NamedPropertyEnumerator(const v8::AccessorInfo& info) {
101
+ return Info(info).enumerateNames();
102
+ }
103
+
104
+ v8::Handle<v8::Value> Accessor::IndexedPropertyGetter(uint32_t index, const v8::AccessorInfo& info) {
105
+ return Info(info).get(index);
106
+ }
107
+ v8::Handle<v8::Value> Accessor::IndexedPropertySetter(uint32_t index, v8::Local<v8::Value> value, const v8::AccessorInfo& info) {
108
+ return Info(info).set(index, value);
109
+ }
110
+ v8::Handle<v8::Integer> Accessor::IndexedPropertyQuery(uint32_t index, const v8::AccessorInfo& info) {
111
+ return Info(info).query(index);
112
+ }
113
+ v8::Handle<v8::Boolean> Accessor::IndexedPropertyDeleter(uint32_t index, const v8::AccessorInfo& info) {
114
+ return Info(info).remove(index);
115
+ }
116
+ v8::Handle<v8::Array> Accessor::IndexedPropertyEnumerator(const v8::AccessorInfo& info) {
117
+ return Info(info).enumerateIndices();
118
+ }
119
+
120
+ Accessor::Info::Info(const v8::AccessorInfo& info) {
121
+ this->info = &info;
122
+ }
123
+
124
+ Accessor::Info::Info(VALUE value) {
125
+ Data_Get_Struct(value, class v8::AccessorInfo, info);
126
+ }
127
+
128
+ v8::Handle<v8::Value> Accessor::Info::get(v8::Local<v8::String> property) {
129
+ Accessor accessor(info->Data());
130
+ return Value(rb_funcall(accessor.get, rb_intern("call"), 2, (VALUE)String(property), (VALUE)*this));
131
+ }
132
+
133
+ v8::Handle<v8::Value> Accessor::Info::set(v8::Local<v8::String> property, v8::Local<v8::Value> value) {
134
+ Accessor accessor(info->Data());
135
+ return Value(rb_funcall(accessor.set, rb_intern("call"), 3, (VALUE)String(property), (VALUE)Value(value), (VALUE)*this));
136
+ }
137
+
138
+ v8::Handle<v8::Integer> Accessor::Info::query(v8::Local<v8::String> property) {
139
+ Accessor accessor(info->Data());
140
+ return v8::Integer::New(NUM2INT(rb_funcall(accessor.query, rb_intern("call"), 2, (VALUE)String(property), (VALUE)*this)));
141
+ }
142
+
143
+ v8::Handle<v8::Boolean> Accessor::Info::remove(v8::Local<v8::String> property) {
144
+ Accessor accessor(info->Data());
145
+ return v8::Boolean::New(Bool(rb_funcall(accessor.deleter, rb_intern("call"), 2, (VALUE)String(property), (VALUE)*this)));
146
+ }
147
+
148
+ v8::Handle<v8::Array> Accessor::Info::enumerateNames() {
149
+ Accessor accessor(info->Data());
150
+ return Array(rb_funcall(accessor.enumerator, rb_intern("call"), 1, (VALUE)*this));
151
+ }
152
+
153
+ v8::Handle<v8::Value> Accessor::Info::get(uint32_t index) {
154
+ Accessor accessor(info->Data());
155
+ return Value(rb_funcall(accessor.get, rb_intern("call"), 2, UINT2NUM(index), (VALUE)*this));
156
+ }
157
+
158
+ v8::Handle<v8::Value> Accessor::Info::set(uint32_t index, v8::Local<v8::Value> value) {
159
+ Accessor accessor(info->Data());
160
+ return Value(rb_funcall(accessor.set, rb_intern("call"), 3, UINT2NUM(index), (VALUE)Value(value), (VALUE)*this));
161
+ }
162
+
163
+ v8::Handle<v8::Integer> Accessor::Info::query(uint32_t index) {
164
+ Accessor accessor(info->Data());
165
+ return v8::Integer::New(NUM2INT(rb_funcall(accessor.query, rb_intern("call"), 2, UINT2NUM(index), (VALUE)*this)));
166
+ }
167
+
168
+ v8::Handle<v8::Boolean> Accessor::Info::remove(uint32_t index) {
169
+ Accessor accessor(info->Data());
170
+ return v8::Boolean::New(Bool(rb_funcall(accessor.deleter, rb_intern("call"), 2, UINT2NUM(index), (VALUE)*this)));
171
+ }
172
+
173
+ v8::Handle<v8::Array> Accessor::Info::enumerateIndices() {
174
+ Accessor accessor(info->Data());
175
+ return Array(rb_funcall(accessor.enumerator, rb_intern("call"), 1, (VALUE)*this));
176
+ }
177
+
178
+ Accessor::Info::operator VALUE() {
179
+ return Data_Wrap_Struct(Class, 0, 0, (void*)this->info);
180
+ }
181
+ }
data/ext/v8/array.cc ADDED
@@ -0,0 +1,26 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ void Array::Init() {
6
+ ClassBuilder("Array", Object::Class).
7
+ defineSingletonMethod("New", &New).
8
+ defineMethod("Length", &Length).
9
+ defineMethod("CloneElementAt", &CloneElementAt).
10
+ store(&Class);
11
+ }
12
+
13
+ VALUE Array::New(int argc, VALUE argv[], VALUE self) {
14
+ VALUE length; rb_scan_args(argc, argv, "01", &length);
15
+ return Array(v8::Array::New(RTEST(length) ? NUM2INT(length) : 0));
16
+ }
17
+
18
+ VALUE Array::Length(VALUE self) {
19
+ return UInt32(Array(self)->Length());
20
+ }
21
+
22
+ VALUE Array::CloneElementAt(VALUE self, VALUE index) {
23
+ return Object(Array(self)->CloneElementAt(UInt32(index)));
24
+ }
25
+
26
+ }
data/ext/v8/backref.cc ADDED
@@ -0,0 +1,56 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ VALUE Backref::Storage;
6
+ ID Backref::_new;
7
+ ID Backref::object;
8
+
9
+ void Backref::Init() {
10
+ Storage = rb_eval_string("Ref::WeakReference");
11
+ rb_gc_register_address(&Storage);
12
+ _new = rb_intern("new");
13
+ object = rb_intern("object");
14
+ }
15
+
16
+ Backref::Backref(VALUE initial) {
17
+ allocate(initial);
18
+ this->storage = rb_funcall(Storage, _new, 1, initial);
19
+ rb_gc_register_address(&storage);
20
+ }
21
+
22
+ Backref::~Backref() {
23
+ deallocate();
24
+ }
25
+
26
+ void Backref::allocate(VALUE data) {
27
+ this->storage = rb_funcall(Storage, _new, 1, data);
28
+ rb_gc_register_address(&storage);
29
+ }
30
+
31
+ void Backref::deallocate() {
32
+ rb_gc_unregister_address(&storage);
33
+ }
34
+
35
+ VALUE Backref::get() {
36
+ return rb_funcall(storage, object, 0);
37
+ }
38
+
39
+ VALUE Backref::set(VALUE data) {
40
+ deallocate();
41
+ allocate(data);
42
+ return data;
43
+ }
44
+
45
+ v8::Handle<v8::Value> Backref::toExternal() {
46
+ v8::Local<v8::Value> wrapper = v8::External::Wrap(this);
47
+ v8::Persistent<v8::Value>::New(wrapper).MakeWeak(this, &release);
48
+ return wrapper;
49
+ }
50
+
51
+ void Backref::release(v8::Persistent<v8::Value> handle, void* data) {
52
+ handle.Dispose();
53
+ Backref* backref = (Backref*)data;
54
+ delete backref;
55
+ }
56
+ }
data/ext/v8/build.rb ADDED
@@ -0,0 +1,51 @@
1
+
2
+ LIBV8_COMPATIBILITY = '~> 3.11.8'
3
+
4
+ def have_rubygem_libv8?
5
+ require 'rubygems'
6
+ gem 'libv8', LIBV8_COMPATIBILITY
7
+ return true
8
+ rescue Gem::LoadError
9
+ return false
10
+ rescue LoadError
11
+ return false
12
+ end
13
+
14
+ def build_with_system_libv8
15
+ dir_config('v8')
16
+ find_header('v8.h') or begin
17
+ puts <<-EOS
18
+ The Ruby Racer requires libv8 #{LIBV8_COMPATIBILITY}
19
+ to be present on your system in order to compile
20
+ and link, but it could not be found.
21
+
22
+ In order to resolve this, you will either need to manually
23
+ install an appropriate libv8 and make sure that this
24
+ build process can find it. If you install it into the
25
+ standard system path, then it should just be picked up
26
+ automatically. Otherwise, you'll have to pass some extra
27
+ flags to the build process as a hint.
28
+
29
+ If you don't want to bother with all that, there is a
30
+ rubygem that will do all this for you. You can add
31
+ following line to your Gemfile:
32
+ gem 'libv8', '#{LIBV8_COMPATIBILITY}'
33
+
34
+ We hope that helps, and we apologize, but now we have
35
+ to push the eject button on this install.
36
+
37
+ thanks,
38
+ The Mgmt.
39
+
40
+ EOS
41
+ raise "unable to locate libv8. Please see output for details"
42
+ end
43
+ $LDFLAGS << " -lv8 "
44
+ end
45
+
46
+ def build_with_rubygem_libv8
47
+ require 'libv8'
48
+ include Libv8
49
+ $INCFLAGS.insert 0, "#{libv8_include_flags} "
50
+ $LDFLAGS.insert 0, libv8_objects.join(' ') + " "
51
+ end
@@ -0,0 +1,34 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ VALUE Constants::_Undefined;
5
+ VALUE Constants::_Null;
6
+ VALUE Constants::_True;
7
+ VALUE Constants::_False;
8
+ void Constants::Init() {
9
+ ModuleBuilder("V8::C").
10
+ defineSingletonMethod("Undefined", &Undefined).
11
+ defineSingletonMethod("Null", &Null).
12
+ defineSingletonMethod("True", &True).
13
+ defineSingletonMethod("False", &False);
14
+
15
+ _Undefined = _Null = _True = _False = Qnil;
16
+ rb_gc_register_address(&_Undefined);
17
+ rb_gc_register_address(&_Null);
18
+ rb_gc_register_address(&_True);
19
+ rb_gc_register_address(&_False);
20
+ }
21
+
22
+ VALUE Constants::Undefined(VALUE self) {
23
+ return cached<Primitive, v8::Primitive>(&_Undefined, v8::Undefined());
24
+ }
25
+ VALUE Constants::Null(VALUE self) {
26
+ return cached<Primitive, v8::Primitive>(&_Null, v8::Null());
27
+ }
28
+ VALUE Constants::True(VALUE self) {
29
+ return cached<Bool, v8::Boolean>(&_True, v8::True());
30
+ }
31
+ VALUE Constants::False(VALUE self) {
32
+ return cached<Bool, v8::Boolean>(&_False, v8::False());
33
+ }
34
+ }
@@ -0,0 +1,52 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+ void ResourceConstraints::Init() {
5
+ ClassBuilder("ResourceConstraints").
6
+ defineSingletonMethod("new", &initialize).
7
+ defineMethod("max_young_space_size", &max_young_space_size).
8
+ defineMethod("set_max_young_space_size", &set_max_young_space_size).
9
+ defineMethod("max_old_space_size", &max_old_space_size).
10
+ defineMethod("set_max_old_space_size", &set_max_old_space_size).
11
+ defineMethod("max_executable_size", &set_max_executable_size).
12
+ defineMethod("set_max_executable_size", &set_max_executable_size).
13
+ store(&Class);
14
+ ModuleBuilder("V8::C").
15
+ defineSingletonMethod("SetResourceConstraints", &SetResourceConstraints);
16
+ }
17
+
18
+ VALUE ResourceConstraints::SetResourceConstraints(VALUE self, VALUE constraints) {
19
+ Void(v8::SetResourceConstraints(ResourceConstraints(constraints)));
20
+ }
21
+
22
+ VALUE ResourceConstraints::initialize(VALUE self) {
23
+ return ResourceConstraints(new v8::ResourceConstraints());
24
+ }
25
+ VALUE ResourceConstraints::max_young_space_size(VALUE self) {
26
+ return INT2FIX(ResourceConstraints(self)->max_young_space_size());
27
+ }
28
+ VALUE ResourceConstraints::set_max_young_space_size(VALUE self, VALUE value) {
29
+ Void(ResourceConstraints(self)->set_max_young_space_size(NUM2INT(value)));
30
+ }
31
+ VALUE ResourceConstraints::max_old_space_size(VALUE self) {
32
+ return INT2FIX(ResourceConstraints(self)->max_old_space_size());
33
+ }
34
+ VALUE ResourceConstraints::set_max_old_space_size(VALUE self, VALUE value) {
35
+ Void(ResourceConstraints(self)->set_max_old_space_size(NUM2INT(value)));
36
+ }
37
+ VALUE ResourceConstraints::max_executable_size(VALUE self) {
38
+ return INT2FIX(ResourceConstraints(self)->max_executable_size());
39
+ }
40
+ VALUE ResourceConstraints::set_max_executable_size(VALUE self, VALUE value) {
41
+ Void(ResourceConstraints(self)->set_max_executable_size(NUM2INT(value)));
42
+ }
43
+
44
+ // What do these even mean?
45
+ // uint32_t* stack_limit() const { return stack_limit_; }
46
+ // // Sets an address beyond which the VM's stack may not grow.
47
+ // void set_stack_limit(uint32_t* value) { stack_limit_ = value; }
48
+
49
+ template <> void Pointer<v8::ResourceConstraints>::unwrap(VALUE value) {
50
+ Data_Get_Struct(value, class v8::ResourceConstraints, pointer);
51
+ }
52
+ }
data/ext/v8/context.cc ADDED
@@ -0,0 +1,130 @@
1
+ #include "rr.h"
2
+
3
+ namespace rr {
4
+
5
+ void Context::Init() {
6
+ ClassBuilder("Context").
7
+ defineSingletonMethod("New", &New).
8
+ defineSingletonMethod("GetCurrent", &GetCurrent).
9
+ defineSingletonMethod("GetEntered", &GetEntered).
10
+ defineSingletonMethod("GetCalling", &GetCalling).
11
+ defineSingletonMethod("InContext", &InContext).
12
+ defineMethod("Dispose", &Dispose).
13
+ defineMethod("Global", &Global).
14
+ defineMethod("DetachGlobal", &Global).
15
+ defineMethod("ReattachGlobal", &ReattachGlobal).
16
+ defineMethod("SetSecurityToken", &SetSecurityToken).
17
+ defineMethod("UseDefaultSecurityToken", &UseDefaultSecurityToken).
18
+ defineMethod("GetSecurityToken", &GetSecurityToken).
19
+ defineMethod("HasOutOfMemoryException", &HasOutOfMemoryException).
20
+ defineMethod("SetData", &SetData).
21
+ defineMethod("GetData", &GetData).
22
+ defineMethod("AllowCodeGenerationFromStrings", &AllowCodeGenerationFromStrings).
23
+ defineMethod("IsCodeGenerationFromStringsAllowed", &IsCodeGenerationFromStringsAllowed).
24
+ defineMethod("Enter", &Enter).
25
+ defineMethod("Exit", &Exit).
26
+ store(&Class);
27
+ ClassBuilder("ExtensionConfiguration").
28
+ defineSingletonMethod("new", &ExtensionConfiguration::initialize).
29
+ store(&ExtensionConfiguration::Class);
30
+ }
31
+
32
+ VALUE Context::Dispose(VALUE self) {
33
+ Void(Context(self).dispose())
34
+ }
35
+
36
+ VALUE Context::Global(VALUE self) {
37
+ return Object(Context(self)->Global());
38
+ }
39
+
40
+ VALUE Context::DetachGlobal(VALUE self) {
41
+ Void(Context(self)->DetachGlobal());
42
+ }
43
+
44
+ VALUE Context::ReattachGlobal(VALUE self, VALUE global) {
45
+ Void(Context(self)->ReattachGlobal(Object(global)));
46
+ }
47
+
48
+ VALUE Context::GetEntered(VALUE self) {
49
+ return Context(v8::Context::GetEntered());
50
+ }
51
+
52
+ VALUE Context::GetCurrent(VALUE self) {
53
+ return Context(v8::Context::GetCurrent());
54
+ }
55
+
56
+ VALUE Context::GetCalling(VALUE self) {
57
+ return Context(v8::Context::GetCalling());
58
+ }
59
+
60
+ VALUE Context::SetSecurityToken(VALUE self, VALUE token) {
61
+ Void(Context(self)->SetSecurityToken(Value(token)));
62
+ }
63
+
64
+ VALUE Context::UseDefaultSecurityToken(VALUE self) {
65
+ Void(Context(self)->UseDefaultSecurityToken());
66
+ }
67
+
68
+ VALUE Context::GetSecurityToken(VALUE self) {
69
+ return Value(Context(self)->GetSecurityToken());
70
+ }
71
+
72
+ VALUE Context::HasOutOfMemoryException(VALUE self) {
73
+ return Bool(Context(self)->HasOutOfMemoryException());
74
+ }
75
+
76
+ VALUE Context::InContext(VALUE self) {
77
+ return Bool(v8::Context::InContext());
78
+ }
79
+
80
+ VALUE Context::SetData(VALUE self, VALUE data) {
81
+ Void(Context(self)->SetData(String(data)));
82
+ }
83
+
84
+ VALUE Context::GetData(VALUE self) {
85
+ return Value(Context(self)->GetData());
86
+ }
87
+
88
+ VALUE Context::AllowCodeGenerationFromStrings(VALUE self, VALUE allow) {
89
+ Void(Context(self)->AllowCodeGenerationFromStrings(RTEST(allow)));
90
+ }
91
+
92
+ VALUE Context::IsCodeGenerationFromStringsAllowed(VALUE self) {
93
+ return Bool(Context(self)->IsCodeGenerationFromStringsAllowed());
94
+ }
95
+
96
+ VALUE ExtensionConfiguration::initialize(VALUE self, VALUE names) {
97
+ int length = RARRAY_LENINT(names);
98
+ const char* array[length];
99
+ for (int i = 0; i < length; i++) {
100
+ array[i] = RSTRING_PTR(rb_ary_entry(names, i));
101
+ }
102
+ return ExtensionConfiguration(new v8::ExtensionConfiguration(length, array));
103
+ }
104
+
105
+ VALUE Context::New(int argc, VALUE argv[], VALUE self) {
106
+ VALUE extension_configuration; VALUE global_template; VALUE global_object;
107
+ rb_scan_args(argc, argv, "03", &extension_configuration, &global_template, &global_object);
108
+ v8::Persistent<v8::Context> context(v8::Context::New(
109
+ ExtensionConfiguration(extension_configuration),
110
+ *ObjectTemplate(global_template),
111
+ *Object(global_object)
112
+ ));
113
+ Context reference(context);
114
+ context.Dispose();
115
+ return reference;
116
+ }
117
+
118
+ VALUE Context::Enter(VALUE self) {
119
+ Void(Context(self)->Enter());
120
+ }
121
+
122
+ VALUE Context::Exit(VALUE self) {
123
+ Void(Context(self)->Exit());
124
+ }
125
+
126
+ template <> void Pointer<v8::ExtensionConfiguration>::unwrap(VALUE value) {
127
+ Data_Get_Struct(value, class v8::ExtensionConfiguration, pointer);
128
+ }
129
+
130
+ }