mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Use 1.9 syntax
This commit is contained in:
parent
686692e0db
commit
14748fc693
5 changed files with 25 additions and 25 deletions
4
Gemfile
4
Gemfile
|
@ -3,6 +3,6 @@ source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'therubyracer', :platform => :mri
|
gem 'therubyracer', platform: :mri
|
||||||
gem 'therubyrhino', ">=1.73.3", :platform => :jruby
|
gem 'therubyrhino', ">=1.73.3", platform: :jruby
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,7 +31,7 @@ require "open-uri"
|
||||||
source = open("http://coffeescript.org/extras/coffee-script.js").read
|
source = open("http://coffeescript.org/extras/coffee-script.js").read
|
||||||
|
|
||||||
context = ExecJS.compile(source)
|
context = ExecJS.compile(source)
|
||||||
context.call("CoffeeScript.compile", "square = (x) -> x * x", :bare => true)
|
context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
|
||||||
# => "var square;\nsquare = function(x) {\n return x * x;\n};"
|
# => "var square;\nsquare = function(x) {\n return x * x;\n};"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ module ExecJS
|
||||||
source = encode(source)
|
source = encode(source)
|
||||||
|
|
||||||
if /\S/ =~ source
|
if /\S/ =~ source
|
||||||
exec("return eval(#{::JSON.generate("(#{source})", :quirks_mode => true)})")
|
exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ module ExecJS
|
||||||
end
|
end
|
||||||
output.sub!('#{encoded_source}') do
|
output.sub!('#{encoded_source}') do
|
||||||
encoded_source = encode_unicode_codepoints(source)
|
encoded_source = encode_unicode_codepoints(source)
|
||||||
::JSON.generate("(function(){ #{encoded_source} })()", :quirks_mode => true)
|
::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
|
||||||
end
|
end
|
||||||
output.sub!('#{json2_source}') do
|
output.sub!('#{json2_source}') do
|
||||||
IO.read(ExecJS.root + "/support/json2.js")
|
IO.read(ExecJS.root + "/support/json2.js")
|
||||||
|
@ -59,7 +59,7 @@ module ExecJS
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_result(output)
|
def extract_result(output)
|
||||||
status, value = output.empty? ? [] : ::JSON.parse(output, :create_additions => false)
|
status, value = output.empty? ? [] : ::JSON.parse(output, create_additions: false)
|
||||||
if status == "ok"
|
if status == "ok"
|
||||||
value
|
value
|
||||||
elsif value =~ /SyntaxError:/
|
elsif value =~ /SyntaxError:/
|
||||||
|
|
|
@ -19,30 +19,30 @@ module ExecJS
|
||||||
Mustang = MustangRuntime.new
|
Mustang = MustangRuntime.new
|
||||||
|
|
||||||
Node = ExternalRuntime.new(
|
Node = ExternalRuntime.new(
|
||||||
:name => "Node.js (V8)",
|
name: "Node.js (V8)",
|
||||||
:command => ["nodejs", "node"],
|
command: ["nodejs", "node"],
|
||||||
:runner_path => ExecJS.root + "/support/node_runner.js",
|
runner_path: ExecJS.root + "/support/node_runner.js",
|
||||||
:encoding => 'UTF-8'
|
encoding: 'UTF-8'
|
||||||
)
|
)
|
||||||
|
|
||||||
JavaScriptCore = ExternalRuntime.new(
|
JavaScriptCore = ExternalRuntime.new(
|
||||||
:name => "JavaScriptCore",
|
name: "JavaScriptCore",
|
||||||
:command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
|
command: "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
|
||||||
:runner_path => ExecJS.root + "/support/jsc_runner.js"
|
runner_path: ExecJS.root + "/support/jsc_runner.js"
|
||||||
)
|
)
|
||||||
|
|
||||||
SpiderMonkey = Spidermonkey = ExternalRuntime.new(
|
SpiderMonkey = Spidermonkey = ExternalRuntime.new(
|
||||||
:name => "SpiderMonkey",
|
name: "SpiderMonkey",
|
||||||
:command => "js",
|
command: "js",
|
||||||
:runner_path => ExecJS.root + "/support/spidermonkey_runner.js",
|
runner_path: ExecJS.root + "/support/spidermonkey_runner.js",
|
||||||
:deprecated => true
|
deprecated: true
|
||||||
)
|
)
|
||||||
|
|
||||||
JScript = ExternalRuntime.new(
|
JScript = ExternalRuntime.new(
|
||||||
:name => "JScript",
|
name: "JScript",
|
||||||
:command => "cscript //E:jscript //Nologo //U",
|
command: "cscript //E:jscript //Nologo //U",
|
||||||
:runner_path => ExecJS.root + "/support/jscript_runner.js",
|
runner_path: ExecJS.root + "/support/jscript_runner.js",
|
||||||
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
|
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,20 +17,20 @@ end
|
||||||
|
|
||||||
class TestExecJS < Test
|
class TestExecJS < Test
|
||||||
def test_runtime_available
|
def test_runtime_available
|
||||||
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
|
runtime = ExecJS::ExternalRuntime.new(command: "nonexistent")
|
||||||
assert !runtime.available?
|
assert !runtime.available?
|
||||||
|
|
||||||
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
|
runtime = ExecJS::ExternalRuntime.new(command: "ruby")
|
||||||
assert runtime.available?
|
assert runtime.available?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_runtime_assignment
|
def test_runtime_assignment
|
||||||
original_runtime = ExecJS.runtime
|
original_runtime = ExecJS.runtime
|
||||||
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
|
runtime = ExecJS::ExternalRuntime.new(command: "nonexistent")
|
||||||
assert_raises(ExecJS::RuntimeUnavailable) { ExecJS.runtime = runtime }
|
assert_raises(ExecJS::RuntimeUnavailable) { ExecJS.runtime = runtime }
|
||||||
assert_equal original_runtime, ExecJS.runtime
|
assert_equal original_runtime, ExecJS.runtime
|
||||||
|
|
||||||
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
|
runtime = ExecJS::ExternalRuntime.new(command: "ruby")
|
||||||
ExecJS.runtime = runtime
|
ExecJS.runtime = runtime
|
||||||
assert_equal runtime, ExecJS.runtime
|
assert_equal runtime, ExecJS.runtime
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in a new issue