therubyrhino 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23aafaf63c5af04a6c05a35bf9fa2b390be1f802f2871be65460ae2deae16f8e
4
- data.tar.gz: 121d8fe9f0b66fb725adb95e528e78ab08abde6e849ea839e607a85af004aa68
3
+ metadata.gz: 2e15819e51a33cdf6ad48d5ccdbe29732ed6c845e46c7052d7899a1ddb6fa80a
4
+ data.tar.gz: 2c7d2c651436969c0ef632857bf42dcd43ce88ee85717a032328c3c003f3ab02
5
5
  SHA512:
6
- metadata.gz: a2ed193aa1265042172ba68b3ddea823949d7ff2ea8dc3fdbffb353d7d99640e33ee8ad12e7e5cdff4bd7abbccce0ae50d0f293c7b9c1f2c15b5c9175d23377d
7
- data.tar.gz: 3f2fc23e13149d53e1aa008b2161d1580ac75357ce94316ae734056614f9b9c653113558c65154138fc1d816a9a3791d5436dd4a0cfa657067c3ac63bef947e3
6
+ metadata.gz: c173fc94ff7c4a34642671dc86b22e826ca3659ff4677989ff99d9d9a2d9589de0c381890ac5a0e6012b2e4ee9e3390e0c1da645edf0493ccf30c80af3aa1efb
7
+ data.tar.gz: bc8cee36e858478f88adbc39c073a0108d87f5d56e6cb375f1cb4165d343bb0186e6890d1caf65e586663da722d594818e2a781a1b1478660f51c9166bf07a47
@@ -108,13 +108,9 @@ class Java::OrgMozillaJavascript::ScriptableObject
108
108
  else
109
109
  if property = self[name_str]
110
110
  if property.is_a?(Rhino::JS::Function)
111
- begin
112
- context = Rhino::JS::Context.enter
113
- scope = current_scope(context)
111
+ with_context do |context|
114
112
  js_args = Rhino.args_to_javascript(args, self) # scope == self
115
- Rhino.to_ruby property.__call__(context, scope, self, js_args)
116
- ensure
117
- Rhino::JS::Context.exit
113
+ Rhino.to_ruby property.__call__(context, current_scope(context), self, js_args)
118
114
  end
119
115
  else
120
116
  if args.size > 0
@@ -129,9 +125,23 @@ class Java::OrgMozillaJavascript::ScriptableObject
129
125
  end
130
126
 
131
127
  protected
132
-
128
+
129
+ def with_context
130
+ context = Rhino::JS::Context.getCurrentContext
131
+ unless context
132
+ context = Rhino::JS::Context.enter
133
+ context.initStandardObjects
134
+ context_exit = true
135
+ end
136
+ begin
137
+ yield(context)
138
+ ensure
139
+ Rhino::JS::Context.exit if context_exit
140
+ end
141
+ end
142
+
133
143
  def current_scope(context)
134
- getParentScope || context.initStandardObjects
144
+ getParentScope || Rhino::JS::ScriptRuntime.getGlobal(context)
135
145
  end
136
146
 
137
147
  end
@@ -183,16 +193,17 @@ module Rhino
183
193
  # JavaScript's Function#call but rather as Ruby's Method#call !
184
194
  # Use #apply or #bind before calling to achieve the same effect.
185
195
  def call(*args)
186
- context = Rhino::JS::Context.enter; scope = current_scope(context)
187
- # calling as a (var) stored function - no this === undefined "use strict"
188
- # TODO can't pass Undefined.instance as this - it's not a Scriptable !?
189
- this = Rhino::JS::ScriptRuntime.getGlobal(context)
190
- js_args = Rhino.args_to_javascript(args, scope)
191
- Rhino.to_ruby __call__(context, scope, this, js_args)
192
- rescue Rhino::JS::JavaScriptException => e
193
- raise Rhino::JSError.new(e)
194
- ensure
195
- Rhino::JS::Context.exit
196
+ with_context do |context|
197
+ begin
198
+ # calling as a (var) stored function - no this === undefined "use strict"
199
+ # TODO can't pass Undefined.instance as this - it's not a Scriptable !?
200
+ this = Rhino::JS::ScriptRuntime.getGlobal(context)
201
+ js_args = Rhino.args_to_javascript(args, scope = current_scope(context))
202
+ Rhino.to_ruby __call__(context, scope, this, js_args)
203
+ rescue Rhino::JS::JavaScriptException => e
204
+ raise Rhino::JSError.new(e)
205
+ end
206
+ end
196
207
  end
197
208
  end
198
209
  end
@@ -203,9 +214,10 @@ class Java::OrgMozillaJavascript::BaseFunction
203
214
 
204
215
  # Object call(Context context, Scriptable scope, Scriptable this, Object[] args)
205
216
  alias_method :__call__, :call
206
-
217
+
218
+ include Rhino::Ruby::FunctionCall if RUBY_VERSION < '2.1'
207
219
  # @deprecated (but needed to support JRuby <= 9.2)
208
- module_exec { define_method :call, Rhino::Ruby::FunctionCall.instance_method(:call) }
220
+ define_method :call, Rhino::Ruby::FunctionCall.instance_method(:call)
209
221
 
210
222
  def self.inherited(klass)
211
223
  # NOTE: in JRuby < 9.3 inherited won't be called for a Java class
@@ -216,21 +228,22 @@ class Java::OrgMozillaJavascript::BaseFunction
216
228
 
217
229
  # bind a JavaScript function into the given (this) context
218
230
  def bind(this, *args)
219
- context = Rhino::JS::Context.enter; scope = current_scope(context)
220
- args = Rhino.args_to_javascript(args, scope)
221
- Rhino::JS::BoundFunction.new(context, scope, self, Rhino.to_javascript(this), args)
222
- ensure
223
- Rhino::JS::Context.exit
231
+ with_context do |context|
232
+ args = Rhino.args_to_javascript(args, scope = current_scope(context))
233
+ Rhino::JS::BoundFunction.new(context, scope, self, Rhino.to_javascript(this), args)
234
+ end
224
235
  end
225
236
 
226
237
  # use JavaScript functions constructors from Ruby as `fn.new`
227
238
  def new(*args)
228
- context = Rhino::JS::Context.enter; scope = current_scope(context)
229
- construct(context, scope, Rhino.args_to_javascript(args, scope))
230
- rescue Rhino::JS::JavaScriptException => e
231
- raise Rhino::JSError.new(e)
232
- ensure
233
- Rhino::JS::Context.exit
239
+ with_context do |context|
240
+ begin
241
+ scope = current_scope(context)
242
+ construct(context, scope, Rhino.args_to_javascript(args, scope))
243
+ rescue Rhino::JS::JavaScriptException => e
244
+ raise Rhino::JSError.new(e)
245
+ end
246
+ end
234
247
  end
235
248
 
236
249
  # apply a function with the given context and (optional) arguments
@@ -239,13 +252,14 @@ class Java::OrgMozillaJavascript::BaseFunction
239
252
  # NOTE: That #call from Ruby does not have the same semantics as
240
253
  # JavaScript's Function#call but rather as Ruby's Method#call !
241
254
  def apply(this, *args)
242
- context = Rhino::JS::Context.enter; scope = current_scope(context)
243
- args = Rhino.args_to_javascript(args, scope)
244
- __call__(context, scope, Rhino.to_javascript(this), args)
245
- rescue Rhino::JS::JavaScriptException => e
246
- raise Rhino::JSError.new(e)
247
- ensure
248
- Rhino::JS::Context.exit
255
+ with_context do |context|
256
+ begin
257
+ args = Rhino.args_to_javascript(args, scope = current_scope(context))
258
+ __call__(context, scope, Rhino.to_javascript(this), args)
259
+ rescue Rhino::JS::JavaScriptException => e
260
+ raise Rhino::JSError.new(e)
261
+ end
262
+ end
249
263
  end
250
264
  alias_method :methodcall, :apply # V8::Function compatibility
251
265
 
@@ -1,3 +1,3 @@
1
1
  module Rhino
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -96,10 +96,6 @@ describe "NativeObject (scoped)" do
96
96
  @object = @context.newObject(@scope)
97
97
  end
98
98
 
99
- after do
100
- Rhino::JS::Context.exit
101
- end
102
-
103
99
  it_should_behave_like 'ScriptableObject'
104
100
 
105
101
  it 'routes rhino methods' do
@@ -172,10 +168,6 @@ describe "NativeFunction" do
172
168
  object = @context.newObject(@scope)
173
169
  @object = Rhino::JS::ScriptableObject.getProperty(object, 'toString')
174
170
  end
175
-
176
- after do
177
- Rhino::JS::Context.exit
178
- end
179
171
 
180
172
  it_should_behave_like 'ScriptableObject'
181
173
 
@@ -250,10 +242,6 @@ describe "NativeFunction (constructor)" do
250
242
 
251
243
  @object = Rhino::JS::ScriptableObject.getProperty(@context.newObject(@scope), 'constructor')
252
244
  end
253
-
254
- after do
255
- Rhino::JS::Context.exit
256
- end
257
245
 
258
246
  it_should_behave_like 'ScriptableObject'
259
247
 
@@ -5,12 +5,13 @@ shared_examples_for Rhino::Ruby::Scriptable, :shared => true do
5
5
  it "puts, gets and has a read/write attr" do
6
6
  start = mock('start')
7
7
  start.expects(:put).never
8
-
8
+
9
+ @wrapper = wrapper
9
10
  @wrapper.unwrap.instance_eval do
10
11
  def foo; @foo; end
11
12
  def foo=(foo); @foo = foo; end
12
13
  end
13
-
14
+
14
15
  @wrapper.put('foo', start, 42)
15
16
  @wrapper.has('foo', nil).should == true
16
17
  @wrapper.get('foo', nil).should == 42
@@ -20,21 +21,23 @@ shared_examples_for Rhino::Ruby::Scriptable, :shared => true do
20
21
  it "puts, gets and has a write only attr" do
21
22
  start = mock('start')
22
23
  start.expects(:put).never
23
-
24
+
25
+ @wrapper = wrapper
24
26
  @wrapper.unwrap.instance_eval do
25
27
  def foo=(foo); @foo = foo; end
26
28
  end
27
-
29
+
28
30
  @wrapper.put('foo', start, 42)
31
+ @wrapper.unwrap.instance_variable_get(:'@foo').should == 42
29
32
  @wrapper.has('foo', nil).should == true
30
33
  @wrapper.get('foo', nil).should be(nil)
31
- @wrapper.unwrap.instance_variable_get(:'@foo').should == 42
32
34
  end
33
35
 
34
36
  it "puts, gets and has gets delegated if it acts like a Hash" do
35
37
  start = mock('start')
36
38
  start.expects(:put).never
37
-
39
+
40
+ @wrapper = wrapper
38
41
  @wrapper.unwrap.instance_eval do
39
42
  def [](name); (@hash ||= {})[name]; end
40
43
  def []=(name, value); (@hash ||= {})[name] = value; end
@@ -49,7 +52,8 @@ shared_examples_for Rhino::Ruby::Scriptable, :shared => true do
49
52
  it "puts, gets and has non-existing property" do
50
53
  start = mock('start')
51
54
  start.expects(:put).once
52
-
55
+
56
+ @wrapper = wrapper
53
57
  @wrapper.put('foo', start, 42)
54
58
  @wrapper.has('foo', nil).should == false
55
59
  @wrapper.get('foo', nil).should be(Rhino::JS::Scriptable::NOT_FOUND)
@@ -58,15 +62,14 @@ shared_examples_for Rhino::Ruby::Scriptable, :shared => true do
58
62
  end
59
63
 
60
64
  describe Rhino::Ruby::Object do
61
-
62
- before do
63
- @wrapper = Rhino::Ruby::Object.wrap @object = Object.new
64
- end
65
-
65
+
66
+ let(:object) { Object.new }
67
+ let(:wrapper) { Rhino::Ruby::Object.wrap object }
68
+
66
69
  it "unwraps a ruby object" do
67
- @wrapper.unwrap.should be(@object)
70
+ wrapper.unwrap.should be(object)
68
71
  end
69
-
72
+
70
73
  it_should_behave_like Rhino::Ruby::Scriptable
71
74
 
72
75
  class UII < Object
@@ -162,13 +165,18 @@ describe Rhino::Ruby::Object do
162
165
  end
163
166
 
164
167
  describe Rhino::Ruby::Function do
165
-
166
- before do
167
- @wrapper = Rhino::Ruby::Function.wrap @method = Object.new.method(:to_s)
168
+
169
+ let(:a_class) do
170
+ Class.new do
171
+ def self.sample; end
172
+ def inspect; 'SAMPLE' end
173
+ end
168
174
  end
169
-
175
+ let(:method) { a_class.method(:sample) }
176
+ let(:wrapper) { Rhino::Ruby::Function.wrap method }
177
+
170
178
  it "unwraps a ruby method" do
171
- @wrapper.unwrap.should be(@method)
179
+ wrapper.unwrap.should be(method)
172
180
  end
173
181
 
174
182
  it_should_behave_like Rhino::Ruby::Scriptable
@@ -222,8 +230,8 @@ describe Rhino::Ruby::Function do
222
230
  rb_function = Rhino::Ruby::Function.wrap klass.new.method(:foo)
223
231
  this = nil
224
232
 
225
- args = [ 1.to_java, 2.to_java, 3.to_java ].to_java; js_return = nil
226
- lambda { js_return = rb_function.call(context, scope, this, args) }.should_not raise_error
233
+ args = [ 1.to_java, 2.to_java, 3.to_java ].to_java
234
+ js_return = rb_function.call(context, scope, this, args)
227
235
  js_return.should == 1
228
236
  end
229
237
 
@@ -321,13 +329,12 @@ describe Rhino::Ruby::Function do
321
329
  end
322
330
 
323
331
  describe Rhino::Ruby::Constructor do
324
-
325
- before do
326
- @wrapper = Rhino::Ruby::Constructor.wrap @class = Class.new(Object)
327
- end
328
-
332
+
333
+ let(:klass) { Class.new(Object) }
334
+ let(:wrapper) { Rhino::Ruby::Constructor.wrap(klass) }
335
+
329
336
  it "unwraps a ruby method" do
330
- @wrapper.unwrap.should be(@class)
337
+ wrapper.unwrap.should be(klass)
331
338
  end
332
339
 
333
340
  it_should_behave_like Rhino::Ruby::Scriptable
@@ -20,15 +20,23 @@ module Rhino
20
20
  @context_factory ||= Rhino::JS::ContextFactory.new
21
21
  end
22
22
 
23
- def context
23
+ def context(enter: true)
24
24
  @context || context_factory.call { |ctx| @context = ctx }
25
- @context
25
+ @context.tap { Rhino::JS::Context.enter(@context, context_factory) }
26
26
  end
27
27
 
28
28
  def scope
29
- context.initStandardObjects(nil, false)
29
+ context.initStandardObjects
30
30
  end
31
-
31
+
32
+ def exit_context
33
+ Rhino::JS::Context.exit if @context
34
+ end
35
+
36
+ def self.included(base)
37
+ base.after { exit_context }
38
+ end
39
+
32
40
  end
33
41
  end
34
42
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.required_ruby_version = '>= 1.9.3'
23
23
 
24
- s.add_dependency "therubyrhino_jar", '>= 1.7.4', '< 1.7.8'
24
+ s.add_dependency "therubyrhino_jar", '>= 1.7.4', '< 1.7.9'
25
25
 
26
26
  s.add_development_dependency "rspec", "~> 2.14.1"
27
27
  s.add_development_dependency "mocha", "~> 0.13.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: therubyrhino
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-19 00:00:00.000000000 Z
11
+ date: 2019-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: 1.7.4
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
- version: 1.7.8
21
+ version: 1.7.9
22
22
  name: therubyrhino_jar
23
23
  type: :runtime
24
24
  prerelease: false
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 1.7.4
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 1.7.8
32
+ version: 1.7.9
33
33
  - !ruby/object:Gem::Dependency
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements: