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
b6700b4b8b
commit
fe55c29464
5 changed files with 25 additions and 25 deletions
4
Gemfile
4
Gemfile
|
@ -3,6 +3,6 @@ source 'https://rubygems.org'
|
|||
gemspec
|
||||
|
||||
group :test do
|
||||
gem 'therubyracer', :platform => :mri
|
||||
gem 'therubyrhino', ">=1.73.3", :platform => :jruby
|
||||
gem 'therubyracer', platform: :mri
|
||||
gem 'therubyrhino', ">=1.73.3", platform: :jruby
|
||||
end
|
||||
|
|
|
@ -31,7 +31,7 @@ require "open-uri"
|
|||
source = open("http://coffeescript.org/extras/coffee-script.js").read
|
||||
|
||||
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};"
|
||||
```
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ module ExecJS
|
|||
source = encode(source)
|
||||
|
||||
if /\S/ =~ source
|
||||
exec("return eval(#{::JSON.generate("(#{source})", :quirks_mode => true)})")
|
||||
exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,7 +49,7 @@ module ExecJS
|
|||
end
|
||||
output.sub!('#{encoded_source}') do
|
||||
encoded_source = encode_unicode_codepoints(source)
|
||||
::JSON.generate("(function(){ #{encoded_source} })()", :quirks_mode => true)
|
||||
::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
|
||||
end
|
||||
output.sub!('#{json2_source}') do
|
||||
IO.read(ExecJS.root + "/support/json2.js")
|
||||
|
@ -58,7 +58,7 @@ module ExecJS
|
|||
end
|
||||
|
||||
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"
|
||||
value
|
||||
elsif value =~ /SyntaxError:/
|
||||
|
|
|
@ -19,30 +19,30 @@ module ExecJS
|
|||
Mustang = MustangRuntime.new
|
||||
|
||||
Node = ExternalRuntime.new(
|
||||
:name => "Node.js (V8)",
|
||||
:command => ["nodejs", "node"],
|
||||
:runner_path => ExecJS.root + "/support/node_runner.js",
|
||||
:encoding => 'UTF-8'
|
||||
name: "Node.js (V8)",
|
||||
command: ["nodejs", "node"],
|
||||
runner_path: ExecJS.root + "/support/node_runner.js",
|
||||
encoding: 'UTF-8'
|
||||
)
|
||||
|
||||
JavaScriptCore = ExternalRuntime.new(
|
||||
:name => "JavaScriptCore",
|
||||
:command => "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
|
||||
:runner_path => ExecJS.root + "/support/jsc_runner.js"
|
||||
name: "JavaScriptCore",
|
||||
command: "/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc",
|
||||
runner_path: ExecJS.root + "/support/jsc_runner.js"
|
||||
)
|
||||
|
||||
SpiderMonkey = Spidermonkey = ExternalRuntime.new(
|
||||
:name => "SpiderMonkey",
|
||||
:command => "js",
|
||||
:runner_path => ExecJS.root + "/support/spidermonkey_runner.js",
|
||||
:deprecated => true
|
||||
name: "SpiderMonkey",
|
||||
command: "js",
|
||||
runner_path: ExecJS.root + "/support/spidermonkey_runner.js",
|
||||
deprecated: true
|
||||
)
|
||||
|
||||
JScript = ExternalRuntime.new(
|
||||
:name => "JScript",
|
||||
:command => "cscript //E:jscript //Nologo //U",
|
||||
:runner_path => ExecJS.root + "/support/jscript_runner.js",
|
||||
:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE
|
||||
name: "JScript",
|
||||
command: "cscript //E:jscript //Nologo //U",
|
||||
runner_path: ExecJS.root + "/support/jscript_runner.js",
|
||||
encoding: 'UTF-16LE' # CScript with //U returns UTF-16LE
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -17,20 +17,20 @@ end
|
|||
|
||||
class TestExecJS < Test
|
||||
def test_runtime_available
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
|
||||
runtime = ExecJS::ExternalRuntime.new(command: "nonexistent")
|
||||
assert !runtime.available?
|
||||
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
|
||||
runtime = ExecJS::ExternalRuntime.new(command: "ruby")
|
||||
assert runtime.available?
|
||||
end
|
||||
|
||||
def test_runtime_assignment
|
||||
original_runtime = ExecJS.runtime
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "nonexistent")
|
||||
runtime = ExecJS::ExternalRuntime.new(command: "nonexistent")
|
||||
assert_raises(ExecJS::RuntimeUnavailable) { ExecJS.runtime = runtime }
|
||||
assert_equal original_runtime, ExecJS.runtime
|
||||
|
||||
runtime = ExecJS::ExternalRuntime.new(:command => "ruby")
|
||||
runtime = ExecJS::ExternalRuntime.new(command: "ruby")
|
||||
ExecJS.runtime = runtime
|
||||
assert_equal runtime, ExecJS.runtime
|
||||
ensure
|
||||
|
|
Loading…
Reference in a new issue