therubyrhino 1.73.2 → 1.73.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source :rubygems
2
2
 
3
- gemspec
3
+ gemspec
4
+
5
+ gem 'redjs', :git => 'git://github.com/cowboyd/redjs.git', :branch => "0.4", :group => :test
@@ -1,3 +1,51 @@
1
+ === 1.73.3 2012-04-23
2
+ RedJS 0.4 compatible
3
+
4
+ * allow try-catch-ing ScriptError (besides StandardError) in JS
5
+ * support for yield in JS property access via the [], []= methods
6
+ * refactor access implementations to classes + introduce a shared base
7
+ * missing explicit require 'rhino/version'
8
+ * Ruby StandardError wrapping so they can be try-catched as JS "error" values
9
+ * Rhino::Context.new is expected to yield when block passed
10
+
11
+ === 1.73.2 2012-04-11
12
+ RedJS 0.2.1 compatible
13
+
14
+ * improve JSError#message + add JSError#value to reflect throw JS value
15
+ * correctly convert hashes nested within arrays to_javascript (#12)
16
+ * full jruby --1.9 compatibility
17
+ * Context.default_factory - no longer use a new factory per context
18
+ * restrictable limits now require Contex.new(:restrictable => true)
19
+ * added Context#timeout_limit (to complete instruction_limit)
20
+
21
+ === 1.73.1 2011-11-28
22
+ NOTE: this is a "major" code update from 1.73.0 with some incompatibilities
23
+ although keeping the bits backward compatible as much as possible :
24
+
25
+ * add a JS:Function#apply to be used for calling functions from Ruby
26
+ * add a JS:Function#bind usable with JS functions from Ruby
27
+ * JS:Function#call should work similar to Method/Proc#call
28
+ * customizable scriptable access module for resolving Ruby properties from JS
29
+ with TRR compatible Ruby::DefaultAccess and a custom Ruby::AttributeAccess
30
+ * implement JavaScript function style argument filling/slicing (for Ruby)
31
+ * delegate to hash like method []/[]= when wrapped subject supports them
32
+ * introduce Ruby::Constructor JS wrapper for Ruby classes
33
+ * hande int JavaScript property resolution
34
+ * make sure Time -> Date conversion happens as well
35
+ * deprecate JavascriptError use JSError instead with a javascript_backtrace fix
36
+ * avoid using Rhino::To.javascript instead use Rhino.to_javascript etc.
37
+ * NativeObject/NativeFunction got removed to avoid wrapping - instead Rhino's
38
+ "native" Java classes are customized using JRuby's Java integration
39
+ * support for setting JS version via Context.version
40
+ * Rhino::J gets deprecated it's now know as Rhino::JS
41
+
42
+ === 1.73.0 2011-11-28
43
+
44
+ * upgrade to rhino-1.7R3
45
+ * cache objects passed to context - same object passed twice ends up the same
46
+ * properly map ruby Time objects to javascript Date
47
+ * jruby --1.9 improvements
48
+
1
49
  === 1.72.8 2011-06-26
2
50
  * fix passing of options hash to ruby.
3
51
 
@@ -5,18 +5,18 @@
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- Embed the Mozilla Rhino Javascript interpreter into Ruby
8
+ Embed the Mozilla Rhino JavaScript interpreter into Ruby
9
9
 
10
10
  == FEATURES/PROBLEMS:
11
11
 
12
- * Evaluate Javascript from with in Ruby
13
- * Embed your Ruby objects into the Javascript world
12
+ * Evaluate JavaScript from with in Ruby
13
+ * Embed your Ruby objects into the JavaScript world
14
14
 
15
15
  == SYNOPSIS:
16
16
 
17
- 1. Javascript goes into Ruby
18
- 1. Ruby Objects goes into Javascript
19
- 1. Our shark's in the Javascript!
17
+ 1. JavaScript goes into Ruby
18
+ 2. Ruby Objects goes into JavaScript
19
+ 3. Our shark's in the JavaScript!
20
20
 
21
21
  require 'rhino'
22
22
 
@@ -30,14 +30,14 @@ Embed the Mozilla Rhino Javascript interpreter into Ruby
30
30
  cxt.eval('foo') # => "bar"
31
31
  end
32
32
 
33
- # evaluate a ruby function from javascript
33
+ # evaluate a ruby function from JS
34
34
 
35
35
  Rhino::Context.open do |context|
36
36
  context["say"] = lambda {|word, times| word * times}
37
37
  context.eval("say("Hello", 3)") #=> HelloHelloHello
38
38
  end
39
39
 
40
- # embed a ruby object into your javascript environment
40
+ # embed a ruby object into your JS environment
41
41
 
42
42
  class MyMath
43
43
  def plus(lhs, rhs)
@@ -50,7 +50,7 @@ Embed the Mozilla Rhino Javascript interpreter into Ruby
50
50
  context.eval("math.plus(20, 22)") #=> 42
51
51
  end
52
52
 
53
- # make a ruby object *be* your javascript environment
53
+ # make a ruby object *be* your JS environment
54
54
  math = MyMath.new
55
55
  Rhino::Context.open(:with => math) do |context|
56
56
  context.eval("plus(20, 22)") #=> 42
@@ -90,7 +90,7 @@ Embed the Mozilla Rhino Javascript interpreter into Ruby
90
90
  } # => Rhino::ScriptTimeoutError
91
91
  end
92
92
 
93
- ==== Different ways of loading javascript source
93
+ ==== Different ways of loading JavaScript source
94
94
 
95
95
  In addition to just evaluating strings, you can also use streams such as files.
96
96
 
@@ -106,10 +106,10 @@ In addition to just evaluating strings, you can also use streams such as files.
106
106
 
107
107
  ==== Configurable Ruby access
108
108
 
109
- By default accessing Ruby objects from javascript is compatible with therubyracer:
109
+ By default accessing Ruby objects from JavaScript is compatible with *therubyracer*:
110
110
  https://github.com/cowboyd/therubyracer/wiki/Accessing-Ruby-Objects-From-JavaScript
111
111
 
112
- Thus you end-up calling arbitrary no-arg methods as if they were javascript properties,
112
+ Thus you end-up calling arbitrary no-arg methods as if they were JavaScript properties,
113
113
  since instance accessors (properties) and methods (functions) are indistinguishable:
114
114
 
115
115
  Rhino::Context.open do |context|
@@ -132,7 +132,7 @@ that attempts to mirror only attributes as properties as close as possible:
132
132
  end
133
133
  end
134
134
 
135
- Rhino::Ruby::Scriptable.access = Rhino::Ruby::AttributeAccess
135
+ Rhino::Ruby::Scriptable.access = :attribute
136
136
  Rhino::Context.open do |context|
137
137
  context['Foo'] = Foo
138
138
  context.eval('var foo = new Foo()')
@@ -141,14 +141,19 @@ that attempts to mirror only attributes as properties as close as possible:
141
141
  context.eval('foo.check_bar()') # called like a function
142
142
  end
143
143
 
144
+ If you happen to come up with your own access strategy, just set it directly :
145
+
146
+ Rhino::Ruby::Scriptable.access = FooApp::BarAccess.instance
147
+
144
148
  === Safe by default
145
149
 
146
- The Ruby Rhino is designed to let you evaluate javascript as safely as possible unless you tell it to do something more
147
- dangerous. The default context is a hermetically sealed javascript environment with only the standard javascript objects
148
- and functions. Nothing from the ruby world is accessible at all.
150
+ The Ruby Rhino is designed to let you evaluate JavaScript as safely as possible
151
+ unless you tell it to do something more dangerous. The default context is a
152
+ hermetically sealed JavaScript environment with only the standard objects and
153
+ functions. Nothing from the Ruby world is accessible at all.
149
154
 
150
- For ruby objects that you explicitly embed into javascript, only the +public+ methods *defined in their classes* are
151
- exposed by default. E.g.
155
+ For Ruby objects that you explicitly embed into JavaScript, only the +public+
156
+ methods "defined in their classes" are exposed by default e.g.
152
157
 
153
158
  class A
154
159
  def a
@@ -171,9 +176,15 @@ exposed by default. E.g.
171
176
  cxt.eval("b.a()") # => 'TypeError: undefined property 'a' is not a function'
172
177
  end
173
178
 
179
+ == Rhino
180
+
181
+ Rhino is currently maintained at https://github.com/mozilla/rhino
182
+ Release downloads are available at http://www.mozilla.org/rhino/download.html
183
+ Rhino is licensed under the MPL 1.1/GPL 2.0 license.
184
+
174
185
  == REQUIREMENTS:
175
186
 
176
- * JRuby >= 1.3.0
187
+ * JRuby >= 1.5.6
177
188
 
178
189
  == INSTALL:
179
190
 
@@ -17,6 +17,7 @@ module Rhino
17
17
 
18
18
  end
19
19
 
20
+ require 'rhino/version'
20
21
  require 'rhino/wormhole'
21
22
  Rhino.extend Rhino::To
22
23
 
@@ -82,6 +82,7 @@ module Rhino
82
82
  end
83
83
  end
84
84
  end
85
+ yield(self) if block_given?
85
86
  end
86
87
 
87
88
  # Returns the ContextFactory used while creating this context.
@@ -149,7 +150,7 @@ module Rhino
149
150
  @native.instruction_limit = limit
150
151
  else
151
152
  raise "setting an instruction_limit has no effect on this context, use " +
152
- "Context.open(:restricted => true) to gain a restrictable instance"
153
+ "Context.open(:restrictable => true) to gain a restrictable instance"
153
154
  end
154
155
  end
155
156
 
@@ -166,7 +167,7 @@ module Rhino
166
167
  @native.timeout_limit = limit
167
168
  else
168
169
  raise "setting an timeout_limit has no effect on this context, use " +
169
- "Context.open(:restricted => true) to gain a restrictable instance"
170
+ "Context.open(:restrictable => true) to gain a restrictable instance"
170
171
  end
171
172
  end
172
173
 
@@ -2,28 +2,52 @@
2
2
  module Rhino
3
3
  module Ruby
4
4
 
5
- def self.wrap_error(e)
6
- JS::WrappedException.new(org.jruby.exceptions.RaiseException.new(e))
7
- end
8
-
9
5
  # shared JS::Scriptable implementation
10
6
  module Scriptable
11
7
 
8
+ @@access = nil
9
+ def self.access=(access)
10
+ @@access = ( access.respond_to?(:get) && access.respond_to?(:put) ) ? access :
11
+ begin
12
+ access =
13
+ if access && ! access.is_a?(Class) # Scriptable.access = :attribute
14
+ name = access.to_s.chomp('_access')
15
+ name = name[0, 1].capitalize << name[1..-1]
16
+ name = :"#{name}Access"
17
+ if Ruby.const_defined?(name)
18
+ Ruby.const_get(name) # e.g. Rhino::Ruby::AttributeAccess
19
+ else
20
+ const_get(name) # e.g. Rhino::Ruby::Scriptable::FooAccess
21
+ end
22
+ else # nil, false, Class
23
+ access
24
+ end
25
+ access.is_a?(Class) ? access.new : access
26
+ end
27
+ end
28
+
29
+ def self.access
30
+ @@access ||= Ruby::DefaultAccess.new
31
+ end
32
+
12
33
  # override Object Scriptable#get(String name, Scriptable start);
13
34
  # override Object Scriptable#get(int index, Scriptable start);
14
35
  def get(name, start)
36
+ return nil if exclude?(name)
15
37
  access.get(unwrap, name, self) { super }
16
38
  end
17
39
 
18
40
  # override boolean Scriptable#has(String name, Scriptable start);
19
41
  # override boolean Scriptable#has(int index, Scriptable start);
20
42
  def has(name, start)
43
+ return nil if exclude?(name)
21
44
  access.has(unwrap, name, self) { super }
22
45
  end
23
46
 
24
47
  # override void Scriptable#put(String name, Scriptable start, Object value);
25
48
  # override void Scriptable#put(int index, Scriptable start, Object value);
26
49
  def put(name, start, value)
50
+ return nil if exclude?(name)
27
51
  access.put(unwrap, name, value) { super }
28
52
  end
29
53
 
@@ -31,7 +55,7 @@ module Rhino
31
55
  def getIds
32
56
  ids = []
33
57
  unwrap.public_methods(false).each do |name|
34
- name = name[0...-1] if name[-1, 1] == '=' # 'foo=' ... 'foo'
58
+ next unless name = convert(name)
35
59
  name = name.to_s.to_java # java.lang.String
36
60
  ids << name unless ids.include?(name)
37
61
  end
@@ -39,21 +63,28 @@ module Rhino
39
63
  ids.to_java
40
64
  end
41
65
 
42
- @@access = nil
66
+ private
43
67
 
44
- def self.access=(access)
45
- @@access = access
68
+ def convert(name)
69
+ if exclude?(name)
70
+ nil
71
+ elsif name[-1, 1] == '='
72
+ name[0...-1]
73
+ else
74
+ name
75
+ end
46
76
  end
47
77
 
48
- def self.access
49
- @@access ||= Ruby::DefaultAccess
50
- end
78
+ FETCH = '[]'.freeze
79
+ STORE = '[]='.freeze
51
80
 
52
- private
81
+ def exclude?(name)
82
+ name == FETCH || name == STORE
83
+ end
53
84
 
54
- def access
55
- Scriptable.access
56
- end
85
+ def access
86
+ Scriptable.access
87
+ end
57
88
 
58
89
  end
59
90
 
@@ -78,7 +109,7 @@ module Rhino
78
109
  def unwrap
79
110
  @ruby
80
111
  end
81
-
112
+
82
113
  # abstract String Scriptable#getClassName();
83
114
  def getClassName
84
115
  @ruby.class.to_s # to_s handles 'nameless' classes as well
@@ -160,12 +191,12 @@ module Rhino
160
191
  begin
161
192
  callable =
162
193
  if @callable.is_a?(UnboundMethod)
163
- @callable.bind(Rhino.to_ruby(this))
194
+ @callable.bind(Rhino.to_ruby(this)) # might end up as TypeError
164
195
  else
165
196
  @callable
166
197
  end
167
198
  result = callable.call(*rb_args)
168
- rescue => e
199
+ rescue StandardError, ScriptError => e
169
200
  raise Ruby.wrap_error(e) # thus `try { } catch (e)` works in JS
170
201
  end
171
202
  Rhino.to_javascript(result, scope)
@@ -216,6 +247,25 @@ module Rhino
216
247
  context ? context.cache(key, &block) : yield
217
248
  end
218
249
 
250
+ # "hack" for ruby errors so that they act as JS thrown objects
251
+ class Exception < JS::JavaScriptException
252
+
253
+ def initialize(value)
254
+ super wrap_value(value)
255
+ end
256
+
257
+ private
258
+
259
+ def wrap_value(value)
260
+ value.is_a?(Object) ? value : Object.wrap(value)
261
+ end
262
+
263
+ end
264
+
265
+ def self.wrap_error(e)
266
+ Exception.new(e)
267
+ end
268
+
219
269
  end
220
270
 
221
271
  RubyObject = Ruby::Object
@@ -4,5 +4,78 @@ module Rhino
4
4
  autoload :DefaultAccess, "rhino/ruby/default_access"
5
5
  autoload :AttributeAccess, "rhino/ruby/attribute_access"
6
6
 
7
+ class AccessBase
8
+
9
+ def has(object, name, scope)
10
+ # try [](name) method :
11
+ if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
12
+ unless internal?(name)
13
+ value = object.[](name) { return true }
14
+ return true unless value.nil?
15
+ end
16
+ end
17
+ yield
18
+ end
19
+
20
+ def get(object, name, scope)
21
+ # try [](name) method :
22
+ if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
23
+ value = begin
24
+ object[name]
25
+ rescue LocalJumpError
26
+ nil
27
+ end unless internal?(name)
28
+ return Rhino.to_javascript(value, scope) unless value.nil?
29
+ end
30
+ yield
31
+ end
32
+
33
+ def put(object, name, value)
34
+ # try []=(name, value) method :
35
+ if object.respond_to?(:'[]=') && object.method(:'[]=').arity == 2
36
+ rb_value = Rhino.to_ruby(value)
37
+ begin
38
+ return object[name] = rb_value
39
+ rescue LocalJumpError
40
+ end unless internal?(name)
41
+ end
42
+ yield
43
+ end
44
+
45
+ private
46
+
47
+ UNDERSCORES = '__'.freeze
48
+
49
+ def internal?(name) # e.g. '__iterator__', '__proto__'
50
+ name.is_a?(String) &&
51
+ name[0..1] == UNDERSCORES && name[-2..-1] == UNDERSCORES
52
+ end
53
+
54
+ end
55
+
56
+ module DeprecatedAccess
57
+
58
+ def has(object, name, scope, &block)
59
+ Rhino.warn "[DEPRECATION] `#{self.name}.has` is deprecated, please sub-class #{self.name} instead."
60
+ instance.has(object, name, scope, &block)
61
+ end
62
+
63
+ def get(object, name, scope, &block)
64
+ Rhino.warn "[DEPRECATION] `#{self.name}.get` is deprecated, please sub-class #{self.name} instead."
65
+ instance.get(object, name, scope, &block)
66
+ end
67
+
68
+ def put(object, name, value, &block)
69
+ Rhino.warn "[DEPRECATION] `#{self.name}.put` is deprecated, please sub-class #{self.name} instead."
70
+ instance.put(object, name, value, &block)
71
+ end
72
+
73
+ private
74
+ def instance
75
+ @instance ||= self.new
76
+ end
77
+
78
+ end
79
+
7
80
  end
8
81
  end
@@ -1,57 +1,42 @@
1
1
  module Rhino
2
2
  module Ruby
3
- module AttributeAccess
3
+ class AttributeAccess < AccessBase
4
4
 
5
- def self.has(object, name, scope)
5
+ def has(object, name, scope)
6
6
  if object.respond_to?(name.to_s) ||
7
7
  object.respond_to?(:"#{name}=") # might have a writer but no reader
8
8
  return true
9
9
  end
10
- # try [](name) method :
11
- if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
12
- return true if object[name]
13
- end
14
- yield
10
+ super
15
11
  end
16
12
 
17
- def self.get(object, name, scope)
13
+ def get(object, name, scope)
18
14
  name_sym = name.to_s.to_sym
19
15
  if object.respond_to?(name_sym)
20
16
  method = object.method(name_sym)
21
17
  if method.arity == 0 && # check if it is an attr_reader
22
18
  ( object.respond_to?(:"#{name}=") ||
23
19
  object.instance_variables.find { |var| var.to_sym == :"@#{name}" } )
24
- begin
25
- return Rhino.to_javascript(method.call, scope)
26
- rescue => e
27
- raise Rhino::Ruby.wrap_error(e)
28
- end
20
+ return Rhino.to_javascript(method.call, scope)
29
21
  else
30
22
  return Function.wrap(method.unbind)
31
23
  end
32
24
  elsif object.respond_to?(:"#{name}=")
33
25
  return nil # it does have the property but is non readable
34
26
  end
35
- # try [](name) method :
36
- if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
37
- if value = object[name]
38
- return Rhino.to_javascript(value, scope)
39
- end
40
- end
41
- yield
27
+ super
42
28
  end
43
29
 
44
- def self.put(object, name, value)
30
+ def put(object, name, value)
45
31
  if object.respond_to?(set_name = :"#{name}=")
46
- return object.send(set_name, Rhino.to_ruby(value))
32
+ rb_value = Rhino.to_ruby(value)
33
+ return object.send(set_name, rb_value)
47
34
  end
48
- # try []=(name, value) method :
49
- if object.respond_to?(:'[]=') && object.method(:'[]=').arity == 2
50
- return object[name] = Rhino.to_ruby(value)
51
- end
52
- yield
35
+ super
53
36
  end
54
37
 
38
+ extend DeprecatedAccess # backward compatibility for a while
39
+
55
40
  end
56
41
  end
57
42
  end
@@ -1,54 +1,38 @@
1
1
  module Rhino
2
2
  module Ruby
3
- module DefaultAccess
3
+ class DefaultAccess < AccessBase
4
4
 
5
- def self.has(object, name, scope)
5
+ def has(object, name, scope)
6
6
  if object.respond_to?(name.to_s) ||
7
- object.respond_to?("#{name}=")
7
+ object.respond_to?(:"#{name}=")
8
8
  return true
9
9
  end
10
- # try [](name) method :
11
- if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
12
- return true if object[name]
13
- end
14
- yield
10
+ super
15
11
  end
16
12
 
17
- def self.get(object, name, scope)
13
+ def get(object, name, scope)
18
14
  if object.respond_to?(name_s = name.to_s)
19
15
  method = object.method(name_s)
20
16
  if method.arity == 0
21
- begin
22
- return Rhino.to_javascript(method.call, scope)
23
- rescue => e
24
- raise Rhino::Ruby.wrap_error(e)
25
- end
17
+ return Rhino.to_javascript(method.call, scope)
26
18
  else
27
19
  return Function.wrap(method.unbind)
28
20
  end
29
- elsif object.respond_to?("#{name}=")
21
+ elsif object.respond_to?(:"#{name}=")
30
22
  return nil
31
23
  end
32
- # try [](name) method :
33
- if object.respond_to?(:'[]') && object.method(:'[]').arity == 1
34
- if value = object[name]
35
- return Rhino.to_javascript(value, scope)
36
- end
37
- end
38
- yield
24
+ super
39
25
  end
40
26
 
41
- def self.put(object, name, value)
42
- if object.respond_to?(set_name = "#{name}=")
27
+ def put(object, name, value)
28
+ if object.respond_to?(set_name = :"#{name}=")
43
29
  return object.send(set_name, Rhino.to_ruby(value))
44
30
  end
45
- # try []=(name, value) method :
46
- if object.respond_to?(:'[]=') && object.method(:'[]=').arity == 2
47
- return object[name] = Rhino.to_ruby(value)
48
- end
49
- yield
31
+ super
50
32
  end
51
33
 
34
+ extend DeprecatedAccess # backward compatibility for a while
35
+
52
36
  end
53
37
  end
54
38
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rhino
3
- VERSION = "1.73.2"
3
+ VERSION = "1.73.3"
4
4
  end
@@ -3,7 +3,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
3
3
  describe Rhino::Ruby::AttributeAccess do
4
4
 
5
5
  before(:all) do
6
- Rhino::Ruby::Scriptable.access = Rhino::Ruby::AttributeAccess
6
+ Rhino::Ruby::Scriptable.access = Rhino::Ruby::AttributeAccess.new
7
7
  end
8
8
 
9
9
  after(:all) do
@@ -66,4 +66,54 @@ describe Rhino::Ruby::AttributeAccess do
66
66
  rb_object.the_attr_1.should == 42
67
67
  end
68
68
 
69
+ it "might set access as a symbol" do
70
+ prev_access = Rhino::Ruby::Scriptable.access
71
+ module FooAccess; end # backward compatibility
72
+ class Foo2Access; end
73
+
74
+ begin
75
+
76
+ Rhino::Ruby::Scriptable.access = nil
77
+ lambda {
78
+ Rhino::Ruby::Scriptable.access = :attribute
79
+ }.should_not raise_error
80
+ Rhino::Ruby::Scriptable.access.should be_a Rhino::Ruby::AttributeAccess
81
+
82
+ Rhino::Ruby::Scriptable.access = nil
83
+ lambda {
84
+ Rhino::Ruby::Scriptable.access = :attribute_access
85
+ }.should_not raise_error
86
+ Rhino::Ruby::Scriptable.access.should be_a Rhino::Ruby::AttributeAccess
87
+
88
+ lambda {
89
+ Rhino::Ruby::Scriptable.access = :foo
90
+ }.should_not raise_error
91
+ Rhino::Ruby::Scriptable.access.should == FooAccess
92
+
93
+ lambda {
94
+ Rhino::Ruby::Scriptable.access = :foo2
95
+ }.should_not raise_error
96
+ Rhino::Ruby::Scriptable.access.should be_a Foo2Access
97
+
98
+ lambda {
99
+ Rhino::Ruby::Scriptable.access = :bar
100
+ }.should raise_error
101
+
102
+ ensure
103
+ Rhino::Ruby::Scriptable.access = prev_access
104
+ end
105
+ end
106
+
107
+ it "is backward compatibile with the 'module' way" do
108
+ Rhino::Ruby::AttributeAccess.respond_to?(:has).should be true
109
+ Rhino::Ruby::AttributeAccess.respond_to?(:get).should be true
110
+ Rhino::Ruby::AttributeAccess.respond_to?(:put).should be true
111
+
112
+ Rhino::Ruby::Scriptable.access = Rhino::Ruby::AttributeAccess
113
+
114
+ rb_object = Rhino::Ruby::Object.wrap Meh.new
115
+ rb_object.get('theMethod0', nil).should be_a(Rhino::Ruby::Function)
116
+ rb_object.has('non-existent-method', nil).should be false
117
+ end
118
+
69
119
  end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ require 'redjs/load_specs'
4
+
5
+ puts "will run JavaScript specs from RedJS #{RedJS::VERSION}"
6
+
7
+ describe Rhino::Context do
8
+
9
+ it_behaves_like 'RedJS::Context'
10
+
11
+ # TODO: remove if present in RedJS
12
+ it "catched ScriptError in JS" do
13
+ klass = Class.new do
14
+ def muu(*args)
15
+ args && raise(ScriptError.new('muu'))
16
+ end
17
+ end
18
+
19
+ error = nil
20
+ lambda {
21
+ RedJS::Context.new do |cxt|
22
+ cxt['obj'] = klass.new
23
+ error = cxt.eval('var error; try { obj.muu(); error = null } catch(e) { error = e }')
24
+ end
25
+ }.should_not raise_error
26
+ error.should_not be nil
27
+ error.should be_a ScriptError
28
+ end
29
+
30
+ it "keeps objects iterable when property accessor is provided" do
31
+ klass = Class.new do
32
+ def [](name); name; end
33
+ attr_accessor :foo
34
+ def bar=(bar); bar; end
35
+ end
36
+
37
+ RedJS::Context.new do |cxt|
38
+ cxt['o'] = klass.new
39
+ cxt.eval('a = new Array(); for (var i in o) a.push(i);')
40
+ cxt['a'].length.should == 2 # [ 'foo', 'bar' ]
41
+ end
42
+ end
43
+
44
+ end
@@ -388,3 +388,27 @@ describe Rhino::Ruby::Constructor do
388
388
  end
389
389
 
390
390
  end
391
+
392
+ describe Rhino::Ruby::Exception do
393
+
394
+ it 'outcomes as ruby errors in function calls' do
395
+ klass = Class.new(Object) do
396
+ def foo(arg)
397
+ raise TypeError, "don't foo me with #{arg}" unless arg.is_a?(String)
398
+ end
399
+ end
400
+ rb_function = Rhino::Ruby::Function.wrap klass.new.method(:foo)
401
+ context = nil; scope = nil; this = nil; args = [ 42.to_java ].to_java
402
+ begin
403
+ rb_function.call(context, scope, this, args)
404
+ rescue java.lang.Exception => e
405
+ e.should be_a(Rhino::Ruby::Exception)
406
+ e.getValue.should be_a(Rhino::Ruby::Object)
407
+ e.value.unwrap.should be_a(TypeError)
408
+ e.value.unwrap.message == "don't foo me with 42"
409
+ else
410
+ fail "#{Rhino::Ruby::Exception} expected to be raised"
411
+ end
412
+ end
413
+
414
+ end
@@ -1,3 +1,10 @@
1
1
 
2
- require 'mocha'
3
2
  require 'rhino'
3
+
4
+ require 'mocha'
5
+ require 'redjs'
6
+
7
+ module RedJS
8
+ Context = Rhino::Context
9
+ Error = Rhino::JSError
10
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: therubyrhino
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.73.2
5
+ version: 1.73.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Charles Lowell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-04-11 00:00:00 Z
13
+ date: 2012-04-23 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -66,7 +66,6 @@ extra_rdoc_files:
66
66
  - README.rdoc
67
67
  files:
68
68
  - .gitignore
69
- - .gitmodules
70
69
  - .travis.yml
71
70
  - Gemfile
72
71
  - History.txt
@@ -85,15 +84,14 @@ files:
85
84
  - lib/rhino/ruby/default_access.rb
86
85
  - lib/rhino/version.rb
87
86
  - lib/rhino/wormhole.rb
88
- - spec/redjs_helper.rb
89
87
  - spec/rhino/access_spec.rb
90
88
  - spec/rhino/context_spec.rb
91
89
  - spec/rhino/deprecations_spec.rb
92
90
  - spec/rhino/error_spec.rb
91
+ - spec/rhino/redjs_spec.rb
93
92
  - spec/rhino/rhino_ext_spec.rb
94
93
  - spec/rhino/ruby_spec.rb
95
94
  - spec/rhino/wormhole_spec.rb
96
- - spec/spec.opts
97
95
  - spec/spec_helper.rb
98
96
  - therubyrhino.gemspec
99
97
  homepage: http://github.com/cowboyd/therubyrhino
@@ -1,3 +0,0 @@
1
- [submodule "spec/redjs"]
2
- path = spec/redjs
3
- url = git@github.com:cowboyd/redjs.git
@@ -1,5 +0,0 @@
1
-
2
- require File.dirname(__FILE__) + '/spec_helper.rb'
3
-
4
- include Rhino
5
-
@@ -1 +0,0 @@
1
- --colour