therubyrhino 1.73.3 → 1.73.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/History.txt +9 -0
- data/lib/rhino.rb +2 -2
- data/lib/rhino/error.rb +30 -4
- data/lib/rhino/rhino_ext.rb +27 -10
- data/lib/rhino/version.rb +1 -1
- data/spec/rhino/error_spec.rb +56 -0
- data/spec/spec_helper.rb +4 -0
- metadata +2 -2
data/Gemfile
CHANGED
@@ -2,4 +2,6 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
# NOTE: some specs might be excluded @see #spec/spec_helper.rb
|
6
|
+
gem 'redjs', :git => 'git://github.com/cowboyd/redjs.git', :group => :test,
|
7
|
+
:ref => "8656639e99d52b8d5414250db2e27db4bb531506"
|
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 1.73.4 2012-05-21
|
2
|
+
|
3
|
+
* allow rhino.jar path overrides with Rhino::JAR_PATH
|
4
|
+
* 'correct' JSError#inspect - show thrown value
|
5
|
+
* fix JSError#javascript_backtrace to be an array and add it on top of the
|
6
|
+
(ruby) backtrace
|
7
|
+
* make sure JSError#cause always points to native rhino cause (#19)
|
8
|
+
* avoid using instance variables with 'native' JS::Context (JRuby 1.7 warnings)
|
9
|
+
|
1
10
|
=== 1.73.3 2012-04-23
|
2
11
|
RedJS 0.4 compatible
|
3
12
|
|
data/lib/rhino.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'java'
|
2
2
|
|
3
|
-
require 'rhino/rhino-1.7R3.jar'
|
4
|
-
|
5
3
|
module Rhino
|
6
4
|
|
5
|
+
require defined?(Rhino::JAR_PATH) ? JAR_PATH : 'rhino/rhino-1.7R3.jar'
|
6
|
+
|
7
7
|
# This module contains all the native Rhino objects implemented in Java
|
8
8
|
# e.g. Rhino::JS::NativeObject # => org.mozilla.javascript.NativeObject
|
9
9
|
module JS
|
data/lib/rhino/error.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module Rhino
|
3
2
|
|
4
3
|
class JSError < StandardError
|
@@ -9,9 +8,20 @@ module Rhino
|
|
9
8
|
super(message)
|
10
9
|
end
|
11
10
|
|
11
|
+
def inspect
|
12
|
+
"#<#{self.class.name}: #{message}>"
|
13
|
+
end
|
14
|
+
|
12
15
|
# most likely a Rhino::JS::JavaScriptException
|
13
16
|
def cause
|
14
|
-
@
|
17
|
+
return @cause if defined?(@cause)
|
18
|
+
@cause = begin
|
19
|
+
if @native.respond_to?(:cause) && @native.cause
|
20
|
+
@native.cause
|
21
|
+
else
|
22
|
+
@native.is_a?(JS::RhinoException) ? @native : nil
|
23
|
+
end
|
24
|
+
end
|
15
25
|
end
|
16
26
|
|
17
27
|
def value
|
@@ -40,10 +50,26 @@ module Rhino
|
|
40
50
|
end
|
41
51
|
end
|
42
52
|
|
43
|
-
def
|
44
|
-
|
53
|
+
def backtrace
|
54
|
+
if js_backtrace = javascript_backtrace
|
55
|
+
js_backtrace.push(*super)
|
56
|
+
else
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def javascript_backtrace(keep_elements = false)
|
62
|
+
if cause.is_a?(JS::RhinoException)
|
63
|
+
cause.getScriptStack.map do |element| # ScriptStackElement[]
|
64
|
+
keep_elements ? element : element.to_s
|
65
|
+
end
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
45
69
|
end
|
46
70
|
|
71
|
+
Rhino::JS::RhinoException.useMozillaStackStyle(false)
|
72
|
+
|
47
73
|
end
|
48
74
|
|
49
75
|
end
|
data/lib/rhino/rhino_ext.rb
CHANGED
@@ -196,18 +196,35 @@ class Java::OrgMozillaJavascript::BaseFunction
|
|
196
196
|
|
197
197
|
end
|
198
198
|
|
199
|
+
class Java::OrgMozillaJavascript::ScriptStackElement
|
200
|
+
|
201
|
+
def file_name; fileName; end # public final String fileName;
|
202
|
+
def function_name; functionName; end # public final String functionName;
|
203
|
+
def line_number; lineNumber; end # public final int lineNumber;
|
204
|
+
|
205
|
+
def to_s
|
206
|
+
str = "at #{fileName}"
|
207
|
+
str << ':' << lineNumber.to_s if lineNumber > -1
|
208
|
+
str << " (#{funcionName})" if functionName
|
209
|
+
str
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
199
214
|
class Java::OrgMozillaJavascript::Context
|
200
215
|
|
216
|
+
CACHE = java.util.WeakHashMap.new
|
217
|
+
|
201
218
|
def reset_cache!
|
202
|
-
|
219
|
+
CACHE[self] = java.util.WeakHashMap.new
|
203
220
|
end
|
204
221
|
|
205
222
|
def enable_cache!
|
206
|
-
|
223
|
+
CACHE[self] = nil unless CACHE[self]
|
207
224
|
end
|
208
225
|
|
209
226
|
def disable_cache!
|
210
|
-
|
227
|
+
CACHE[self] = false
|
211
228
|
end
|
212
229
|
|
213
230
|
# Support for caching JS data per context.
|
@@ -217,20 +234,20 @@ class Java::OrgMozillaJavascript::Context
|
|
217
234
|
# (implementing #equals & #hashCode e.g. RubyStrings will work ...)
|
218
235
|
#
|
219
236
|
def cache(key)
|
220
|
-
return yield if
|
221
|
-
reset_cache! unless
|
222
|
-
fetch(key) || store(key, yield)
|
237
|
+
return yield if (cache = CACHE[self]) == false
|
238
|
+
cache = reset_cache! unless cache
|
239
|
+
fetch(key, cache) || store(key, yield, cache)
|
223
240
|
end
|
224
241
|
|
225
242
|
private
|
226
243
|
|
227
|
-
def fetch(key)
|
228
|
-
ref =
|
244
|
+
def fetch(key, cache = CACHE[self])
|
245
|
+
ref = cache.get(key)
|
229
246
|
ref ? ref.get : nil
|
230
247
|
end
|
231
248
|
|
232
|
-
def store(key, value)
|
233
|
-
|
249
|
+
def store(key, value, cache = CACHE[self])
|
250
|
+
cache.put(key, java.lang.ref.WeakReference.new(value))
|
234
251
|
value
|
235
252
|
end
|
236
253
|
|
data/lib/rhino/version.rb
CHANGED
data/spec/rhino/error_spec.rb
CHANGED
@@ -59,5 +59,61 @@ describe Rhino::JSError do
|
|
59
59
|
fail "expected to rescue"
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
it "contains the native error as the cause" do
|
64
|
+
begin
|
65
|
+
Rhino::Context.eval "throw 42"
|
66
|
+
rescue => e
|
67
|
+
e.cause.should_not be nil
|
68
|
+
e.cause.should be_a Java::OrgMozillaJavascript::JavaScriptException
|
69
|
+
e.cause.getValue.should == 42
|
70
|
+
e.cause.lineNumber.should == 1
|
71
|
+
e.cause.sourceName.should == '<eval>'
|
72
|
+
else
|
73
|
+
fail "expected to rescue"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "has a correct javascript backtrace" do
|
78
|
+
begin
|
79
|
+
Rhino::Context.eval "throw 42"
|
80
|
+
rescue => e
|
81
|
+
e.javascript_backtrace.should be_a Enumerable
|
82
|
+
e.javascript_backtrace.size.should == 1
|
83
|
+
e.javascript_backtrace[0].should == "at <eval>:1"
|
84
|
+
|
85
|
+
e.javascript_backtrace(true).should be_a Enumerable
|
86
|
+
e.javascript_backtrace(true).size.should == 1
|
87
|
+
element = e.javascript_backtrace(true)[0]
|
88
|
+
element.file_name.should == '<eval>'
|
89
|
+
element.function_name.should be nil
|
90
|
+
element.line_number.should == 1
|
91
|
+
else
|
92
|
+
fail "expected to rescue"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "backtrace starts with the javascript part" do
|
97
|
+
begin
|
98
|
+
Rhino::Context.eval "throw 42"
|
99
|
+
rescue => e
|
100
|
+
e.backtrace.should be_a Array
|
101
|
+
e.backtrace[0].should == "at <eval>:1"
|
102
|
+
e.backtrace[1].should_not be nil
|
103
|
+
else
|
104
|
+
fail "expected to rescue"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it "inspect shows the javascript value" do
|
109
|
+
begin
|
110
|
+
Rhino::Context.eval "throw '42'"
|
111
|
+
rescue => e
|
112
|
+
e.inspect.should == '#<Rhino::JSError: 42>'
|
113
|
+
e.to_s.should == '42'
|
114
|
+
else
|
115
|
+
fail "expected to rescue"
|
116
|
+
end
|
117
|
+
end
|
62
118
|
|
63
119
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: therubyrhino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.73.
|
5
|
+
version: 1.73.4
|
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-
|
13
|
+
date: 2012-05-21 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|