therubyracer 0.8.2 → 0.9.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 (53) hide show
  1. data/Changelog.md +1 -1
  2. data/ext/v8/rr.cpp +14 -7
  3. data/ext/v8/rr.h +1 -0
  4. data/ext/v8/v8.cpp +27 -25
  5. data/ext/v8/v8_array.cpp +7 -9
  6. data/ext/v8/v8_callbacks.cpp +1 -1
  7. data/ext/v8/{v8_cxt.cpp → v8_context.cpp} +11 -11
  8. data/ext/v8/{v8_cxt.h → v8_context.h} +1 -1
  9. data/ext/v8/v8_date.cpp +6 -6
  10. data/ext/v8/v8_exception.cpp +10 -11
  11. data/ext/v8/v8_external.cpp +7 -24
  12. data/ext/v8/v8_external.h +0 -1
  13. data/ext/v8/{v8_func.cpp → v8_function.cpp} +14 -14
  14. data/ext/v8/{v8_func.h → v8_function.h} +1 -2
  15. data/ext/v8/v8_handle.cpp +119 -0
  16. data/ext/v8/v8_handle.h +27 -0
  17. data/ext/v8/{v8_msg.cpp → v8_message.cpp} +8 -9
  18. data/ext/v8/{v8_msg.h → v8_message.h} +1 -1
  19. data/ext/v8/{v8_obj.cpp → v8_object.cpp} +51 -29
  20. data/ext/v8/{v8_obj.h → v8_object.h} +3 -4
  21. data/ext/v8/v8_script.cpp +5 -5
  22. data/ext/v8/{v8_str.cpp → v8_string.cpp} +9 -11
  23. data/ext/v8/{v8_str.h → v8_string.h} +1 -1
  24. data/ext/v8/v8_template.cpp +113 -98
  25. data/ext/v8/v8_try_catch.cpp +1 -1
  26. data/ext/v8/v8_v8.cpp +7 -0
  27. data/ext/v8/v8_value.cpp +44 -36
  28. data/ext/v8/v8_value.h +2 -2
  29. data/ext/v8/v8_weakref.cpp +51 -0
  30. data/ext/v8/v8_weakref.h +30 -0
  31. data/lib/v8.rb +6 -1
  32. data/lib/v8/context.rb +13 -3
  33. data/lib/v8/error.rb +1 -1
  34. data/lib/v8/portal.rb +26 -277
  35. data/lib/v8/portal/caller.rb +36 -0
  36. data/lib/v8/portal/constructor.rb +98 -0
  37. data/lib/v8/portal/function.rb +48 -0
  38. data/lib/v8/portal/interceptors.rb +153 -0
  39. data/lib/v8/portal/proxies.rb +102 -0
  40. data/lib/v8/portal/templates.rb +73 -0
  41. data/lib/v8/version.rb +1 -1
  42. data/spec/ext/array_spec.rb +15 -0
  43. data/spec/ext/cxt_spec.rb +4 -4
  44. data/spec/ext/ext_spec_helper.rb +43 -0
  45. data/spec/ext/mem_spec.rb +42 -0
  46. data/spec/ext/object_spec.rb +22 -0
  47. data/spec/redjs/jsapi_spec.rb +4 -4
  48. data/spec/spec_helper.rb +1 -1
  49. data/spec/v8/portal/proxies_spec.rb +189 -0
  50. metadata +38 -42
  51. data/ext/v8/v8_ref.cpp +0 -37
  52. data/ext/v8/v8_ref.h +0 -28
  53. data/lib/v8/portal/functions.rb +0 -45
@@ -1,3 +1,3 @@
1
1
  module V8
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0beta1"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe V8::C::Array do
4
+ include V8::ExtSpec
5
+
6
+ it "can be instantiated" do
7
+ a = c::Array::New()
8
+ a.Length().should eql(0)
9
+ end
10
+
11
+ it "maintains referential integrity" do
12
+ v8_eval('a = []')
13
+ v8_eval('a').should be(v8_eval('a'))
14
+ end
15
+ end
@@ -11,10 +11,11 @@ describe C::Context do
11
11
 
12
12
  it "can get the current javascript execution stack" do
13
13
  V8::Context.new do |cxt|
14
+ trace = nil
14
15
  cxt['getTrace'] = lambda do
15
- V8::Context.stack
16
+ trace = V8::Context.stack
16
17
  end
17
- trace = cxt.eval(<<-JS, 'trace.js')
18
+ cxt.eval(<<-JS, 'trace.js')
18
19
  function one() {
19
20
  return two();
20
21
  }
@@ -28,9 +29,8 @@ describe C::Context do
28
29
  }
29
30
  one();
30
31
  JS
31
-
32
32
  trace.length.should be(4)
33
- trace.first.tap do |frame|
33
+ trace.to_a[0].tap do |frame|
34
34
  frame.line_number.should == 10
35
35
  frame.column.should == 16
36
36
  frame.script_name.should == 'trace.js'
@@ -0,0 +1,43 @@
1
+
2
+ module V8::ExtSpec
3
+
4
+ def self.included(object)
5
+ object.class_eval do
6
+ before(:all) {c::V8::SetFlagsFromString("--expose-gc")}
7
+ before do
8
+ @cxt = c::Context::New()
9
+ @cxt.Enter()
10
+ end
11
+ after do
12
+ @cxt.Exit()
13
+ @cxt.Dispose()
14
+ end
15
+ end
16
+ end
17
+
18
+ def v8_eval(script, sourcename = "<eval>")
19
+ c::Script::New(c::String::New(script), c::String::New(sourcename)).Run()
20
+ end
21
+
22
+ def c
23
+ V8::C
24
+ end
25
+
26
+ def ruby_gc
27
+ if GC.respond_to?(:stress)
28
+ current = GC.stress
29
+ GC.stress = true
30
+ end
31
+ yield
32
+ ensure
33
+ if GC.respond_to?(:stess)
34
+ GC.stress = current
35
+ end
36
+ end
37
+
38
+ def v8_gc
39
+ while !c::V8::IdleNotification();end
40
+ v8_eval('gc()', 'gc.js')
41
+ end
42
+
43
+ end
@@ -0,0 +1,42 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ describe "Memory:" do
5
+ include V8::ExtSpec
6
+ context "A JavaScript Object reflected into Ruby" do
7
+
8
+ before do
9
+ @weakref_callback = WeakrefCallback.new
10
+ end
11
+
12
+ it "has a strong reference from the ruby side, which is not released until the Ruby reference goes away" do
13
+ handle = c::Handle::New(object = c::Object::New())
14
+ handle.MakeWeak(nil, @weakref_callback)
15
+ ruby_gc do
16
+ v8_gc
17
+ @weakref_callback.should_not have_been_invoked
18
+ handle.should_not be_dead
19
+ end
20
+ ruby_gc do
21
+ object = nil
22
+ v8_gc
23
+ @weakref_callback.should have_been_invoked
24
+ handle.should be_dead
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ class WeakrefCallback
31
+
32
+ def call(value, parameters)
33
+ @invoked = true
34
+ end
35
+
36
+ def has_been_invoked?
37
+ @invoked
38
+ end
39
+ end
40
+ end
41
+ #These don't work in 1.8.7. Can't determine why not. I'll probably have to come back to this.
42
+ end if RUBY_VERSION >= '1.9.2'
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::C::Object do
4
+ include V8::ExtSpec
5
+
6
+ it "always returns a copy of the same object if it is the same object" do
7
+ v8_eval('var o = new Object()')
8
+ v8_eval('o').should be(v8_eval('o'))
9
+ end
10
+
11
+ it "will return a new peer and not barf if the old peer has been garbage collected" do
12
+ v8_eval('var o = {foo: "bar"}')
13
+ o = v8_eval('o')
14
+ old_id = o.object_id
15
+ ruby_gc do
16
+ o = nil
17
+ v8_eval('o').Get(c::String::New("foo")).Utf8Value().should == "bar"
18
+ v8_eval('o').object_id.should_not be(old_id)
19
+ end
20
+ #can't quite get this to work in 1.8. I'm questioning if it's worth the effort
21
+ end if RUBY_VERSION >= "1.9.2"
22
+ end
@@ -93,9 +93,9 @@ describe "Ruby Javascript API" do
93
93
 
94
94
  it "always returns the same ruby object for a single javascript object" do
95
95
  obj = @cxt.eval('obj = {}')
96
- obj.should be @cxt['obj']
97
- @cxt.eval('obj').should be @cxt['obj']
98
- @cxt['obj'].should be @cxt['obj']
96
+ obj.should be(@cxt['obj'])
97
+ @cxt.eval('obj').should be(@cxt['obj'])
98
+ @cxt['obj'].should be(@cxt['obj'])
99
99
  end
100
100
 
101
101
  it "converts arrays to javascript" do
@@ -618,7 +618,7 @@ describe "Ruby Javascript API" do
618
618
  obj.str = "baz"
619
619
  obj.str.should == "baz"
620
620
  obj.double = proc {|i| i * 2}
621
- obj.double(2).should == 4
621
+ obj.double.call(2).should == 4
622
622
  obj.array = 1,2,3
623
623
  obj.array.to_a.should == [1,2,3]
624
624
  obj.array = [1,2,3]
@@ -1,7 +1,7 @@
1
1
 
2
2
  require 'v8'
3
-
4
3
  require 'erb'
4
+ require Pathname(__FILE__).dirname.join('ext/ext_spec_helper')
5
5
  def rputs(msg)
6
6
  puts "<pre>#{ERB::Util.h(msg)}</pre>"
7
7
  $stdout.flush
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ describe V8::Portal::Proxies do
4
+ include V8::ExtSpec
5
+ # include V8::MemSpec
6
+
7
+ context "for Ruby objects which are embedded into javascript" do
8
+
9
+ it "allows you to resolve the Ruby object's JavaScript proxy" do
10
+ js_proxy = c::Object::New()
11
+ rb_object = Object.new
12
+ subject.register_javascript_proxy js_proxy, :for => rb_object
13
+ subject.rb_object_2_js_proxy(rb_object).should be(js_proxy)
14
+ subject.js_proxy_2_rb_object(js_proxy).should be(rb_object)
15
+ end
16
+
17
+ it "requires a Ruby object which is the actual object that is proxied" do
18
+ expect {subject.register_javascript_proxy c::Object::New()}.should raise_error(ArgumentError)
19
+ end
20
+
21
+ it "can only register proxies which are low-level JavaScript objects" do
22
+ expect {subject.register_javascript_proxy Object.new, :for => Object.new}.should raise_error(ArgumentError)
23
+ end
24
+
25
+ it "is only allowed to have a single JavaScript proxy" do
26
+ rb_object = Object.new
27
+ subject.register_javascript_proxy c::Object::New(), :for => rb_object
28
+ expect {subject.register_javascript_proxy c::Object::New(), :for => rb_object}.should raise_error(V8::Portal::Proxies::DoubleProxyError)
29
+ end
30
+
31
+ context "Memory Management" do
32
+ it "holds a hard reference to any ruby object which is linked to a javascript proxy" do
33
+ rb_object = Object.new
34
+ check_not_finalized(rb_object)
35
+ subject.register_javascript_proxy c::Object::New(), :for => rb_object
36
+ rb_object = nil
37
+ end
38
+
39
+ it "releases the hard reference if its corresponding javascript object has been garbage collected" do
40
+ rb_object = Object.new
41
+ js_proxy = c::Object::New()
42
+ check_finalized(rb_object)
43
+ subject.register_javascript_proxy js_proxy, :for => rb_object
44
+ rb_object = nil
45
+ ruby_gc do
46
+ v8_gc()
47
+ end
48
+ end
49
+ end if RUBY_VERSION >= "1.9.2"
50
+ end
51
+
52
+ context "for a JavaScript objects which are embedded into Ruby" do
53
+
54
+ it "allows you to resolve the JavaScript object's Ruby proxy" do
55
+ rb_proxy = Object.new
56
+ js_object = c::Object::New()
57
+ subject.register_ruby_proxy rb_proxy, :for => js_object
58
+ subject.js_object_2_rb_proxy(js_object).should be(rb_proxy)
59
+ subject.rb_proxy_2_js_object(rb_proxy).should be(js_object)
60
+ end
61
+
62
+ it "requires a JavaScript low level javascript object as the actual object that is proxied" do
63
+ expect {subject.register_javascript_proxy Object.new, :for => c::Object::New()}.should raise_error(ArgumentError)
64
+ end
65
+
66
+ it "will not a proxy twice if the proxy creator block actually registers the proxy inside it" do
67
+ target = Object.new
68
+ proxy = c::Object::New()
69
+ expect {subject.rb2js(target) do |object|
70
+ subject.register_javascript_proxy(proxy, :for => object)
71
+ c::Object::New()
72
+ end}.should_not raise_error
73
+ subject.rb2js(target).should be(proxy)
74
+ end
75
+
76
+ context "Memory Management" do
77
+
78
+ it "holds a hard reference to any JavaScript object which is linked to a Ruby proxy" do
79
+ js_object = c::Object::New()
80
+ check_not_finalized(js_object)
81
+ subject.register_ruby_proxy Object.new, :for => js_object
82
+ js_object = nil
83
+ end
84
+
85
+ it "clears any strong references to the JavaScript object when it's Ruby proxy is garbage collected" do
86
+ js_object = c::Object::New()
87
+ rb_proxy = Object.new
88
+ subject.register_ruby_proxy rb_proxy, :for => js_object
89
+ check_finalized(js_object)
90
+ js_object = rb_proxy = nil
91
+ ruby_gc do
92
+ v8_gc
93
+ end
94
+ end
95
+ end if RUBY_VERSION >= "1.9.2"
96
+
97
+ context "looking up a Ruby object from a random JavaScript object" do
98
+ it "checks first if it's a native Ruby object with a javascript proxy" do
99
+ target = Object.new
100
+ proxy = c::Object::New()
101
+ subject.register_javascript_proxy proxy, :for => target
102
+ subject.js2rb(proxy).should be(target)
103
+ end
104
+ it "then sees if maybe it's a native JavaScript that has a Ruby proxy" do
105
+ target = c::Object::New()
106
+ proxy = Object.new
107
+ subject.register_ruby_proxy proxy, :for => target
108
+ subject.js2rb(target).should be(proxy)
109
+ end
110
+ it "will assume that it is a native JavaScript object that needs a Ruby proxy if no corresponding Ruby object can be found" do
111
+ js = c::Object::New()
112
+ proxy = subject.js2rb(js) do |target|
113
+ {:target => target}
114
+ end
115
+ subject.js2rb(js).should be(proxy)
116
+ end
117
+ end
118
+
119
+ context "looking up a JavaScript object from a random Ruby object" do
120
+ it "checks first if it's a native JavaScript object with a Ruby proxy" do
121
+ target = c::Object::New()
122
+ proxy = Object.new
123
+ subject.register_ruby_proxy proxy, :for => target
124
+ subject.rb2js(proxy).should be(target)
125
+ end
126
+
127
+ it "then sees if maybe it's a native Ruby object that has a JavaScript proxy" do
128
+ target = Object.new
129
+ proxy = c::Object::New()
130
+ subject.register_javascript_proxy proxy, :for => target
131
+ subject.rb2js(target).should be(proxy)
132
+ end
133
+
134
+ it "assumes that it is a native Ruby object that needs a JavaScript proxy if no corresponding JavaScript object can be found" do
135
+ rb = Object.new
136
+ proxy = nil
137
+ js = subject.rb2js(rb) do |target|
138
+ target.should be(rb)
139
+ proxy = c::Object::New()
140
+ end
141
+ proxy.should_not be_nil
142
+ js.should be(proxy)
143
+ subject.rb2js(rb).should be(proxy)
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ private
150
+
151
+ def finalize(object_id)
152
+ @finalized ||= {}
153
+ @finalized[object_id] = true
154
+ end
155
+
156
+ def check_finalized(object)
157
+ @finalized ||= {}
158
+ ObjectSpace.define_finalizer(object, method(:finalize))
159
+ id_to_check = object.object_id
160
+ object = nil
161
+ afterwards do
162
+ @finalized[id_to_check].should be_true
163
+ end
164
+ end
165
+
166
+ def check_not_finalized(object)
167
+ @finalized ||= {}
168
+ ObjectSpace.define_finalizer(object, method(:finalize))
169
+ id_to_check = object.object_id
170
+ object = nil
171
+ afterwards do
172
+ @finalized[id_to_check].should be_false
173
+ end
174
+ end
175
+
176
+ def afterwards(&block)
177
+ @after ||= []
178
+ @after << block if block_given?
179
+ end
180
+
181
+ after do
182
+ ruby_gc do
183
+ @after.each do |proc|
184
+ proc.call
185
+ end if @after
186
+ end
187
+ end if RUBY_VERSION >= '1.9.2'
188
+
189
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therubyracer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 59
5
- prerelease:
6
- segments:
7
- - 0
8
- - 8
9
- - 2
10
- version: 0.8.2
4
+ prerelease: 5
5
+ version: 0.9.0beta1
11
6
  platform: ruby
12
7
  authors:
13
8
  - Charles Lowell
@@ -16,39 +11,31 @@ autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
13
 
19
- date: 2011-05-25 00:00:00 -05:00
14
+ date: 2011-05-03 00:00:00 -05:00
20
15
  default_executable:
21
16
  dependencies:
22
17
  - !ruby/object:Gem::Dependency
23
- type: :development
18
+ name: rspec
24
19
  requirement: &id001 !ruby/object:Gem::Requirement
25
20
  none: false
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 15
30
- segments:
31
- - 2
32
- - 0
33
- - 0
34
24
  version: 2.0.0
35
- version_requirements: *id001
36
- name: rspec
25
+ type: :development
37
26
  prerelease: false
27
+ version_requirements: *id001
38
28
  - !ruby/object:Gem::Dependency
39
- type: :development
29
+ name: rake-compiler
40
30
  requirement: &id002 !ruby/object:Gem::Requirement
41
31
  none: false
42
32
  requirements:
43
33
  - - ">="
44
34
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
35
  version: "0"
49
- version_requirements: *id002
50
- name: rake-compiler
36
+ type: :development
51
37
  prerelease: false
38
+ version_requirements: *id002
52
39
  description: Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript.
53
40
  email: cowboyd@thefrontside.net
54
41
  executables:
@@ -817,8 +804,8 @@ files:
817
804
  - ext/v8/v8_array.h
818
805
  - ext/v8/v8_callbacks.cpp
819
806
  - ext/v8/v8_callbacks.h
820
- - ext/v8/v8_cxt.cpp
821
- - ext/v8/v8_cxt.h
807
+ - ext/v8/v8_context.cpp
808
+ - ext/v8/v8_context.h
822
809
  - ext/v8/v8_date.cpp
823
810
  - ext/v8/v8_date.h
824
811
  - ext/v8/v8_debug.cpp
@@ -827,20 +814,20 @@ files:
827
814
  - ext/v8/v8_exception.h
828
815
  - ext/v8/v8_external.cpp
829
816
  - ext/v8/v8_external.h
830
- - ext/v8/v8_func.cpp
831
- - ext/v8/v8_func.h
817
+ - ext/v8/v8_function.cpp
818
+ - ext/v8/v8_function.h
819
+ - ext/v8/v8_handle.cpp
820
+ - ext/v8/v8_handle.h
832
821
  - ext/v8/v8_locker.cpp
833
822
  - ext/v8/v8_locker.h
834
- - ext/v8/v8_msg.cpp
835
- - ext/v8/v8_msg.h
836
- - ext/v8/v8_obj.cpp
837
- - ext/v8/v8_obj.h
838
- - ext/v8/v8_ref.cpp
839
- - ext/v8/v8_ref.h
823
+ - ext/v8/v8_message.cpp
824
+ - ext/v8/v8_message.h
825
+ - ext/v8/v8_object.cpp
826
+ - ext/v8/v8_object.h
840
827
  - ext/v8/v8_script.cpp
841
828
  - ext/v8/v8_script.h
842
- - ext/v8/v8_str.cpp
843
- - ext/v8/v8_str.h
829
+ - ext/v8/v8_string.cpp
830
+ - ext/v8/v8_string.h
844
831
  - ext/v8/v8_template.cpp
845
832
  - ext/v8/v8_template.h
846
833
  - ext/v8/v8_try_catch.cpp
@@ -849,6 +836,8 @@ files:
849
836
  - ext/v8/v8_v8.h
850
837
  - ext/v8/v8_value.cpp
851
838
  - ext/v8/v8_value.h
839
+ - ext/v8/v8_weakref.cpp
840
+ - ext/v8/v8_weakref.h
852
841
  - lib/v8.rb
853
842
  - lib/v8/access.rb
854
843
  - lib/v8/array.rb
@@ -858,16 +847,26 @@ files:
858
847
  - lib/v8/function.rb
859
848
  - lib/v8/object.rb
860
849
  - lib/v8/portal.rb
861
- - lib/v8/portal/functions.rb
850
+ - lib/v8/portal/caller.rb
851
+ - lib/v8/portal/constructor.rb
852
+ - lib/v8/portal/function.rb
853
+ - lib/v8/portal/interceptors.rb
854
+ - lib/v8/portal/proxies.rb
855
+ - lib/v8/portal/templates.rb
862
856
  - lib/v8/stack.rb
863
857
  - lib/v8/tap.rb
864
858
  - lib/v8/version.rb
859
+ - spec/ext/array_spec.rb
865
860
  - spec/ext/cxt_spec.rb
861
+ - spec/ext/ext_spec_helper.rb
866
862
  - spec/ext/func_spec.rb
863
+ - spec/ext/mem_spec.rb
864
+ - spec/ext/object_spec.rb
867
865
  - spec/ext/try_catch_spec.rb
868
866
  - spec/redjs_helper.rb
869
867
  - spec/spec_helper.rb
870
868
  - spec/v8/error_spec.rb
869
+ - spec/v8/portal/proxies_spec.rb
871
870
  - therubyracer.gemspec
872
871
  - spec/redjs/README.txt
873
872
  - spec/redjs/jsapi_spec.rb
@@ -887,23 +886,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
887
886
  requirements:
888
887
  - - ">="
889
888
  - !ruby/object:Gem::Version
890
- hash: 3
889
+ hash: 994829624970814208
891
890
  segments:
892
891
  - 0
893
892
  version: "0"
894
893
  required_rubygems_version: !ruby/object:Gem::Requirement
895
894
  none: false
896
895
  requirements:
897
- - - ">="
896
+ - - ">"
898
897
  - !ruby/object:Gem::Version
899
- hash: 3
900
- segments:
901
- - 0
902
- version: "0"
898
+ version: 1.3.1
903
899
  requirements: []
904
900
 
905
901
  rubyforge_project: therubyracer
906
- rubygems_version: 1.6.2
902
+ rubygems_version: 1.6.0
907
903
  signing_key:
908
904
  specification_version: 3
909
905
  summary: Embed the V8 Javascript interpreter into Ruby