therubyracer 0.4.3 → 0.4.4
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/History.txt +12 -1
- data/Manifest.txt +2 -0
- data/README.rdoc +4 -1
- data/ext/v8/converters.cpp +31 -18
- data/ext/v8/converters.h +2 -0
- data/ext/v8/extconf.rb +2 -0
- data/ext/v8/v8.cpp +10 -5
- data/ext/v8/v8_cxt.cpp +37 -2
- data/ext/v8/v8_cxt.h +4 -0
- data/ext/v8/v8_obj.cpp +7 -0
- data/ext/v8/v8_obj.h +1 -0
- data/ext/v8/v8_standalone.cpp +0 -1
- data/lib/v8.rb +1 -1
- data/lib/v8/context.rb +38 -12
- data/lib/v8/object.rb +14 -2
- data/spec/ext/cxt_spec.rb +25 -0
- data/spec/ext/obj_spec.rb +13 -0
- data/spec/redjs/jsapi_spec.rb +22 -49
- data/therubyracer.gemspec +3 -3
- metadata +4 -2
data/History.txt
CHANGED
@@ -1,5 +1,16 @@
|
|
1
|
+
=== 0.X.X 2010-01-14
|
2
|
+
* 2 major enhancements:
|
3
|
+
* Ruby objects embedded into javascript are passed back to ruby as themselves and not a wrapped V8 object wrapping a ruby object.
|
4
|
+
* Use any ruby object as the scope of eval().
|
5
|
+
* 5 minor enhancements:
|
6
|
+
* quick and dirty V8.eval() method added
|
7
|
+
* native objects have a reference to the context that created them.
|
8
|
+
* context now has equality check.
|
9
|
+
* expose InContext() and GetCurrent() methods.
|
10
|
+
* fix a couple of segmentation faults
|
11
|
+
|
1
12
|
=== 0.4.3 2010-10-11
|
2
|
-
*
|
13
|
+
* 3 major enhancements:
|
3
14
|
* access properties on Ruby objects with their camel case equivalents
|
4
15
|
* reflect JavaScript objects into Ruby and access their properties
|
5
16
|
* load JavaScript source from an IO object or by filename
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -20,6 +20,10 @@ Embed the V8 Javascript interpreter into Ruby.
|
|
20
20
|
|
21
21
|
# evaluate some simple javascript
|
22
22
|
|
23
|
+
V8.eval("7 * 6") #=> 42
|
24
|
+
|
25
|
+
# embed values into the scope of your context
|
26
|
+
|
23
27
|
V8::Context.open do |cxt|
|
24
28
|
cxt['foo'] = "bar"
|
25
29
|
cxt.eval('foo') # => "bar"
|
@@ -45,7 +49,6 @@ Embed the V8 Javascript interpreter into Ruby.
|
|
45
49
|
context.eval("math.plus(20,22)") #=> 42
|
46
50
|
end
|
47
51
|
|
48
|
-
#COMING SOON!
|
49
52
|
# make a ruby object *be* your javascript environment
|
50
53
|
math = MyMath.new
|
51
54
|
V8::Context.open(:with => math) do |context|
|
data/ext/v8/converters.cpp
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#include "callbacks.h"
|
3
3
|
#include "v8_ref.h"
|
4
4
|
#include "v8_obj.h"
|
5
|
+
#include "v8_cxt.h"
|
5
6
|
|
6
7
|
using namespace v8;
|
7
8
|
|
@@ -30,7 +31,14 @@ VALUE V82RB(Handle<Value>& value) {
|
|
30
31
|
|
31
32
|
if (value->IsObject()) {
|
32
33
|
Local<Object> object(Object::Cast(*value));
|
33
|
-
|
34
|
+
Local<Value> peer = object->GetHiddenValue(String::New("TheRubyRacer::RubyObject"));
|
35
|
+
if (peer.IsEmpty()) {
|
36
|
+
VALUE context_ref = V8_Ref_Create(V8_C_Context, Context::GetCurrent());
|
37
|
+
object->SetHiddenValue(String::New("TheRubyRacer::Context"), External::Wrap((void *)context_ref));
|
38
|
+
return V8_Ref_Create(V8_C_Object, value, context_ref);
|
39
|
+
} else {
|
40
|
+
return (VALUE)External::Unwrap(peer);
|
41
|
+
}
|
34
42
|
}
|
35
43
|
|
36
44
|
return Qnil;
|
@@ -38,7 +46,6 @@ VALUE V82RB(Handle<Value>& value) {
|
|
38
46
|
|
39
47
|
Local<Value> RB2V8(VALUE value) {
|
40
48
|
VALUE valueClass = rb_class_of(value);
|
41
|
-
|
42
49
|
if(valueClass == rb_cProc || valueClass == rb_cMethod) {
|
43
50
|
Local<FunctionTemplate> t = FunctionTemplate::New(RacerRubyInvocationCallback, External::Wrap((void *)value));
|
44
51
|
return t->GetFunction();
|
@@ -48,21 +55,10 @@ Local<Value> RB2V8(VALUE value) {
|
|
48
55
|
if (convert(value, result)) {
|
49
56
|
return result;
|
50
57
|
}
|
51
|
-
|
52
|
-
Local<
|
53
|
-
|
54
|
-
|
55
|
-
for (int i = 0; i < len; i++) {
|
56
|
-
VALUE method_name = RARRAY_PTR(methods)[i];
|
57
|
-
VALUE camel_method_name = rb_funcall(V8_To, rb_intern("camelcase"), 1, method_name);
|
58
|
-
VALUE method = rb_funcall(value, rb_intern("method"), 1, method_name);
|
59
|
-
Local<String> keystr = (String *)*RB2V8(method_name);
|
60
|
-
Local<String> camelstr = (String *)*RB2V8(camel_method_name);
|
61
|
-
Local<Value> fun = RB2V8(method);
|
62
|
-
tmpl->Set(keystr, fun);
|
63
|
-
tmpl->Set(camelstr, fun);
|
64
|
-
}
|
65
|
-
return tmpl->NewInstance();
|
58
|
+
Local<ObjectTemplate> tmpl = RB_VALUE_2_V8_ObjectTemplate(value);
|
59
|
+
Local<Object> object = tmpl->NewInstance();
|
60
|
+
object->SetHiddenValue(String::New("TheRubyRacer::RubyObject"), External::Wrap((void *)value));
|
61
|
+
return object;
|
66
62
|
}
|
67
63
|
|
68
64
|
std::string V82String(Handle<Value>& value) {
|
@@ -81,4 +77,21 @@ std::string V82String(Handle<Value>& value) {
|
|
81
77
|
}
|
82
78
|
|
83
79
|
return UNDEFINED_STR;
|
84
|
-
}
|
80
|
+
}
|
81
|
+
|
82
|
+
Local<ObjectTemplate> RB_VALUE_2_V8_ObjectTemplate(VALUE value) {
|
83
|
+
Local<ObjectTemplate> tmpl = ObjectTemplate::New();
|
84
|
+
VALUE methods = rb_funcall(value, rb_intern("public_methods"), 1, Qfalse);
|
85
|
+
int len = RARRAY_LEN(methods);
|
86
|
+
for (int i = 0; i < len; i++) {
|
87
|
+
VALUE method_name = RARRAY_PTR(methods)[i];
|
88
|
+
VALUE camel_method_name = rb_funcall(V8_To, rb_intern("camelcase"), 1, method_name);
|
89
|
+
VALUE method = rb_funcall(value, rb_intern("method"), 1, method_name);
|
90
|
+
Local<String> keystr = (String *)*RB2V8(method_name);
|
91
|
+
Local<String> camelstr = (String *)*RB2V8(camel_method_name);
|
92
|
+
Local<FunctionTemplate> fun = FunctionTemplate::New(RacerRubyInvocationCallback, External::Wrap((void *)method));
|
93
|
+
tmpl->Set(keystr, fun);
|
94
|
+
tmpl->Set(camelstr, fun);
|
95
|
+
}
|
96
|
+
return tmpl;
|
97
|
+
}
|
data/ext/v8/converters.h
CHANGED
data/ext/v8/extconf.rb
CHANGED
data/ext/v8/v8.cpp
CHANGED
@@ -37,11 +37,15 @@ extern "C" {
|
|
37
37
|
VALUE rb_mNative = rb_define_module_under(rb_mModule, "C");
|
38
38
|
|
39
39
|
//native context
|
40
|
-
|
41
|
-
rb_define_singleton_method(
|
42
|
-
|
43
|
-
|
44
|
-
rb_define_method(
|
40
|
+
V8_C_Context = rb_define_class_under(rb_mNative, "Context", rb_cObject);
|
41
|
+
rb_define_singleton_method(V8_C_Context, "new", (VALUE(*)(...)) v8_Context_New, -1);
|
42
|
+
rb_define_singleton_method(V8_C_Context, "InContext", (VALUE(*)(...)) v8_Context_InContext, 0);
|
43
|
+
rb_define_singleton_method(V8_C_Context, "GetCurrent", (VALUE(*)(...)) v8_Context_GetCurrent, 0);
|
44
|
+
rb_define_method(V8_C_Context, "Global", (VALUE(*)(...)) v8_cxt_Global, 0);
|
45
|
+
rb_define_method(V8_C_Context, "open", (VALUE(*)(...)) v8_cxt_open, 0);
|
46
|
+
rb_define_method(V8_C_Context, "eval", (VALUE(*)(...)) v8_cxt_eval, 1);
|
47
|
+
rb_define_method(V8_C_Context, "eql?", (VALUE(*)(...)) v8_cxt_eql, 1);
|
48
|
+
rb_define_method(V8_C_Context, "==", (VALUE(*)(...)) v8_cxt_eql, 1);
|
45
49
|
|
46
50
|
//native String
|
47
51
|
VALUE V8__C__String = rb_define_class_under(rb_mNative, "String", rb_cObject);
|
@@ -67,6 +71,7 @@ extern "C" {
|
|
67
71
|
rb_define_method(V8_C_Object, "Get", (VALUE(*)(...))v8_Object_Get, 1);
|
68
72
|
rb_define_method(V8_C_Object, "Set", (VALUE(*)(...))v8_Object_Set, 2);
|
69
73
|
rb_define_method(V8_C_Object, "GetPropertyNames", (VALUE(*)(...)) v8_Object_GetPropertyNames, 0);
|
74
|
+
rb_define_method(V8_C_Object, "context", (VALUE(*)(...)) v8_Object_context, 0);
|
70
75
|
|
71
76
|
V8_C_Message = rb_define_class_under(rb_mNative, "Message", rb_cObject);
|
72
77
|
rb_define_method(V8_C_Message, "Get", (VALUE(*)(...))v8_Message_Get, 0);
|
data/ext/v8/v8_cxt.cpp
CHANGED
@@ -4,6 +4,11 @@
|
|
4
4
|
|
5
5
|
using namespace v8;
|
6
6
|
|
7
|
+
VALUE V8_C_Context;
|
8
|
+
|
9
|
+
//TODO: rename everything to Context_
|
10
|
+
//TODO: do the object init from within here
|
11
|
+
|
7
12
|
VALUE v8_Context_New(int argc, VALUE *argv, VALUE self) {
|
8
13
|
HandleScope handles;
|
9
14
|
VALUE scope;
|
@@ -11,8 +16,26 @@ VALUE v8_Context_New(int argc, VALUE *argv, VALUE self) {
|
|
11
16
|
if (NIL_P(scope)) {
|
12
17
|
return V8_Ref_Create(self, Context::New());
|
13
18
|
} else {
|
14
|
-
|
15
|
-
|
19
|
+
Persistent<Context> context = Context::New(0, RB_VALUE_2_V8_ObjectTemplate(scope));
|
20
|
+
Context::Scope enter(context);
|
21
|
+
context->Global()->SetHiddenValue(String::New("TheRubyRacer::RubyObject"), External::Wrap((void *)scope));
|
22
|
+
VALUE ref = V8_Ref_Create(self, context, scope);
|
23
|
+
context.Dispose();
|
24
|
+
return ref;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE v8_Context_InContext(VALUE self) {
|
29
|
+
return Context::InContext() ? Qtrue : Qfalse;
|
30
|
+
}
|
31
|
+
|
32
|
+
VALUE v8_Context_GetCurrent(VALUE self) {
|
33
|
+
HandleScope handles;
|
34
|
+
if (Context::InContext()) {
|
35
|
+
Local<Context> current = Context::GetCurrent();
|
36
|
+
return V8_Ref_Create(self, current);
|
37
|
+
} else {
|
38
|
+
return Qnil;
|
16
39
|
}
|
17
40
|
}
|
18
41
|
|
@@ -49,4 +72,16 @@ VALUE v8_cxt_eval(VALUE self, VALUE source) {
|
|
49
72
|
}
|
50
73
|
}
|
51
74
|
|
75
|
+
VALUE v8_cxt_eql(VALUE self, VALUE other) {
|
76
|
+
HandleScope handles;
|
77
|
+
if (RTEST(CLASS_OF(other) != V8_C_Context)) {
|
78
|
+
return Qnil;
|
79
|
+
} else {
|
80
|
+
Local<Context> cxt = V8_Ref_Get<Context>(self);
|
81
|
+
Local<Context> that = V8_Ref_Get<Context>(other);
|
82
|
+
return cxt == that ? Qtrue : Qfalse;
|
83
|
+
}
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
|
52
87
|
|
data/ext/v8/v8_cxt.h
CHANGED
@@ -7,10 +7,14 @@
|
|
7
7
|
|
8
8
|
extern VALUE rb_cV8;
|
9
9
|
extern VALUE V8_C_Object;
|
10
|
+
extern VALUE V8_C_Context;
|
10
11
|
|
11
12
|
VALUE v8_Context_New(int argc, VALUE *argv, VALUE self);
|
13
|
+
VALUE v8_Context_InContext(VALUE self);
|
14
|
+
VALUE v8_Context_GetCurrent(VALUE self);
|
12
15
|
VALUE v8_cxt_Global(VALUE self);
|
13
16
|
VALUE v8_cxt_open(VALUE self);
|
14
17
|
VALUE v8_cxt_eval(VALUE self, VALUE source);
|
18
|
+
VALUE v8_cxt_eql(VALUE self, VALUE other);
|
15
19
|
|
16
20
|
#endif
|
data/ext/v8/v8_obj.cpp
CHANGED
@@ -42,3 +42,10 @@ VALUE v8_Object_GetPropertyNames(VALUE self) {
|
|
42
42
|
Local<Value> names = object->GetPropertyNames();
|
43
43
|
return V82RB(names);
|
44
44
|
}
|
45
|
+
|
46
|
+
VALUE v8_Object_context(VALUE self) {
|
47
|
+
HandleScope handles;
|
48
|
+
Local<Object> object = unwrap(self);
|
49
|
+
Local<Value> cxt = object->GetHiddenValue(String::New("TheRubyRacer::Context"));
|
50
|
+
return cxt.IsEmpty() ? Qnil : (VALUE)External::Unwrap(cxt);
|
51
|
+
}
|
data/ext/v8/v8_obj.h
CHANGED
data/ext/v8/v8_standalone.cpp
CHANGED
data/lib/v8.rb
CHANGED
data/lib/v8/context.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
|
-
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
module V8
|
2
4
|
class Context
|
3
|
-
def initialize
|
4
|
-
@native = C::Context.new
|
5
|
+
def initialize(opts = {})
|
6
|
+
@native = C::Context.new(opts[:with])
|
5
7
|
end
|
6
8
|
|
7
9
|
def open(&block)
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
if block_given?
|
11
|
+
unless @native == C::Context::GetCurrent()
|
12
|
+
@native.open do
|
13
|
+
block.call(self)
|
14
|
+
end
|
15
|
+
else
|
16
|
+
block.call(self)
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
def eval(javascript, sourcename = '<eval>', line = 1)
|
@@ -31,23 +39,41 @@ module V8
|
|
31
39
|
end
|
32
40
|
|
33
41
|
def [](key)
|
34
|
-
|
42
|
+
open do
|
43
|
+
To.ruby(@native.Global().Get(key.to_s))
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
47
|
def []=(key, value)
|
38
48
|
value.tap do
|
39
|
-
|
40
|
-
|
49
|
+
open do
|
50
|
+
@native.Global().tap do |scope|
|
51
|
+
scope.Set(key.to_s, value)
|
52
|
+
end
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
44
56
|
|
45
|
-
def self.open(&block)
|
46
|
-
new.open(&block)
|
47
|
-
end
|
57
|
+
def self.open(opts = {}, &block)
|
58
|
+
new(opts).open(&block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.eval(source)
|
62
|
+
new.eval(source)
|
63
|
+
end
|
64
|
+
|
65
|
+
def V8.eval(*args)
|
66
|
+
V8::Context.eval(*args)
|
67
|
+
end
|
48
68
|
end
|
49
69
|
|
50
70
|
class ContextError < StandardError
|
71
|
+
def initialize(caller_name)
|
72
|
+
super("tried to call method '#{caller_name} without an open context")
|
73
|
+
end
|
74
|
+
def self.check_open(caller_name)
|
75
|
+
raise new(caller_name) unless C::Context::InContext()
|
76
|
+
end
|
51
77
|
end
|
52
78
|
class JavascriptError < StandardError
|
53
79
|
def initialize(v8_message)
|
data/lib/v8/object.rb
CHANGED
@@ -8,12 +8,16 @@ module V8
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def [](key)
|
11
|
-
|
11
|
+
@native.context.open do
|
12
|
+
To.ruby(@native.Get(key.to_s))
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
def []=(key, value)
|
15
17
|
value.tap do
|
16
|
-
@native.
|
18
|
+
@native.context.open do
|
19
|
+
@native.Set(key.to_s, value)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
@@ -23,4 +27,12 @@ module V8
|
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Object
|
33
|
+
def eval_js(javascript)
|
34
|
+
V8::Context.open(:with => self) do |cxt|
|
35
|
+
cxt.eval(javascript)
|
36
|
+
end
|
37
|
+
end
|
26
38
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
require "#{File.dirname(__FILE__)}/../spec_helper.rb"
|
3
|
+
|
4
|
+
include V8
|
5
|
+
|
6
|
+
describe C::Context do
|
7
|
+
|
8
|
+
it "should not have a current context if no context is open" do
|
9
|
+
C::Context::GetCurrent().should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "can determine if there is a current context" do
|
13
|
+
C::Context::InContext().should be(false)
|
14
|
+
C::Context.new.open do |cxt|
|
15
|
+
C::Context::InContext().should be(true)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns the currently open context" do
|
20
|
+
C::Context.new.open do |cxt|
|
21
|
+
cxt.should be_eql(C::Context::GetCurrent())
|
22
|
+
cxt.should == C::Context::GetCurrent()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../spec_helper.rb"
|
2
|
+
|
3
|
+
include V8
|
4
|
+
|
5
|
+
describe C::Object do
|
6
|
+
it "has a reference to its calling context" do
|
7
|
+
C::Context.new.open do |cxt|
|
8
|
+
o = cxt.eval('new Object()');
|
9
|
+
o.context.should == cxt
|
10
|
+
o.context.should be_eql(cxt)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/spec/redjs/jsapi_spec.rb
CHANGED
@@ -4,44 +4,36 @@ describe "Ruby Javascript API" do
|
|
4
4
|
|
5
5
|
describe "Basic Evaluation" do
|
6
6
|
it "can evaluate some javascript" do
|
7
|
-
Context.
|
8
|
-
cxt.eval("5 + 3").should == 8
|
9
|
-
end
|
7
|
+
Context.eval("5 + 3")
|
10
8
|
end
|
11
9
|
|
12
10
|
it "can pass back null to ruby" do
|
13
|
-
Context.
|
14
|
-
cxt.eval("null").should be_nil
|
15
|
-
end
|
11
|
+
Context.eval("null").should be_nil
|
16
12
|
end
|
17
13
|
|
18
14
|
it "can pass back undefined to ruby" do
|
19
|
-
Context.
|
20
|
-
cxt.eval("this.undefined").should be_nil
|
21
|
-
end
|
15
|
+
Context.eval("this.undefined").should be_nil
|
22
16
|
end
|
23
17
|
|
24
18
|
it "can pass the empty string back to ruby" do
|
25
|
-
eval("''").should == ""
|
19
|
+
Context.eval("''").should == ""
|
26
20
|
end
|
27
21
|
|
28
22
|
it "can pass doubles back to ruby" do
|
29
|
-
eval("2.5").should == 2.5
|
23
|
+
Context.eval("2.5").should == 2.5
|
30
24
|
end
|
31
25
|
|
32
26
|
it "can pass fixed numbers back to ruby" do
|
33
|
-
eval("1").should == 1
|
27
|
+
Context.eval("1").should == 1
|
34
28
|
end
|
35
29
|
|
36
30
|
it "can pass boolean values back to ruby" do
|
37
|
-
eval("true").should be(true)
|
38
|
-
eval("false").should be(false)
|
31
|
+
Context.eval("true").should be(true)
|
32
|
+
Context.eval("false").should be(false)
|
39
33
|
end
|
40
34
|
|
41
35
|
it "treats nil and the empty string as the same thing when it comes to eval" do
|
42
|
-
Context.
|
43
|
-
cxt.eval(nil).should == cxt.eval('')
|
44
|
-
end
|
36
|
+
Context.eval(nil).should == Context.eval('')
|
45
37
|
end
|
46
38
|
|
47
39
|
it "can pass back strings to ruby" do
|
@@ -74,21 +66,13 @@ describe "Ruby Javascript API" do
|
|
74
66
|
end
|
75
67
|
|
76
68
|
it "unwraps ruby objects returned by embedded ruby code to maintain referential integrity" do
|
77
|
-
|
78
|
-
mock(:object).tap do |o|
|
69
|
+
Object.new.tap do |o|
|
79
70
|
Context.open do |cxt|
|
80
71
|
cxt['get'] = lambda {o}
|
81
72
|
cxt.eval('get()').should be(o)
|
82
73
|
end
|
83
74
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
it "won't let you do some operations unless the context is open" do
|
87
|
-
pending "I'm not sure about this requirement"
|
88
|
-
Context.new.tap do |closed|
|
89
|
-
lambda {closed.eval('1')}.should raise_error(ContextError)
|
90
|
-
end
|
91
|
-
end
|
75
|
+
end
|
92
76
|
end
|
93
77
|
|
94
78
|
describe "Calling Ruby Code From Within Javascript" do
|
@@ -222,7 +206,7 @@ describe "Ruby Javascript API" do
|
|
222
206
|
|
223
207
|
new
|
224
208
|
end
|
225
|
-
|
209
|
+
|
226
210
|
Context.open(:with => scope) do |cxt|
|
227
211
|
cxt.eval("plus(1,2)").should == 3
|
228
212
|
cxt.eval("minus(10, 20)").should == -10
|
@@ -244,8 +228,7 @@ describe "Ruby Javascript API" do
|
|
244
228
|
cxt.eval('falls').should be(false)
|
245
229
|
end
|
246
230
|
end
|
247
|
-
|
248
|
-
|
231
|
+
|
249
232
|
it "extends object to allow for the arbitrary execution of javascript with any object as the scope" do
|
250
233
|
Class.new.class_eval do
|
251
234
|
|
@@ -270,13 +253,7 @@ describe "Ruby Javascript API" do
|
|
270
253
|
end
|
271
254
|
end
|
272
255
|
}.should raise_error(RunawayScriptError)
|
273
|
-
end
|
274
|
-
|
275
|
-
it "has a private constructor" do
|
276
|
-
lambda {
|
277
|
-
Context.new(nil)
|
278
|
-
}.should raise_error
|
279
|
-
end
|
256
|
+
end
|
280
257
|
end
|
281
258
|
|
282
259
|
describe "loading javascript source into the interpreter" do
|
@@ -330,21 +307,17 @@ describe "Ruby Javascript API" do
|
|
330
307
|
end
|
331
308
|
|
332
309
|
it "can have its properties manipulated via ruby style [] hash access" do
|
333
|
-
@
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
@o["blue"].should == "blam"
|
338
|
-
end
|
310
|
+
@o["foo"] = 'bar'
|
311
|
+
evaljs('o.foo').should == "bar"
|
312
|
+
evaljs('o.blue = "blam"')
|
313
|
+
@o["blue"].should == "blam"
|
339
314
|
end
|
340
315
|
|
341
316
|
it "doesn't matter if you use a symbol or a string to set a value" do
|
342
|
-
@
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
@o[:baz].should == "bang"
|
347
|
-
end
|
317
|
+
@o[:foo] = "bar"
|
318
|
+
@o['foo'].should == "bar"
|
319
|
+
@o['baz'] = "bang"
|
320
|
+
@o[:baz].should == "bang"
|
348
321
|
end
|
349
322
|
|
350
323
|
it "returns nil when the value is null, null, or not defined" do
|
data/therubyracer.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{therubyracer}
|
5
|
-
s.version = "0.4.
|
5
|
+
s.version = "0.4.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Charles Lowell", "Bill Robertson"]
|
9
|
-
s.date = %q{2010-01-
|
9
|
+
s.date = %q{2010-01-14}
|
10
10
|
s.description = %q{Embed the V8 Javascript interpreter into Ruby.}
|
11
11
|
s.email = ["cowboyd@thefrontside.net", "billrobertson42@gmail.com"]
|
12
12
|
s.extensions = ["ext/v8/extconf.rb"]
|
13
13
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "docs/data_conversion.txt"]
|
14
|
-
s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "docs/data_conversion.txt", "ext/v8/callbacks.cpp", "ext/v8/callbacks.h", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.cpp", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_func.cpp", "ext/v8/v8_func.h", "ext/v8/v8_msg.cpp", "ext/v8/v8_msg.h", "ext/v8/v8_obj.cpp", "ext/v8/v8_obj.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/context.rb", "lib/v8/object.rb", "lib/v8/to.rb", "script/console", "script/destroy", "script/generate", "spec/redjs/README.txt", "spec/redjs/jsapi_spec.rb", "spec/redjs_helper.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "therubyracer.gemspec"]
|
14
|
+
s.files = ["Doxyfile", "History.txt", "Manifest.txt", "README.rdoc", "Rakefile", "docs/data_conversion.txt", "ext/v8/callbacks.cpp", "ext/v8/callbacks.h", "ext/v8/convert_ruby.cpp", "ext/v8/convert_ruby.h", "ext/v8/convert_string.cpp", "ext/v8/convert_string.h", "ext/v8/convert_v8.cpp", "ext/v8/convert_v8.h", "ext/v8/converters.cpp", "ext/v8/converters.h", "ext/v8/extconf.rb", "ext/v8/v8.cpp", "ext/v8/v8_cxt.cpp", "ext/v8/v8_cxt.h", "ext/v8/v8_func.cpp", "ext/v8/v8_func.h", "ext/v8/v8_msg.cpp", "ext/v8/v8_msg.h", "ext/v8/v8_obj.cpp", "ext/v8/v8_obj.h", "ext/v8/v8_ref.cpp", "ext/v8/v8_ref.h", "ext/v8/v8_script.cpp", "ext/v8/v8_script.h", "ext/v8/v8_standalone.cpp", "ext/v8/v8_standalone.h", "ext/v8/v8_str.cpp", "ext/v8/v8_str.h", "ext/v8/v8_template.cpp", "ext/v8/v8_template.h", "lib/v8.rb", "lib/v8/context.rb", "lib/v8/object.rb", "lib/v8/to.rb", "script/console", "script/destroy", "script/generate", "spec/ext/cxt_spec.rb", "spec/ext/obj_spec.rb", "spec/redjs/README.txt", "spec/redjs/jsapi_spec.rb", "spec/redjs_helper.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/rspec.rake", "therubyracer.gemspec"]
|
15
15
|
s.homepage = %q{http://github.com/cowboyd/therubyracer}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
17
17
|
s.require_paths = ["lib", "ext"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: therubyracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Lowell
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-14 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- script/console
|
80
80
|
- script/destroy
|
81
81
|
- script/generate
|
82
|
+
- spec/ext/cxt_spec.rb
|
83
|
+
- spec/ext/obj_spec.rb
|
82
84
|
- spec/redjs/README.txt
|
83
85
|
- spec/redjs/jsapi_spec.rb
|
84
86
|
- spec/redjs_helper.rb
|