[DRE-commits] [ruby-execjs] 01/09: Imported Upstream version 2.2.1
Caitlin Matos
cm-guest at moszumanska.debian.org
Sat Jul 26 03:26:49 UTC 2014
This is an automated email from the git hooks/post-receive script.
cm-guest pushed a commit to branch master
in repository ruby-execjs.
commit 64aee2fa112af157b89f9d6328d1bae8a7c62335
Author: Caitlin Matos <caitlin.matos at zoho.com>
Date: Thu Jul 24 20:25:41 2014 -0400
Imported Upstream version 2.2.1
---
LICENSE | 4 +-
README.md | 40 ++++++---
checksums.yaml.gz | Bin 0 -> 268 bytes
lib/execjs/encoding.rb | 33 +++-----
lib/execjs/external_runtime.rb | 160 ++++++++++++++---------------------
lib/execjs/johnson_runtime.rb | 4 +-
lib/execjs/json.rb | 23 -----
lib/execjs/ruby_racer_runtime.rb | 4 +-
lib/execjs/runtimes.rb | 30 +++----
lib/execjs/support/jsc_runner.js | 2 +-
lib/execjs/support/jscript_runner.js | 2 +-
lib/execjs/version.rb | 2 +-
metadata.yml | 106 ++++++++---------------
13 files changed, 161 insertions(+), 249 deletions(-)
diff --git a/LICENSE b/LICENSE
index 0db3dc6..3b3cdd6 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
-Copyright (c) 2011 Sam Stephenson
-Copyright (c) 2011 Josh Peek
+Copyright (c) 2014 Sam Stephenson
+Copyright (c) 2014 Josh Peek
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/README.md b/README.md
index 85151cb..92f812c 100644
--- a/README.md
+++ b/README.md
@@ -17,26 +17,44 @@ ExecJS supports these runtimes:
A short example:
- require "execjs"
- ExecJS.eval "'red yellow blue'.split(' ')"
- # => ["red", "yellow", "blue"]
+``` ruby
+require "execjs"
+ExecJS.eval "'red yellow blue'.split(' ')"
+# => ["red", "yellow", "blue"]
+```
A longer example, demonstrating how to invoke the CoffeeScript compiler:
- require "execjs"
- require "open-uri"
- source = open("http://jashkenas.github.com/coffee-script/extras/coffee-script.js").read
+``` ruby
+require "execjs"
+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)
- # => "var square;\nsquare = function(x) {\n return x * x;\n};"
+context = ExecJS.compile(source)
+context.call("CoffeeScript.compile", "square = (x) -> x * x", bare: true)
+# => "var square;\nsquare = function(x) {\n return x * x;\n};"
+```
# Installation
- $ gem install execjs
+```
+$ gem install execjs
+```
+
+
+# FAQ
+
+**Why can't I use CommonJS `require()` inside ExecJS?**
+
+ExecJS provides a lowest common denominator interface to any JavaScript runtime.
+Use ExecJS when it doesn't matter which JavaScript interpreter your code runs
+in. If you want to access the Node API, you should check another library like
+[commonjs.rb](https://github.com/cowboyd/commonjs.rb) designed to provide a
+consistent interface.
+
# License
-Copyright (c) 2011 Sam Stephenson and Josh Peek.
+Copyright (c) 2014 Sam Stephenson and Josh Peek.
Released under the MIT license. See `LICENSE` for details.
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
new file mode 100644
index 0000000..9aa02d4
Binary files /dev/null and b/checksums.yaml.gz differ
diff --git a/lib/execjs/encoding.rb b/lib/execjs/encoding.rb
index 3a74927..406fb0d 100644
--- a/lib/execjs/encoding.rb
+++ b/lib/execjs/encoding.rb
@@ -1,32 +1,25 @@
module ExecJS
# Encodes strings as UTF-8
module Encoding
- if "".respond_to?(:encode)
- if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
- # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
- # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
- def encode(string)
- if string.encoding.name == 'ASCII-8BIT'
- data = string.dup
- data.force_encoding('UTF-8')
+ if RUBY_ENGINE == 'jruby' || RUBY_ENGINE == 'rbx'
+ # workaround for jruby bug http://jira.codehaus.org/browse/JRUBY-6588
+ # workaround for rbx bug https://github.com/rubinius/rubinius/issues/1729
+ def encode(string)
+ if string.encoding.name == 'ASCII-8BIT'
+ data = string.dup
+ data.force_encoding('UTF-8')
- unless data.valid_encoding?
- raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
- end
- else
- data = string.encode('UTF-8')
+ unless data.valid_encoding?
+ raise ::Encoding::UndefinedConversionError, "Could not encode ASCII-8BIT data #{string.dump} as UTF-8"
end
- data
- end
- else
- def encode(string)
- string.encode('UTF-8')
+ else
+ data = string.encode('UTF-8')
end
+ data
end
else
- # Define no-op on 1.8
def encode(string)
- string
+ string.encode('UTF-8')
end
end
end
diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb
index 4877975..c7a89a1 100644
--- a/lib/execjs/external_runtime.rb
+++ b/lib/execjs/external_runtime.rb
@@ -1,5 +1,4 @@
-require "shellwords"
-require "tempfile"
+require "tmpdir"
require "execjs/runtime"
module ExecJS
@@ -16,50 +15,47 @@ module ExecJS
source = encode(source)
if /\S/ =~ source
- exec("return eval(#{JSON.encode("(#{source})")})")
+ exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
end
end
def exec(source, options = {})
source = encode(source)
source = "#{@source}\n#{source}" if @source
+ source = @runtime.compile_source(source)
- compile_to_tempfile(source) do |file|
- extract_result(@runtime.send(:exec_runtime, file.path))
+ tmpfile = write_to_tempfile(source)
+ begin
+ extract_result(@runtime.exec_runtime(tmpfile.path))
+ ensure
+ File.unlink(tmpfile)
end
end
def call(identifier, *args)
- eval "#{identifier}.apply(this, #{JSON.encode(args)})"
+ eval "#{identifier}.apply(this, #{::JSON.generate(args)})"
end
protected
- def compile_to_tempfile(source)
- tempfile = Tempfile.open(['execjs', '.js'])
- tempfile.write compile(source)
- tempfile.close
- yield tempfile
- ensure
- tempfile.close!
+ # See Tempfile.create on Ruby 2.1
+ def create_tempfile(basename)
+ tmpfile = nil
+ Dir::Tmpname.create(basename) do |tmpname|
+ mode = File::WRONLY | File::CREAT | File::EXCL
+ tmpfile = File.open(tmpname, mode, 0600)
+ end
+ tmpfile
end
- def compile(source)
- @runtime.send(:runner_source).dup.tap do |output|
- output.sub!('#{source}') do
- source
- end
- output.sub!('#{encoded_source}') do
- encoded_source = encode_unicode_codepoints(source)
- JSON.encode("(function(){ #{encoded_source} })()")
- end
- output.sub!('#{json2_source}') do
- IO.read(ExecJS.root + "/support/json2.js")
- end
- end
+ def write_to_tempfile(contents)
+ tmpfile = create_tempfile(['execjs', 'js'])
+ tmpfile.write(contents)
+ tmpfile.close
+ tmpfile
end
def extract_result(output)
- status, value = output.empty? ? [] : JSON.decode(output)
+ status, value = output.empty? ? [] : ::JSON.parse(output, create_additions: false)
if status == "ok"
value
elsif value =~ /SyntaxError:/
@@ -68,22 +64,6 @@ module ExecJS
raise ProgramError, value
end
end
-
- if "".respond_to?(:codepoints)
- def encode_unicode_codepoints(str)
- str.gsub(/[\u0080-\uffff]/) do |ch|
- "\\u%04x" % ch.codepoints.to_a
- end
- end
- else
- def encode_unicode_codepoints(str)
- str.gsub(/([\xC0-\xDF][\x80-\xBF]|
- [\xE0-\xEF][\x80-\xBF]{2}|
- [\xF0-\xF7][\x80-\xBF]{3})+/nx) do |ch|
- "\\u%04x" % ch.unpack("U*")
- end
- end
- end
end
attr_reader :name
@@ -92,15 +72,21 @@ module ExecJS
@name = options[:name]
@command = options[:command]
@runner_path = options[:runner_path]
- @test_args = options[:test_args]
- @test_match = options[:test_match]
@encoding = options[:encoding]
@deprecated = !!options[:deprecated]
@binary = nil
+
+ @popen_options = {}
+ @popen_options[:external_encoding] = @encoding if @encoding
+ @popen_options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
+
+ if @runner_path
+ instance_eval generate_compile_method(@runner_path)
+ end
end
def available?
- require "execjs/json"
+ require 'json'
binary ? true : false
end
@@ -110,7 +96,7 @@ module ExecJS
private
def binary
- @binary ||= locate_binary
+ @binary ||= which(@command)
end
def locate_executable(cmd)
@@ -130,29 +116,44 @@ module ExecJS
end
protected
- def runner_source
- @runner_source ||= IO.read(@runner_path)
+ def generate_compile_method(path)
+ <<-RUBY
+ def compile_source(source)
+ <<-RUNNER
+ #{IO.read(path)}
+ RUNNER
+ end
+ RUBY
+ end
+
+ def json2_source
+ @json2_source ||= IO.read(ExecJS.root + "/support/json2.js")
+ end
+
+ def encode_source(source)
+ encoded_source = encode_unicode_codepoints(source)
+ ::JSON.generate("(function(){ #{encoded_source} })()", quirks_mode: true)
+ end
+
+ def encode_unicode_codepoints(str)
+ str.gsub(/[\u0080-\uffff]/) do |ch|
+ "\\u%04x" % ch.codepoints.to_a
+ end
end
def exec_runtime(filename)
- output = sh("#{shell_escape(*(binary.split(' ') << filename))} 2>&1")
+ io = IO.popen(binary.split(' ') << filename, @popen_options.merge({err: [:child, :out]}))
+ output = io.read
+ io.close
+
if $?.success?
output
else
raise RuntimeError, output
end
end
-
- def locate_binary
- if binary = which(@command)
- if @test_args
- output = `#{shell_escape(binary, @test_args)} 2>&1`
- binary if output.match(@test_match)
- else
- binary
- end
- end
- end
+ # Internally exposed for Context.
+ public :exec_runtime
def which(command)
Array(command).find do |name|
@@ -164,42 +165,5 @@ module ExecJS
args ? "#{path} #{args}" : path
end
end
-
- if "".respond_to?(:force_encoding)
- def sh(command)
- output, options = nil, {}
- options[:external_encoding] = @encoding if @encoding
- options[:internal_encoding] = ::Encoding.default_internal || 'UTF-8'
- IO.popen(command, options) { |f| output = f.read }
- output
- end
- else
- require "iconv"
-
- def sh(command)
- output = nil
- IO.popen(command) { |f| output = f.read }
-
- if @encoding
- Iconv.new('UTF-8', @encoding).iconv(output)
- else
- output
- end
- end
- end
-
- if ExecJS.windows?
- def shell_escape(*args)
- # see http://technet.microsoft.com/en-us/library/cc723564.aspx#XSLTsection123121120120
- args.map { |arg|
- arg = %Q("#{arg.gsub('"','""')}") if arg.match(/[&|()<>^ "]/)
- arg
- }.join(" ")
- end
- else
- def shell_escape(*args)
- Shellwords.join(args)
- end
- end
end
end
diff --git a/lib/execjs/johnson_runtime.rb b/lib/execjs/johnson_runtime.rb
index 4c42cd3..c47a618 100644
--- a/lib/execjs/johnson_runtime.rb
+++ b/lib/execjs/johnson_runtime.rb
@@ -47,9 +47,7 @@ module ExecJS
when function?(value)
nil
when string?(value)
- value.respond_to?(:force_encoding) ?
- value.force_encoding('UTF-8') :
- value
+ value.force_encoding('UTF-8')
when array?(value)
value.map { |v| unbox(v) }
when object?(value)
diff --git a/lib/execjs/json.rb b/lib/execjs/json.rb
deleted file mode 100644
index d6b135f..0000000
--- a/lib/execjs/json.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require "multi_json"
-
-module ExecJS
- module JSON
- if MultiJson.respond_to?(:dump)
- def self.decode(obj)
- MultiJson.load(obj)
- end
-
- def self.encode(obj)
- MultiJson.dump(obj)
- end
- else
- def self.decode(obj)
- MultiJson.decode(obj)
- end
-
- def self.encode(obj)
- MultiJson.encode(obj)
- end
- end
- end
-end
diff --git a/lib/execjs/ruby_racer_runtime.rb b/lib/execjs/ruby_racer_runtime.rb
index dfce4b3..f5bca9c 100644
--- a/lib/execjs/ruby_racer_runtime.rb
+++ b/lib/execjs/ruby_racer_runtime.rb
@@ -64,9 +64,7 @@ module ExecJS
vs
end
when String
- value.respond_to?(:force_encoding) ?
- value.force_encoding('UTF-8') :
- value
+ value.force_encoding('UTF-8')
else
value
end
diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb
index a26435d..969e7a6 100644
--- a/lib/execjs/runtimes.rb
+++ b/lib/execjs/runtimes.rb
@@ -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
)
diff --git a/lib/execjs/support/jsc_runner.js b/lib/execjs/support/jsc_runner.js
index a88a024..b7bc023 100644
--- a/lib/execjs/support/jsc_runner.js
+++ b/lib/execjs/support/jsc_runner.js
@@ -1,5 +1,5 @@
(function(program, execJS) { execJS(program) })(function() {
- return eval(#{encoded_source});
+ return eval(#{encode_source(source)});
}, function(program) {
var output;
try {
diff --git a/lib/execjs/support/jscript_runner.js b/lib/execjs/support/jscript_runner.js
index d27edf1..4619e56 100644
--- a/lib/execjs/support/jscript_runner.js
+++ b/lib/execjs/support/jscript_runner.js
@@ -1,5 +1,5 @@
(function(program, execJS) { execJS(program) })(function() {
- return eval(#{encoded_source});
+ return eval(#{encode_source(source)});
}, function(program) {
#{json2_source}
var output, print = function(string) {
diff --git a/lib/execjs/version.rb b/lib/execjs/version.rb
index f1988a4..4e40e43 100644
--- a/lib/execjs/version.rb
+++ b/lib/execjs/version.rb
@@ -1,3 +1,3 @@
module ExecJS
- VERSION = "1.4.0"
+ VERSION = "2.2.1"
end
diff --git a/metadata.yml b/metadata.yml
index 01a3547..8bffdfd 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,70 +1,45 @@
---- !ruby/object:Gem::Specification
+--- !ruby/object:Gem::Specification
name: execjs
-version: !ruby/object:Gem::Version
- hash: 7
- prerelease:
- segments:
- - 1
- - 4
- - 0
- version: 1.4.0
+version: !ruby/object:Gem::Version
+ version: 2.2.1
platform: ruby
-authors:
+authors:
- Sam Stephenson
- Josh Peek
autorequire:
bindir: bin
cert_chain: []
-
-date: 2012-05-20 00:00:00 Z
-dependencies:
-- !ruby/object:Gem::Dependency
- name: multi_json
- prerelease: false
- requirement: &id001 !ruby/object:Gem::Requirement
- none: false
- requirements:
- - - ~>
- - !ruby/object:Gem::Version
- hash: 15
- segments:
- - 1
- - 0
- version: "1.0"
- type: :runtime
- version_requirements: *id001
-- !ruby/object:Gem::Dependency
+date: 2014-06-26 00:00:00.000000000 Z
+dependencies:
+- !ruby/object:Gem::Dependency
name: rake
- prerelease: false
- requirement: &id002 !ruby/object:Gem::Requirement
- none: false
- requirements:
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
- - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ - !ruby/object:Gem::Version
+ version: '0'
type: :development
- version_requirements: *id002
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - ">="
+ - !ruby/object:Gem::Version
+ version: '0'
description: ExecJS lets you run JavaScript code from Ruby.
-email:
+email:
- sstephenson at gmail.com
- josh at joshpeek.com
executables: []
-
extensions: []
-
extra_rdoc_files: []
-
-files:
-- README.md
+files:
- LICENSE
+- README.md
+- lib/execjs.rb
- lib/execjs/disabled_runtime.rb
- lib/execjs/encoding.rb
- lib/execjs/external_runtime.rb
- lib/execjs/johnson_runtime.rb
-- lib/execjs/json.rb
- lib/execjs/module.rb
- lib/execjs/mustang_runtime.rb
- lib/execjs/ruby_racer_runtime.rb
@@ -77,39 +52,28 @@ files:
- lib/execjs/support/node_runner.js
- lib/execjs/support/spidermonkey_runner.js
- lib/execjs/version.rb
-- lib/execjs.rb
homepage: https://github.com/sstephenson/execjs
-licenses: []
-
+licenses:
+- MIT
+metadata: {}
post_install_message:
rdoc_options: []
-
-require_paths:
+require_paths:
- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
+required_ruby_version: !ruby/object:Gem::Requirement
+ requirements:
- - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement
- none: false
- requirements:
+ - !ruby/object:Gem::Version
+ version: '0'
+required_rubygems_version: !ruby/object:Gem::Requirement
+ requirements:
- - ">="
- - !ruby/object:Gem::Version
- hash: 3
- segments:
- - 0
- version: "0"
+ - !ruby/object:Gem::Version
+ version: '0'
requirements: []
-
rubyforge_project:
-rubygems_version: 1.8.15
+rubygems_version: 2.2.2
signing_key:
-specification_version: 3
+specification_version: 4
summary: Run JavaScript code from Ruby
test_files: []
-
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-execjs.git
More information about the Pkg-ruby-extras-commits
mailing list