therubyrhino 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Gemfile +14 -4
- data/History.txt +11 -0
- data/README.rdoc +2 -2
- data/lib/rhino.rb +17 -0
- data/lib/rhino/error.rb +40 -20
- data/lib/rhino/version.rb +1 -1
- data/lib/rhino/wormhole.rb +3 -1
- data/spec/rhino/error_spec.rb +51 -2
- data/spec/rhino/integration/bar.js +11 -0
- data/spec/rhino/integration/foo.js +7 -0
- data/spec/rhino/integration/index.js +7 -0
- data/spec/rhino/integration/loop.js +3 -0
- data/spec/rhino/integration/loop/element1.js +3 -0
- data/spec/rhino/integration/loop/element2.js +8 -0
- data/spec/rhino/integration_spec.rb +146 -0
- data/spec/rhino/rhino_ext_spec.rb +39 -19
- data/spec/rhino/wormhole_spec.rb +19 -23
- data/spec/spec_helper.rb +1 -0
- data/therubyrhino.gemspec +1 -1
- metadata +123 -122
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,7 +2,17 @@ source :rubygems
|
|
2
2
|
|
3
3
|
gemspec :name => "therubyrhino"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
group :test do
|
6
|
+
# NOTE: some specs might be excluded @see #spec/spec_helper.rb
|
7
|
+
gem 'redjs', :git => 'git://github.com/cowboyd/redjs.git', :group => :test,
|
8
|
+
:ref => "0d844f066666f967a78b20beb164c52d9ac3f5ca"
|
9
|
+
#gem 'redjs', :path => '../redjs', :group => :test
|
10
|
+
|
11
|
+
# e.g. `export therubyrhino_jar=1.7.3`
|
12
|
+
if jar_version = ENV['therubyrhino_jar']
|
13
|
+
gem 'therubyrhino_jar', jar_version
|
14
|
+
else
|
15
|
+
gem 'therubyrhino_jar', :path => '.'
|
16
|
+
end
|
17
|
+
gem 'less', '>= 2.2.1', :require => nil
|
18
|
+
end
|
data/History.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
=== 2.0.1 2012-08-24
|
2
|
+
|
3
|
+
* JSError improvement to preserve nested Ruby error message
|
4
|
+
* jar-1.7.4 regression fix e.g when loading less (#25)
|
5
|
+
* error.message should be a String value (1.9.3 compat)
|
6
|
+
|
7
|
+
=== jar-1.7.4 2012-08-02
|
8
|
+
|
9
|
+
* updated to new Mozilla Rhino 1.7R4 release, notes:
|
10
|
+
https://developer.mozilla.org/en/New_in_Rhino_1.7R4
|
11
|
+
|
1
12
|
=== 2.0.0 2012-08-02
|
2
13
|
This release is functionally the same as therubyrhino-1.73.5 as long
|
3
14
|
as the therubyrhino_jar-1.7.3 gem dependency is used along with it.
|
data/README.rdoc
CHANGED
@@ -184,11 +184,11 @@ Rhino is licensed under the MPL 1.1/GPL 2.0 license.
|
|
184
184
|
|
185
185
|
== REQUIREMENTS:
|
186
186
|
|
187
|
-
* JRuby >= 1.
|
187
|
+
* JRuby >= 1.6
|
188
188
|
|
189
189
|
== INSTALL:
|
190
190
|
|
191
|
-
*
|
191
|
+
* jruby -S gem install therubyrhino
|
192
192
|
|
193
193
|
== LICENSE:
|
194
194
|
|
data/lib/rhino.rb
CHANGED
@@ -16,6 +16,23 @@ module Rhino
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
@@implementation_version = nil
|
20
|
+
# Helper to resolve what version of Rhino's .jar we're really using.
|
21
|
+
def self.implementation_version
|
22
|
+
@@implementation_version ||= begin
|
23
|
+
urls = JS::Kit.java_class.to_java.getClassLoader.
|
24
|
+
getResources('META-INF/MANIFEST.MF').to_a
|
25
|
+
rhino_jar_urls = urls.select { |url| url.toString.index(JAR_PATH) }
|
26
|
+
if rhino_jar_urls.empty?
|
27
|
+
raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
|
28
|
+
elsif rhino_jar_urls.size > 1
|
29
|
+
raise "could not find #{JAR_PATH} manifest among: #{urls.map(&:toString).join(', ')}"
|
30
|
+
end
|
31
|
+
manifest = java.util.jar.Manifest.new rhino_jar_urls.first.openStream
|
32
|
+
manifest.getMainAttributes.getValue 'Implementation-Version'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
19
36
|
end
|
20
37
|
|
21
38
|
require 'rhino/version'
|
data/lib/rhino/error.rb
CHANGED
@@ -4,37 +4,35 @@ module Rhino
|
|
4
4
|
|
5
5
|
def initialize(native)
|
6
6
|
@native = native # NativeException wrapping a Java Throwable
|
7
|
-
|
8
|
-
|
7
|
+
if ( value = self.value(true) ) != nil
|
8
|
+
super value.is_a?(Exception) ? "#{value.class.name}: #{value.message}" : value
|
9
|
+
else
|
10
|
+
super cause ? cause.details : @native
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
def inspect
|
12
15
|
"#<#{self.class.name}: #{message}>"
|
13
16
|
end
|
14
17
|
|
15
|
-
#
|
18
|
+
# Returns the error message, in case of a native JavaScript value, will
|
19
|
+
# return that value converted to a String.
|
20
|
+
def message
|
21
|
+
super.to_s # since 1.9.x message is expected to allways be a string
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the (nested) cause of this error if any, most likely a
|
25
|
+
# #Rhino::JS::JavaScriptException instance.
|
16
26
|
def cause
|
17
27
|
return @cause if defined?(@cause)
|
18
|
-
@cause
|
19
|
-
|
20
|
-
@native.cause
|
21
|
-
else
|
22
|
-
@native.is_a?(JS::RhinoException) ? @native : nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def value
|
28
|
-
return @value if defined?(@value)
|
29
|
-
if cause.respond_to?(:value) # e.g. JavaScriptException.getValue
|
30
|
-
@value = cause.value
|
31
|
-
elsif ( unwrap = self.unwrap ) && unwrap.respond_to?(:value)
|
32
|
-
@value = unwrap.value
|
28
|
+
if @native.respond_to?(:cause) && @native.cause
|
29
|
+
@native.cause
|
33
30
|
else
|
34
|
-
@
|
31
|
+
@native.is_a?(JS::RhinoException) ? @native : nil
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
35
|
+
# Attempts to unwrap the (native) JavaScript/Java exception.
|
38
36
|
def unwrap
|
39
37
|
return @unwrap if defined?(@unwrap)
|
40
38
|
cause = self.cause
|
@@ -50,6 +48,15 @@ module Rhino
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
51
|
+
# Return the thown (native) JavaScript value.
|
52
|
+
def value(unwrap = false)
|
53
|
+
return @value if defined?(@value) && ! unwrap
|
54
|
+
@value = get_value unless defined?(@value)
|
55
|
+
return @value.unwrap if unwrap && @value.respond_to?(:unwrap)
|
56
|
+
@value
|
57
|
+
end
|
58
|
+
|
59
|
+
# The backtrace is constructed using #javascript_backtrace + the Ruby part.
|
53
60
|
def backtrace
|
54
61
|
if js_backtrace = javascript_backtrace
|
55
62
|
js_backtrace.push(*super)
|
@@ -58,6 +65,7 @@ module Rhino
|
|
58
65
|
end
|
59
66
|
end
|
60
67
|
|
68
|
+
# Returns the JavaScript back-trace part for this error (the script stack).
|
61
69
|
def javascript_backtrace(keep_elements = false)
|
62
70
|
if cause.is_a?(JS::RhinoException)
|
63
71
|
cause.getScriptStack.map do |element| # ScriptStackElement[]
|
@@ -70,6 +78,18 @@ module Rhino
|
|
70
78
|
|
71
79
|
Rhino::JS::RhinoException.useMozillaStackStyle(false)
|
72
80
|
|
81
|
+
private
|
82
|
+
|
83
|
+
def get_value
|
84
|
+
if ( cause = self.cause ) && cause.respond_to?(:value)
|
85
|
+
cause.value # e.g. JavaScriptException.getValue
|
86
|
+
elsif ( unwrap = self.unwrap ) && unwrap.respond_to?(:value)
|
87
|
+
unwrap.value
|
88
|
+
else
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
73
93
|
end
|
74
94
|
|
75
|
-
end
|
95
|
+
end
|
data/lib/rhino/version.rb
CHANGED
data/lib/rhino/wormhole.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
|
2
2
|
module Rhino
|
3
3
|
module To
|
4
|
-
|
4
|
+
|
5
5
|
def to_ruby(object)
|
6
6
|
case object
|
7
7
|
when JS::Scriptable::NOT_FOUND, JS::Undefined then nil
|
8
8
|
when JS::Wrapper then object.unwrap
|
9
9
|
when JS::NativeArray then array_to_ruby(object)
|
10
10
|
when JS::NativeDate then Time.at(object.getJSTimeValue / 1000)
|
11
|
+
# Rhino 1.7R4 added ConsString for optimized String + operations :
|
12
|
+
when Java::JavaLang::CharSequence then object.toString
|
11
13
|
else object
|
12
14
|
end
|
13
15
|
end
|
data/spec/rhino/error_spec.rb
CHANGED
@@ -42,7 +42,7 @@ describe Rhino::JSError do
|
|
42
42
|
e.should be_a(Rhino::JSError)
|
43
43
|
e.value.should be_a(Rhino::JS::NativeObject)
|
44
44
|
e.value['foo'].should == 'bar'
|
45
|
-
e.
|
45
|
+
e.message.should == e.value.to_s
|
46
46
|
else
|
47
47
|
fail "expected to rescue"
|
48
48
|
end
|
@@ -54,7 +54,7 @@ describe Rhino::JSError do
|
|
54
54
|
rescue => e
|
55
55
|
e.should be_a(Rhino::JSError)
|
56
56
|
e.value.should == 'mehehehe'
|
57
|
-
e.
|
57
|
+
e.message.should == e.value.to_s
|
58
58
|
else
|
59
59
|
fail "expected to rescue"
|
60
60
|
end
|
@@ -128,6 +128,28 @@ describe Rhino::JSError do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
it "wrapps false value correctly" do
|
132
|
+
begin
|
133
|
+
Rhino::Context.eval "throw false"
|
134
|
+
rescue => e
|
135
|
+
e.inspect.should == '#<Rhino::JSError: false>'
|
136
|
+
e.value.should be false
|
137
|
+
else
|
138
|
+
fail "expected to rescue"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
it "wrapps null value correctly" do
|
143
|
+
begin
|
144
|
+
Rhino::Context.eval "throw null"
|
145
|
+
rescue => e
|
146
|
+
e.inspect.should == '#<Rhino::JSError: null>'
|
147
|
+
e.value.should be nil
|
148
|
+
else
|
149
|
+
fail "expected to rescue"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
131
153
|
it "raises correct error from function#apply" do
|
132
154
|
begin
|
133
155
|
context = Rhino::Context.new
|
@@ -140,5 +162,32 @@ describe Rhino::JSError do
|
|
140
162
|
fail "expected to rescue"
|
141
163
|
end
|
142
164
|
end
|
165
|
+
|
166
|
+
it "prints info about nested (ruby) error" do
|
167
|
+
context = Rhino::Context.new
|
168
|
+
klass = Class.new do
|
169
|
+
def hello(arg = 42)
|
170
|
+
raise RuntimeError, 'hello' if arg != 42
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context[:Hello] = klass.new
|
174
|
+
hi = context.eval "( function hi(arg) { Hello.hello(arg); } )"
|
175
|
+
begin
|
176
|
+
hi.call(24)
|
177
|
+
rescue => e
|
178
|
+
e.should be_a Rhino::JSError
|
179
|
+
e.value.should_not be nil
|
180
|
+
e.value.should be_a Rhino::Ruby::Object
|
181
|
+
e.value(true).should be_a RuntimeError # unwraps ruby object
|
182
|
+
# prints the original message (beyond [ruby RuntimeError]) :
|
183
|
+
e.message.should == "RuntimeError: hello"
|
184
|
+
else
|
185
|
+
fail "expected to rescue"
|
186
|
+
end
|
187
|
+
# V8::JSError: hello
|
188
|
+
# from (irb):4:in `hello'
|
189
|
+
# from at hi (<eval>:1:28)
|
190
|
+
# from (irb):9
|
191
|
+
end
|
143
192
|
|
144
193
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
//console.log('bar.js 1');
|
2
|
+
var util = require('util');
|
3
|
+
//console.log('bar.js 2');
|
4
|
+
var Bar = {};
|
5
|
+
Bar.puts = function (message) {
|
6
|
+
util.puts(message);
|
7
|
+
return message;
|
8
|
+
};
|
9
|
+
//console.log('bar.js 3');
|
10
|
+
exports.Bar = Bar;
|
11
|
+
//console.log('bar.js 4');
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'rhino'
|
4
|
+
require 'pathname'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
puts "Rhino #{Rhino::VERSION} (#{Rhino::JAR_PATH})"
|
8
|
+
|
9
|
+
describe 'integration' do
|
10
|
+
|
11
|
+
it "loads LESS" do
|
12
|
+
require 'less'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "require foo" do # CommonJS
|
16
|
+
environment = new_environment(:console => Console)
|
17
|
+
environment.native 'util', Util.new(out = StringIO.new)
|
18
|
+
exports = environment.require 'foo'
|
19
|
+
out.string.should == "Hello Bar!\n"
|
20
|
+
|
21
|
+
exports.should_not be nil
|
22
|
+
exports.foo.should respond_to(:'[]')
|
23
|
+
exports.foo['Bar'].should respond_to(:'[]')
|
24
|
+
exports.foo['Bar'][:puts].should be_a Rhino::JS::Function
|
25
|
+
end
|
26
|
+
|
27
|
+
it "require index/loop" do # CommonJS
|
28
|
+
environment = new_environment(:console => Console)
|
29
|
+
environment.require 'index'
|
30
|
+
environment.context['Loop'].should_not be nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def new_environment(globals = {})
|
36
|
+
context = Rhino::Context.new
|
37
|
+
#context.optimization_level = -1
|
38
|
+
globals.each { |key, obj| context[key] = obj }
|
39
|
+
path = Pathname(__FILE__).dirname.join('integration')
|
40
|
+
Env.new(context, :path => path.to_s)
|
41
|
+
end
|
42
|
+
|
43
|
+
class Env # a CommonJS like environment (inspired by commonjs.rb)
|
44
|
+
|
45
|
+
attr_reader :context, :modules
|
46
|
+
|
47
|
+
def initialize(context, options = {})
|
48
|
+
@context = context
|
49
|
+
@paths = [ options[:path] ].flatten.map { |path| Pathname(path) }
|
50
|
+
@modules = {}
|
51
|
+
end
|
52
|
+
|
53
|
+
def require(module_id)
|
54
|
+
unless mod = modules[module_id]
|
55
|
+
filepath = find(module_id) or fail LoadError, "no such module '#{module_id}'"
|
56
|
+
js = "( function(module, require, exports) {\n#{File.read(filepath)}\n} )"
|
57
|
+
load = context.eval(js, filepath.expand_path.to_s)
|
58
|
+
modules[module_id] = mod = Module.new(module_id, self)
|
59
|
+
load.call(mod, mod.require_function, mod.exports)
|
60
|
+
end
|
61
|
+
return mod.exports
|
62
|
+
end
|
63
|
+
|
64
|
+
def native(module_id, impl)
|
65
|
+
modules[module_id] = Module::Native.new(impl)
|
66
|
+
end
|
67
|
+
|
68
|
+
def new_object
|
69
|
+
context['Object'].new
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def find(module_id)
|
75
|
+
if loadpath = @paths.find { |path| path.join("#{module_id}.js").exist? }
|
76
|
+
loadpath.join("#{module_id}.js")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Module
|
81
|
+
|
82
|
+
attr_reader :id, :exports
|
83
|
+
|
84
|
+
def initialize(id, env)
|
85
|
+
@id, @env = id, env
|
86
|
+
@exports = env.new_object
|
87
|
+
@segments = id.split('/')
|
88
|
+
end
|
89
|
+
|
90
|
+
def require_function
|
91
|
+
@require_function ||= lambda do |*args|
|
92
|
+
this, module_id = *args
|
93
|
+
module_id ||= this #backwards compatibility with TRR < 0.10
|
94
|
+
@env.require(expand(module_id))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def expand(module_id)
|
101
|
+
return module_id unless module_id =~ /(\.|\..)/
|
102
|
+
module_id.split('/').inject(@segments[0..-2]) do |path, element|
|
103
|
+
path.tap do
|
104
|
+
if element == '.'
|
105
|
+
#do nothing
|
106
|
+
elsif element == '..'
|
107
|
+
path.pop
|
108
|
+
else
|
109
|
+
path.push element
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end.join('/')
|
113
|
+
end
|
114
|
+
|
115
|
+
class Native
|
116
|
+
|
117
|
+
def initialize(impl); @impl = impl; end
|
118
|
+
def exports; @impl; end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
class Util
|
127
|
+
|
128
|
+
def initialize(io = STDOUT)
|
129
|
+
@io = io
|
130
|
+
end
|
131
|
+
|
132
|
+
def puts(*args)
|
133
|
+
args.each { |arg| @io.puts(arg) }
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
class Console
|
139
|
+
|
140
|
+
def self.log(*msgs)
|
141
|
+
puts msgs.join(', ')
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -1,5 +1,19 @@
|
|
1
1
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
+
module RhinoHelpers
|
4
|
+
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def add_prototype_key(hash, recurse = false)
|
8
|
+
hash['prototype'] ||= {}
|
9
|
+
hash.keys.each do |key|
|
10
|
+
val = hash[key] unless key == 'prototype'
|
11
|
+
add_prototype_key(val, recurse) if val.is_a?(Hash)
|
12
|
+
end if recurse
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
3
17
|
shared_examples_for 'ScriptableObject', :shared => true do
|
4
18
|
|
5
19
|
it "acts like a hash" do
|
@@ -40,7 +54,7 @@ describe "NativeObject" do
|
|
40
54
|
end
|
41
55
|
|
42
56
|
describe "FunctionObject" do
|
43
|
-
|
57
|
+
|
44
58
|
before do
|
45
59
|
factory = Rhino::JS::ContextFactory.new
|
46
60
|
context, scope = nil, nil
|
@@ -54,7 +68,9 @@ describe "FunctionObject" do
|
|
54
68
|
@object = Rhino::JS::FunctionObject.new('to_string', to_string, scope)
|
55
69
|
@object.instance_eval do
|
56
70
|
def to_h_properties
|
57
|
-
{ "arguments"=> nil, "
|
71
|
+
h = { "arguments"=> nil, "name"=> "to_string", "arity"=> 0, "length"=> 0 }
|
72
|
+
RhinoHelpers.add_prototype_key(h) if Rhino.implementation_version < '1.7R4'
|
73
|
+
h
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
@@ -115,7 +131,7 @@ describe "NativeObject (scoped)" do
|
|
115
131
|
end
|
116
132
|
|
117
133
|
describe "NativeFunction" do
|
118
|
-
|
134
|
+
|
119
135
|
before do
|
120
136
|
factory = Rhino::JS::ContextFactory.new
|
121
137
|
@context, @scope = nil, nil
|
@@ -129,7 +145,9 @@ describe "NativeFunction" do
|
|
129
145
|
@object = Rhino::JS::ScriptableObject.getProperty(object, 'toString')
|
130
146
|
@object.instance_eval do
|
131
147
|
def to_h_properties
|
132
|
-
{ "arguments"=> nil, "
|
148
|
+
h = { "arguments"=> nil, "name"=> "toString", "arity"=> 0, "length"=> 0 }
|
149
|
+
RhinoHelpers.add_prototype_key(h) if Rhino.implementation_version < '1.7R4'
|
150
|
+
h
|
133
151
|
end
|
134
152
|
end
|
135
153
|
end
|
@@ -187,7 +205,7 @@ describe "NativeFunction" do
|
|
187
205
|
end
|
188
206
|
|
189
207
|
describe "NativeFunction (constructor)" do
|
190
|
-
|
208
|
+
|
191
209
|
before do
|
192
210
|
factory = Rhino::JS::ContextFactory.new
|
193
211
|
context, scope = nil, nil
|
@@ -200,23 +218,25 @@ describe "NativeFunction (constructor)" do
|
|
200
218
|
@object = Rhino::JS::ScriptableObject.getProperty(context.newObject(scope), 'constructor')
|
201
219
|
@object.instance_eval do
|
202
220
|
def to_h_properties
|
203
|
-
{
|
221
|
+
h = {
|
204
222
|
"arguments"=>nil, "prototype"=>{}, "name"=>"Object", "arity"=>1, "length"=>1,
|
205
223
|
|
206
|
-
"getPrototypeOf"=> { "arguments"=>nil, "
|
207
|
-
"keys"=>{"arguments"=>nil, "
|
208
|
-
"getOwnPropertyNames"=>{"arguments"=>nil, "
|
209
|
-
"getOwnPropertyDescriptor"=>{"arguments"=>nil, "
|
210
|
-
"defineProperty"=>{"arguments"=>nil, "
|
211
|
-
"isExtensible"=>{"arguments"=>nil, "
|
212
|
-
"preventExtensions"=>{"arguments"=>nil, "
|
213
|
-
"defineProperties"=>{"arguments"=>nil, "
|
214
|
-
"create"=>{"arguments"=>nil, "
|
215
|
-
"isSealed"=>{"arguments"=>nil, "
|
216
|
-
"isFrozen"=>{"arguments"=>nil, "
|
217
|
-
"seal"=>{"arguments"=>nil, "
|
218
|
-
"freeze"=>{"arguments"=>nil, "
|
224
|
+
"getPrototypeOf"=> { "arguments"=>nil, "name"=>"getPrototypeOf", "arity"=>1, "length"=>1},
|
225
|
+
"keys"=>{"arguments"=>nil, "name"=>"keys", "arity"=>1, "length"=>1},
|
226
|
+
"getOwnPropertyNames"=>{"arguments"=>nil, "name"=>"getOwnPropertyNames", "arity"=>1, "length"=>1},
|
227
|
+
"getOwnPropertyDescriptor"=>{"arguments"=>nil, "name"=>"getOwnPropertyDescriptor", "arity"=>2, "length"=>2},
|
228
|
+
"defineProperty"=>{"arguments"=>nil, "name"=>"defineProperty", "arity"=>3, "length"=>3},
|
229
|
+
"isExtensible"=>{"arguments"=>nil, "name"=>"isExtensible", "arity"=>1, "length"=>1},
|
230
|
+
"preventExtensions"=>{"arguments"=>nil, "name"=>"preventExtensions", "arity"=>1, "length"=>1},
|
231
|
+
"defineProperties"=>{"arguments"=>nil, "name"=>"defineProperties", "arity"=>2, "length"=>2},
|
232
|
+
"create"=>{"arguments"=>nil, "name"=>"create", "arity"=>2, "length"=>2},
|
233
|
+
"isSealed"=>{"arguments"=>nil, "name"=>"isSealed", "arity"=>1, "length"=>1},
|
234
|
+
"isFrozen"=>{"arguments"=>nil, "name"=>"isFrozen", "arity"=>1, "length"=>1},
|
235
|
+
"seal"=>{"arguments"=>nil, "name"=>"seal", "arity"=>1, "length"=>1},
|
236
|
+
"freeze"=>{"arguments"=>nil, "name"=>"freeze", "arity"=>1, "length"=>1}
|
219
237
|
}
|
238
|
+
RhinoHelpers.add_prototype_key(h, :recurse) if Rhino.implementation_version < '1.7R4'
|
239
|
+
h
|
220
240
|
end
|
221
241
|
end
|
222
242
|
end
|
data/spec/rhino/wormhole_spec.rb
CHANGED
@@ -5,52 +5,48 @@ describe Rhino::To do
|
|
5
5
|
describe "ruby translation" do
|
6
6
|
|
7
7
|
it "converts javascript NOT_FOUND to ruby nil" do
|
8
|
-
Rhino.to_ruby(Rhino::JS::Scriptable::NOT_FOUND).should
|
8
|
+
Rhino.to_ruby(Rhino::JS::Scriptable::NOT_FOUND).should be nil
|
9
9
|
end
|
10
10
|
|
11
11
|
it "converts javascript undefined into nil" do
|
12
|
-
Rhino.to_ruby(Rhino::JS::Undefined.instance).should
|
12
|
+
Rhino.to_ruby(Rhino::JS::Undefined.instance).should be nil
|
13
13
|
end
|
14
14
|
|
15
15
|
it "does return javascript object" do
|
16
16
|
Rhino::JS::NativeObject.new.tap do |js_obj|
|
17
|
-
Rhino.to_ruby(js_obj).
|
18
|
-
rb_obj.should be(js_obj)
|
19
|
-
end
|
17
|
+
Rhino.to_ruby(js_obj).should be(js_obj)
|
20
18
|
end
|
21
19
|
end
|
22
20
|
|
23
21
|
it "wraps native javascript arrays into a ruby NativeArray wrapper" do
|
24
|
-
Rhino::JS::NativeArray.new([1,2,4].to_java)
|
25
|
-
|
26
|
-
end
|
22
|
+
js_array = Rhino::JS::NativeArray.new([1,2,4].to_java)
|
23
|
+
Rhino.to_ruby(js_array).should == [1,2,4]
|
27
24
|
end
|
28
25
|
|
29
|
-
it "
|
30
|
-
|
26
|
+
it "returns a javascript function" do
|
31
27
|
klass = Class.new(Rhino::JS::BaseFunction)
|
32
|
-
|
33
|
-
|
34
|
-
Rhino.to_ruby(js_fn).tap do |rb_fn|
|
35
|
-
rb_fn.should be(js_fn)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
28
|
+
function = klass.new
|
29
|
+
Rhino.to_ruby(function).should be(function)
|
39
30
|
end
|
40
31
|
|
41
32
|
it "leaves native ruby objects alone" do
|
42
|
-
Object.new
|
43
|
-
|
44
|
-
end
|
33
|
+
obj = Object.new
|
34
|
+
Rhino.to_ruby(obj).should be(obj)
|
45
35
|
end
|
46
36
|
|
47
37
|
it "it unwraps wrapped java objects" do
|
48
38
|
Rhino::Context.open do |cx|
|
49
39
|
scope = cx.scope
|
50
40
|
j_str = java.lang.String.new("Hello World")
|
51
|
-
Rhino::JS::NativeJavaObject.new(scope, j_str, j_str.getClass())
|
52
|
-
|
53
|
-
|
41
|
+
native_obj = Rhino::JS::NativeJavaObject.new(scope, j_str, j_str.getClass())
|
42
|
+
Rhino.to_ruby(native_obj).should == "Hello World"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if (Java::JavaClass.for_name('org.mozilla.javascript.ConsString') rescue nil)
|
47
|
+
it "converts a cons string" do
|
48
|
+
cons_string = org.mozilla.javascript.ConsString.new('1', '2')
|
49
|
+
Rhino.to_ruby(cons_string).should == '12'
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
data/spec/spec_helper.rb
CHANGED
data/therubyrhino.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_dependency "therubyrhino_jar", '>= 1.7.3'
|
22
22
|
|
23
23
|
s.add_development_dependency "rake"
|
24
|
-
s.add_development_dependency "rspec", "
|
24
|
+
s.add_development_dependency "rspec", "~> 2.10"
|
25
25
|
s.add_development_dependency "mocha"
|
26
26
|
s.add_development_dependency "jruby-openssl"
|
27
27
|
end
|
metadata
CHANGED
@@ -1,141 +1,142 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: therubyrhino
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 2.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 2.0.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
|
9
|
-
autorequire:
|
7
|
+
authors:
|
8
|
+
- Charles Lowell
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
type: :development
|
12
|
+
date: 2012-08-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: therubyrhino_jar
|
16
|
+
version_requirements: &3954 !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.7.3
|
21
|
+
none: false
|
22
|
+
requirement: *3954
|
23
|
+
prerelease: false
|
24
|
+
type: :runtime
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
version_requirements: &3972 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
none: false
|
33
|
+
requirement: *3972
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
version_requirements: &3990 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.10'
|
43
|
+
none: false
|
44
|
+
requirement: *3990
|
45
|
+
prerelease: false
|
46
|
+
type: :development
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
version_requirements: &4006 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
none: false
|
55
|
+
requirement: *4006
|
56
|
+
prerelease: false
|
57
|
+
type: :development
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jruby-openssl
|
60
|
+
version_requirements: &4022 !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
none: false
|
66
|
+
requirement: *4022
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
70
69
|
description: Call javascript code and manipulate javascript objects from ruby. Call ruby code and manipulate ruby objects from javascript.
|
71
70
|
email: cowboyd@thefrontside.net
|
72
71
|
executables: []
|
73
|
-
|
74
72
|
extensions: []
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
73
|
+
extra_rdoc_files:
|
74
|
+
- README.rdoc
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- History.txt
|
80
|
+
- README.rdoc
|
81
|
+
- Rakefile
|
82
|
+
- lib/rhino.rb
|
83
|
+
- lib/rhino/context.rb
|
84
|
+
- lib/rhino/deprecations.rb
|
85
|
+
- lib/rhino/error.rb
|
86
|
+
- lib/rhino/object.rb
|
87
|
+
- lib/rhino/rhino_ext.rb
|
88
|
+
- lib/rhino/ruby.rb
|
89
|
+
- lib/rhino/ruby/access.rb
|
90
|
+
- lib/rhino/ruby/attribute_access.rb
|
91
|
+
- lib/rhino/ruby/default_access.rb
|
92
|
+
- lib/rhino/version.rb
|
93
|
+
- lib/rhino/wormhole.rb
|
94
|
+
- spec/rhino/access_spec.rb
|
95
|
+
- spec/rhino/context_spec.rb
|
96
|
+
- spec/rhino/deprecations_spec.rb
|
97
|
+
- spec/rhino/error_spec.rb
|
98
|
+
- spec/rhino/integration/bar.js
|
99
|
+
- spec/rhino/integration/foo.js
|
100
|
+
- spec/rhino/integration/index.js
|
101
|
+
- spec/rhino/integration/loop.js
|
102
|
+
- spec/rhino/integration/loop/element1.js
|
103
|
+
- spec/rhino/integration/loop/element2.js
|
104
|
+
- spec/rhino/integration_spec.rb
|
105
|
+
- spec/rhino/redjs_spec.rb
|
106
|
+
- spec/rhino/rhino_ext_spec.rb
|
107
|
+
- spec/rhino/ruby_spec.rb
|
108
|
+
- spec/rhino/wormhole_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- therubyrhino.gemspec
|
107
111
|
homepage: http://github.com/cowboyd/therubyrhino
|
108
112
|
licenses: []
|
109
|
-
|
110
|
-
post_install_message:
|
113
|
+
post_install_message:
|
111
114
|
rdoc_options: []
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
hash: 2
|
124
|
+
version: '0'
|
116
125
|
none: false
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
segments:
|
131
|
+
- 0
|
132
|
+
hash: 2
|
133
|
+
version: '0'
|
125
134
|
none: false
|
126
|
-
requirements:
|
127
|
-
- - ">="
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
hash: 2
|
130
|
-
segments:
|
131
|
-
- 0
|
132
|
-
version: "0"
|
133
135
|
requirements: []
|
134
|
-
|
135
136
|
rubyforge_project: therubyrhino
|
136
137
|
rubygems_version: 1.8.15
|
137
|
-
signing_key:
|
138
|
+
signing_key:
|
138
139
|
specification_version: 3
|
139
140
|
summary: Embed the Rhino JavaScript interpreter into JRuby
|
140
141
|
test_files: []
|
141
|
-
|
142
|
+
...
|