therubyracer 0.7.1 → 0.7.2.pre
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.
- data/Rakefile +3 -2
- data/ext/v8/rr.cpp +5 -18
- data/ext/v8/rr.h +0 -3
- data/ext/v8/upstream/Makefile +1 -1
- data/ext/v8/v8_array.cpp +3 -9
- data/ext/v8/v8_callbacks.cpp +1 -1
- data/ext/v8/v8_cxt.cpp +19 -36
- data/ext/v8/v8_cxt.h +0 -7
- data/ext/v8/v8_exception.cpp +2 -1
- data/ext/v8/v8_external.cpp +18 -11
- data/ext/v8/v8_external.h +1 -0
- data/ext/v8/v8_func.cpp +2 -5
- data/ext/v8/v8_func.h +0 -2
- data/ext/v8/v8_msg.cpp +1 -2
- data/ext/v8/v8_obj.cpp +3 -13
- data/ext/v8/v8_obj.h +0 -1
- data/ext/v8/v8_ref.cpp +1 -6
- data/ext/v8/v8_ref.h +1 -2
- data/ext/v8/v8_script.cpp +0 -2
- data/ext/v8/v8_str.cpp +9 -3
- data/ext/v8/v8_str.h +0 -2
- data/ext/v8/v8_template.cpp +49 -37
- data/ext/v8/v8_template.h +0 -4
- data/ext/v8/v8_try_catch.cpp +0 -1
- data/ext/v8/v8_value.cpp +1 -2
- data/lib/v8.rb +2 -1
- data/lib/v8/access.rb +90 -1
- data/lib/v8/array.rb +1 -1
- data/lib/v8/context.rb +8 -23
- data/lib/v8/error.rb +111 -0
- data/lib/v8/function.rb +6 -5
- data/lib/v8/object.rb +1 -1
- data/lib/v8/to.rb +26 -30
- data/spec/redjs/jsapi_spec.rb +55 -14
- data/spec/v8/error_spec.rb +118 -0
- data/therubyracer.gemspec +4 -4
- metadata +14 -21
- data/ext/v8/callbacks.cpp +0 -185
- data/ext/v8/callbacks.h +0 -14
- data/ext/v8/convert_ruby.cpp +0 -8
- data/ext/v8/convert_ruby.h +0 -99
- data/ext/v8/convert_string.cpp +0 -10
- data/ext/v8/convert_string.h +0 -73
- data/ext/v8/convert_v8.cpp +0 -9
- data/ext/v8/convert_v8.h +0 -124
- data/ext/v8/converters.cpp +0 -84
- data/ext/v8/converters.h +0 -21
- data/ext/v8/v8.bundle +0 -0
- data/lib/v8/callbacks.rb +0 -88
data/ext/v8/v8_obj.h
CHANGED
data/ext/v8/v8_ref.cpp
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
#include "stdio.h"
|
3
3
|
using namespace v8;
|
4
4
|
|
5
|
-
v8_ref::v8_ref(Handle<void> object
|
5
|
+
v8_ref::v8_ref(Handle<void> object) : handle(Persistent<void>::New(object)) {
|
6
6
|
this->references = rb_hash_new();
|
7
|
-
this->set("default", ref);
|
8
7
|
}
|
9
8
|
|
10
9
|
v8_ref::~v8_ref() {
|
@@ -27,10 +26,6 @@ namespace {
|
|
27
26
|
}
|
28
27
|
}
|
29
28
|
|
30
|
-
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref) {
|
31
|
-
return Data_Wrap_Struct(ruby_class, gc_mark, gc_free, new v8_ref(handle, ref));
|
32
|
-
}
|
33
|
-
|
34
29
|
VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle<void> handle) {
|
35
30
|
return Data_Wrap_Struct(rbclass, gc_mark, gc_free, new v8_ref(handle));
|
36
31
|
}
|
data/ext/v8/v8_ref.h
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
struct v8_ref {
|
10
10
|
//takes a handle object and adds a new persistent handle for
|
11
11
|
//the referenced object
|
12
|
-
v8_ref(v8::Handle<void> object
|
12
|
+
v8_ref(v8::Handle<void> object);
|
13
13
|
virtual ~v8_ref();
|
14
14
|
void set(const char *name, VALUE ref);
|
15
15
|
v8::Persistent<void> handle;
|
@@ -17,7 +17,6 @@ struct v8_ref {
|
|
17
17
|
};
|
18
18
|
|
19
19
|
void rr_v8_ref_setref(VALUE handle, const char *name, VALUE ref);
|
20
|
-
VALUE V8_Ref_Create(VALUE ruby_class, v8::Handle<void> handle, VALUE ref = 0);
|
21
20
|
VALUE rr_v8_ref_create(VALUE rbclass, v8::Handle<void> handle);
|
22
21
|
|
23
22
|
template <class T> v8::Local<T> V8_Ref_Get(VALUE object) {
|
data/ext/v8/v8_script.cpp
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
#include "v8.h"
|
2
2
|
#include "v8_ref.h"
|
3
3
|
#include "v8_script.h"
|
4
|
-
#include "converters.h"
|
5
4
|
|
6
5
|
using namespace v8;
|
7
6
|
|
@@ -32,5 +31,4 @@ void rr_init_script() {
|
|
32
31
|
rr_define_singleton_method(ScriptClass, "New", New, 2);
|
33
32
|
rr_define_singleton_method(ScriptClass, "Compile", Compile, 2);
|
34
33
|
rr_define_method(ScriptClass, "Run", Run, 0);
|
35
|
-
rb_funcall(ScriptClass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
|
36
34
|
}
|
data/ext/v8/v8_str.cpp
CHANGED
@@ -12,10 +12,15 @@ namespace {
|
|
12
12
|
Handle<String> unwrap(VALUE value) {
|
13
13
|
return V8_Ref_Get<String>(value);
|
14
14
|
}
|
15
|
-
VALUE New(VALUE
|
15
|
+
VALUE New(VALUE string_class, VALUE data) {
|
16
16
|
HandleScope handles;
|
17
17
|
VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
|
18
|
-
return
|
18
|
+
return rr_v8_ref_create(string_class, String::New(RSTRING_PTR(str), RSTRING_LEN(str)));
|
19
|
+
}
|
20
|
+
VALUE NewSymbol(VALUE string_class, VALUE data) {
|
21
|
+
HandleScope scope;
|
22
|
+
VALUE str = rb_funcall(data, rb_intern("to_s"), 0);
|
23
|
+
return rr_v8_ref_create(string_class, String::NewSymbol(RSTRING_PTR(str), RSTRING_LEN(str)));
|
19
24
|
}
|
20
25
|
VALUE Utf8Value(VALUE self) {
|
21
26
|
HandleScope handles;
|
@@ -34,12 +39,13 @@ namespace {
|
|
34
39
|
VALUE rr_reflect_v8_string(Handle<Value> value) {
|
35
40
|
HandleScope handles;
|
36
41
|
Local<String> string = String::Cast(*value);
|
37
|
-
return
|
42
|
+
return rr_v8_ref_create(StringClass, string);
|
38
43
|
}
|
39
44
|
|
40
45
|
void rr_init_str() {
|
41
46
|
StringClass = rr_define_class("String", rr_cV8_C_Value);
|
42
47
|
rr_define_singleton_method(StringClass, "New", New, 1);
|
48
|
+
rr_define_singleton_method(StringClass, "NewSymbol", NewSymbol, 1);
|
43
49
|
rr_define_method(StringClass, "Utf8Value", Utf8Value, 0);
|
44
50
|
rr_define_method(StringClass, "Utf16Value", Utf16Value, 0);
|
45
51
|
rr_define_method(StringClass, "AsciiValue", AsciiValue, 0);
|
data/ext/v8/v8_str.h
CHANGED
data/ext/v8/v8_template.cpp
CHANGED
@@ -1,17 +1,17 @@
|
|
1
|
-
#include
|
2
|
-
#include <v8.h>
|
1
|
+
#include "rr.h"
|
3
2
|
#include "v8_ref.h"
|
4
3
|
#include "v8_func.h"
|
5
4
|
#include "v8_template.h"
|
6
5
|
#include "v8_external.h"
|
7
6
|
#include "v8_callbacks.h"
|
8
|
-
#include "callbacks.h"
|
9
|
-
#include "converters.h"
|
10
7
|
|
11
8
|
using namespace v8;
|
12
9
|
|
13
10
|
namespace {
|
14
11
|
|
12
|
+
VALUE ObjectTemplateClass;
|
13
|
+
VALUE FunctionTemplateClass;
|
14
|
+
|
15
15
|
VALUE rb_hash_lookup(VALUE hash, const char *key) {
|
16
16
|
return rb_funcall(hash, rb_intern("[]"), 1, rb_str_new2(key));
|
17
17
|
}
|
@@ -55,7 +55,6 @@ namespace {
|
|
55
55
|
* Otherwise, returns an empty handle.
|
56
56
|
*/
|
57
57
|
Handle<Value> RubyNamedPropertySetter(Local<String> property, Local<Value> value, const AccessorInfo& info) {
|
58
|
-
HandleScope handles;
|
59
58
|
VALUE code = (VALUE)External::Unwrap(info.Data());
|
60
59
|
VALUE setter = rb_hash_lookup(code, "setter");
|
61
60
|
VALUE result = rb_funcall(setter, rb_intern("call"), 3, rr_v82rb(property), rr_v82rb(value), rr_v82rb(info));
|
@@ -68,7 +67,6 @@ namespace {
|
|
68
67
|
* The result is true if the property exists and false otherwise.
|
69
68
|
*/
|
70
69
|
Handle<Boolean> RubyNamedPropertyQuery(Local<String> property, const AccessorInfo& info) {
|
71
|
-
HandleScope handles;
|
72
70
|
VALUE code = (VALUE)External::Unwrap(info.Data());
|
73
71
|
VALUE query = rb_hash_lookup(code, "query");
|
74
72
|
VALUE result = rb_funcall(query, rb_intern("call"), 2, rr_v82rb(property), rr_v82rb(info));
|
@@ -82,7 +80,6 @@ namespace {
|
|
82
80
|
* otherwise.
|
83
81
|
*/
|
84
82
|
Handle<Boolean> RubyNamedPropertyDeleter(Local<String> property, const AccessorInfo& info) {
|
85
|
-
HandleScope handles;
|
86
83
|
VALUE code = (VALUE)External::Unwrap(info.Data());
|
87
84
|
VALUE deleter = rb_hash_lookup(code, "deleter");
|
88
85
|
VALUE result = rb_funcall(deleter, rb_intern("call"), 2, rr_v82rb(property), rr_v82rb(info));
|
@@ -95,7 +92,6 @@ namespace {
|
|
95
92
|
* property getter intercepts.
|
96
93
|
*/
|
97
94
|
Handle<Array> RubyNamedPropertyEnumerator(const AccessorInfo& info) {
|
98
|
-
HandleScope handles;
|
99
95
|
VALUE code = (VALUE)External::Unwrap(info.Data());
|
100
96
|
VALUE enumerator = rb_hash_lookup(code, "enumerator");
|
101
97
|
VALUE result = rb_funcall(enumerator, rb_intern("call"), 1, rr_v82rb(info));
|
@@ -111,9 +107,9 @@ namespace {
|
|
111
107
|
}
|
112
108
|
}
|
113
109
|
|
114
|
-
VALUE New(VALUE
|
110
|
+
VALUE New(VALUE rbclass) {
|
115
111
|
HandleScope handles;
|
116
|
-
return
|
112
|
+
return rr_v8_ref_create(rbclass, ObjectTemplate::New());
|
117
113
|
}
|
118
114
|
VALUE NewInstance(VALUE self) {
|
119
115
|
HandleScope scope;
|
@@ -156,7 +152,6 @@ namespace {
|
|
156
152
|
namespace Func {
|
157
153
|
|
158
154
|
Handle<Value> RubyInvocationCallback(const Arguments& args) {
|
159
|
-
HandleScope handles;
|
160
155
|
VALUE code = (VALUE)External::Unwrap(args.Data());
|
161
156
|
VALUE rb_args = rr_v82rb(args);
|
162
157
|
VALUE result = rb_funcall(code, rb_intern("call"), 1, rb_args);
|
@@ -165,13 +160,41 @@ namespace {
|
|
165
160
|
|
166
161
|
VALUE New(VALUE function_template) {
|
167
162
|
HandleScope handles;
|
168
|
-
rb_need_block();
|
169
163
|
VALUE code = rb_block_proc();
|
170
164
|
if (NIL_P(code)) {
|
171
165
|
return Qnil;
|
172
166
|
}
|
173
167
|
Local<FunctionTemplate> templ = FunctionTemplate::New(RubyInvocationCallback, rr_v8_external_create(code));
|
174
|
-
|
168
|
+
VALUE ref = rr_v8_ref_create(function_template,templ);
|
169
|
+
rr_v8_ref_setref(ref, "code", code);
|
170
|
+
return ref;
|
171
|
+
}
|
172
|
+
VALUE SetCallHandler(VALUE self) {
|
173
|
+
HandleScope handles;
|
174
|
+
VALUE code = rb_block_proc();
|
175
|
+
if (NIL_P(code)) {
|
176
|
+
return Qnil;
|
177
|
+
}
|
178
|
+
func(self)->SetCallHandler(RubyInvocationCallback, rr_v8_external_create(code));
|
179
|
+
return Qnil;
|
180
|
+
}
|
181
|
+
VALUE PrototypeTemplate(VALUE self) {
|
182
|
+
HandleScope scope;
|
183
|
+
return rr_v8_ref_create(ObjectTemplateClass, func(self)->PrototypeTemplate());
|
184
|
+
}
|
185
|
+
VALUE InstanceTemplate(VALUE self) {
|
186
|
+
HandleScope scope;
|
187
|
+
return rr_v8_ref_create(ObjectTemplateClass, func(self)->InstanceTemplate());
|
188
|
+
}
|
189
|
+
VALUE Inherit(VALUE self, VALUE function_template) {
|
190
|
+
HandleScope scope;
|
191
|
+
func(self)->Inherit(func(function_template));
|
192
|
+
return Qnil;
|
193
|
+
}
|
194
|
+
VALUE SetClassName(VALUE self, VALUE name) {
|
195
|
+
HandleScope scope;
|
196
|
+
func(self)->SetClassName(rr_rb2v8(name)->ToString());
|
197
|
+
return Qnil;
|
175
198
|
}
|
176
199
|
VALUE GetFunction(VALUE self) {
|
177
200
|
HandleScope handles;
|
@@ -188,28 +211,17 @@ void rr_init_template() {
|
|
188
211
|
VALUE Template = rr_define_class("Template");
|
189
212
|
rr_define_method(Template, "Set", Set, 2);
|
190
213
|
|
191
|
-
|
192
|
-
rr_define_singleton_method(
|
193
|
-
rr_define_method(
|
194
|
-
rr_define_method(
|
195
|
-
|
196
|
-
|
197
|
-
rr_define_singleton_method(
|
198
|
-
rr_define_method(
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
Local<ObjectTemplate> tmpl = ObjectTemplate::New();
|
205
|
-
// tmpl->SetInternalFieldCount(2);
|
206
|
-
tmpl->SetNamedPropertyHandler(
|
207
|
-
RacerRubyNamedPropertyGetter,
|
208
|
-
RacerRubyNamedPropertySetter,
|
209
|
-
0, // RacerRubyNamedPropertyQuery,
|
210
|
-
0, // RacerRubyNamedPropertyDeleter,
|
211
|
-
RacerRubyNamedPropertyEnumerator,
|
212
|
-
rr_v8_external_create(value)
|
213
|
-
);
|
214
|
-
return tmpl;
|
214
|
+
ObjectTemplateClass = rr_define_class("ObjectTemplate", Template);
|
215
|
+
rr_define_singleton_method(ObjectTemplateClass, "New", Obj::New, 0);
|
216
|
+
rr_define_method(ObjectTemplateClass, "NewInstance", Obj::NewInstance, 0);
|
217
|
+
rr_define_method(ObjectTemplateClass, "SetNamedPropertyHandler", Obj::SetNamedPropertyHandler, 5);
|
218
|
+
|
219
|
+
FunctionTemplateClass = rr_define_class("FunctionTemplate", Template);
|
220
|
+
rr_define_singleton_method(FunctionTemplateClass, "New", Func::New, 0);
|
221
|
+
rr_define_method(FunctionTemplateClass, "SetCallHandler", Func::SetCallHandler, 0);
|
222
|
+
rr_define_method(FunctionTemplateClass, "PrototypeTemplate", Func::PrototypeTemplate, 0);
|
223
|
+
rr_define_method(FunctionTemplateClass, "InstanceTemplate", Func::InstanceTemplate, 0);
|
224
|
+
rr_define_method(FunctionTemplateClass, "Inherit", Func::Inherit, 1);
|
225
|
+
rr_define_method(FunctionTemplateClass, "SetClassName", Func::SetClassName, 1);
|
226
|
+
rr_define_method(FunctionTemplateClass, "GetFunction", Func::GetFunction, 0);
|
215
227
|
}
|
data/ext/v8/v8_template.h
CHANGED
data/ext/v8/v8_try_catch.cpp
CHANGED
@@ -96,5 +96,4 @@ void rr_init_v8_try_catch() {
|
|
96
96
|
rr_define_method(TryCatchClass, "StackTrace", StackTrace, 0);
|
97
97
|
rr_define_method(TryCatchClass, "Message", _Message, 0);
|
98
98
|
rr_define_method(TryCatchClass, "CanContinue", CanContinue, 0);
|
99
|
-
rb_funcall(TryCatchClass, rb_intern("private_class_method"), 1, rb_str_new2("new"));
|
100
99
|
}
|
data/ext/v8/v8_value.cpp
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
#include "v8_value.h"
|
2
2
|
#include "v8_ref.h"
|
3
|
-
#include "converters.h"
|
4
3
|
|
5
4
|
using namespace v8;
|
6
5
|
namespace {
|
@@ -164,5 +163,5 @@ void rr_init_value() {
|
|
164
163
|
}
|
165
164
|
|
166
165
|
VALUE rr_wrap_v8_value(Handle<Value>& value) {
|
167
|
-
return
|
166
|
+
return rr_v8_ref_create(rr_cV8_C_Value, value);
|
168
167
|
}
|
data/lib/v8.rb
CHANGED
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
4
|
module V8
|
5
|
-
VERSION = '0.7.
|
5
|
+
VERSION = '0.7.2.pre'
|
6
6
|
require 'v8/v8' #native glue
|
7
7
|
require 'v8/to'
|
8
8
|
require 'v8/context'
|
@@ -11,4 +11,5 @@ module V8
|
|
11
11
|
require 'v8/function'
|
12
12
|
require 'v8/tap'
|
13
13
|
require 'v8/access'
|
14
|
+
require 'v8/error'
|
14
15
|
end
|
data/lib/v8/access.rb
CHANGED
@@ -1,6 +1,95 @@
|
|
1
1
|
require 'set'
|
2
2
|
module V8
|
3
3
|
|
4
|
+
#TODO each context should get its own access rules instead of sharing them across
|
5
|
+
# contetxts
|
6
|
+
###### --cowboyd 07/07/2010
|
7
|
+
class Access
|
8
|
+
def self.[](cls)
|
9
|
+
@access ||= Access.new
|
10
|
+
@access[cls]
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@classes = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def [](cls)
|
18
|
+
@classes ||= {}
|
19
|
+
if ref = @classes[cls.object_id]
|
20
|
+
if ref.weakref_alive?
|
21
|
+
ref.__getobj__
|
22
|
+
else
|
23
|
+
@classes.delete(cls.object_id)
|
24
|
+
self[cls]
|
25
|
+
end
|
26
|
+
else
|
27
|
+
template(cls).tap do |t|
|
28
|
+
t.InstanceTemplate().SetNamedPropertyHandler(
|
29
|
+
NamedPropertyGetter,
|
30
|
+
NamedPropertySetter,
|
31
|
+
nil,
|
32
|
+
nil,
|
33
|
+
NamedPropertyEnumerator
|
34
|
+
)
|
35
|
+
if cls.name && cls.name =~ /(::)?(\w+?)$/
|
36
|
+
t.SetClassName(C::String::NewSymbol("rb::" + $2))
|
37
|
+
else
|
38
|
+
t.SetClassName("Ruby")
|
39
|
+
end
|
40
|
+
@classes[cls.object_id] = WeakRef.new(t)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def template(cls)
|
46
|
+
C::FunctionTemplate::New() do |arguments|
|
47
|
+
unless arguments.Length() == 1 && arguments[0].kind_of?(C::External)
|
48
|
+
C::ThrowException(C::Exception::Error(C::String::New("cannot call native constructor from javascript")))
|
49
|
+
else
|
50
|
+
arguments.This().tap do |this|
|
51
|
+
this.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"), arguments[0])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.rubyobject
|
58
|
+
@rubyobject ||= C::ObjectTemplate::New().tap do |t|
|
59
|
+
t.SetNamedPropertyHandler(
|
60
|
+
NamedPropertyGetter,
|
61
|
+
NamedPropertySetter,
|
62
|
+
nil,
|
63
|
+
nil,
|
64
|
+
NamedPropertyEnumerator
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Constructors < Access
|
71
|
+
def self.[](cls)
|
72
|
+
Access[cls].tap do |template|
|
73
|
+
template.SetCallHandler() do |arguments|
|
74
|
+
wrap = nil
|
75
|
+
if arguments.Length() > 0 && arguments[0].kind_of?(C::External)
|
76
|
+
wrap = arguments[0]
|
77
|
+
else
|
78
|
+
rbargs = []
|
79
|
+
for i in 0..arguments.Length() - 1
|
80
|
+
rbargs << To.rb(arguments[i])
|
81
|
+
end
|
82
|
+
instance = V8::Function.rubycall(cls.method(:new), *rbargs)
|
83
|
+
wrap = C::External::New(instance)
|
84
|
+
end
|
85
|
+
arguments.This().tap do |this|
|
86
|
+
this.SetHiddenValue(C::String::NewSymbol("TheRubyRacer::RubyObject"), wrap)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
4
93
|
class NamedPropertyGetter
|
5
94
|
def self.call(property, info)
|
6
95
|
name = To.rb(property)
|
@@ -41,7 +130,7 @@ module V8
|
|
41
130
|
end
|
42
131
|
end
|
43
132
|
end
|
44
|
-
|
133
|
+
|
45
134
|
class NamedPropertyEnumerator
|
46
135
|
def self.call(info)
|
47
136
|
obj = To.rb(info.This())
|
data/lib/v8/array.rb
CHANGED
data/lib/v8/context.rb
CHANGED
@@ -4,8 +4,11 @@ module V8
|
|
4
4
|
class Context
|
5
5
|
attr_reader :native, :scope
|
6
6
|
def initialize(opts = {})
|
7
|
-
@native = C::Context::New(
|
8
|
-
@
|
7
|
+
@native = opts[:with] ? C::Context::New(Access.rubyobject) : C::Context::New()
|
8
|
+
@native.enter do
|
9
|
+
@native.Global().SetHiddenValue(C::String::New("TheRubyRacer::RubyObject"), C::External::New(opts[:with])) if opts[:with]
|
10
|
+
@scope = To.rb(@native.Global())
|
11
|
+
end
|
9
12
|
yield(self) if block_given?
|
10
13
|
end
|
11
14
|
|
@@ -19,13 +22,13 @@ module V8
|
|
19
22
|
@native.enter do
|
20
23
|
script = C::Script::Compile(To.v8(javascript.to_s), To.v8(filename.to_s))
|
21
24
|
if try.HasCaught()
|
22
|
-
err =
|
25
|
+
err = JSError.new(try)
|
23
26
|
else
|
24
27
|
result = script.Run()
|
25
28
|
if try.HasCaught()
|
26
|
-
err =
|
29
|
+
err = JSError.new(try)
|
27
30
|
else
|
28
|
-
value = To.
|
31
|
+
value = To.rb(result)
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
@@ -60,25 +63,7 @@ module V8
|
|
60
63
|
V8::Context.eval(*args)
|
61
64
|
end
|
62
65
|
end
|
63
|
-
|
64
|
-
class JavascriptError < StandardError
|
65
|
-
attr_reader :source_name, :source_line, :line_number, :javascript_stacktrace
|
66
|
-
|
67
|
-
def initialize(try)
|
68
|
-
msg = try.Message()
|
69
|
-
@source_name = To.ruby(msg.GetScriptResourceName())
|
70
|
-
@source_line = To.ruby(msg.GetSourceLine())
|
71
|
-
@line_number = To.ruby(msg.GetLineNumber())
|
72
|
-
@javascript_stacktrace = To.ruby(try.StackTrace())
|
73
|
-
super("#{To.ruby(msg.Get())}: #{@source_name}:#{@line_number}")
|
74
|
-
end
|
75
|
-
|
76
|
-
def self.check(try)
|
77
|
-
raise JavascriptError.new(try) if try.HasCaught()
|
78
|
-
end
|
79
66
|
|
80
|
-
end
|
81
|
-
|
82
67
|
module C
|
83
68
|
class Context
|
84
69
|
def enter
|