[DRE-commits] [ruby-execjs] 02/04: Imported Upstream version 2.5.2

Antonio Terceiro terceiro at moszumanska.debian.org
Fri Aug 14 17:48:26 UTC 2015


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to branch master
in repository ruby-execjs.

commit 170f134f45fdd57945792c7a38c0228263236730
Author: Antonio Terceiro <terceiro at debian.org>
Date:   Fri Aug 14 14:47:12 2015 -0300

    Imported Upstream version 2.5.2
---
 .gitignore                     |  1 +
 .travis.yml                    | 47 +++++++++++++++++++++++++----
 CONTRIBUTING.md                |  2 +-
 Gemfile                        |  1 +
 LICENSE                        |  4 +--
 MAINTAINING.md                 |  6 ++--
 README.md                      |  3 +-
 Rakefile                       |  1 +
 execjs.gemspec                 |  5 +++-
 lib/execjs/duktape_runtime.rb  | 68 ++++++++++++++++++++++++++++++++++++++++++
 lib/execjs/external_runtime.rb |  9 +++++-
 lib/execjs/module.rb           |  4 +++
 lib/execjs/runtimes.rb         | 20 ++++++-------
 lib/execjs/version.rb          |  2 +-
 test/fixtures/coffee-script.js | 12 ++++----
 15 files changed, 152 insertions(+), 33 deletions(-)

diff --git a/.gitignore b/.gitignore
index b844b14..033a8fc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 Gemfile.lock
+pkg/*
diff --git a/.travis.yml b/.travis.yml
index c3b1e21..65df6c1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,42 @@
-sudo: false
 language: ruby
-rvm:
-  - 2.0.0
-  - 2.1
-  - 2.2
-  - jruby-19mode
+cache: bundler
+sudo: false
+
+script: bundle exec ruby test/test_execjs.rb
+
+matrix:
+  include:
+    - rvm: 2.0.0
+      env: EXECJS_RUNTIME=Node
+    - rvm: 2.0.0
+      env: EXECJS_RUNTIME=Duktape
+    - rvm: 2.0.0
+      env: EXECJS_RUNTIME=RubyRacer
+
+    - rvm: 2.1
+      env: EXECJS_RUNTIME=Node
+    - rvm: 2.1
+      env: EXECJS_RUNTIME=Duktape
+    - rvm: 2.1
+      env: EXECJS_RUNTIME=RubyRacer
+
+    - rvm: 2.2
+      env: EXECJS_RUNTIME=Node
+    - rvm: 2.2
+      env: EXECJS_RUNTIME=Duktape
+    - rvm: 2.2
+      env: EXECJS_RUNTIME=RubyRacer
+
+    - rvm: jruby-19mode
+      env: EXECJS_RUNTIME=Node
+    - rvm: jruby-19mode
+      env: EXECJS_RUNTIME=RubyRhino
+
+    - os: osx
+      env: EXECJS_RUNTIME=JavaScriptCore
+    - os: osx
+      env: EXECJS_RUNTIME=Node
+    - os: osx
+      env: EXECJS_RUNTIME=Duktape
+    - os: osx
+      env: EXECJS_RUNTIME=RubyRacer
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 759c363..2ceea93 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -5,7 +5,7 @@
 Clone the repository from GitHub.
 
 ```
-$ git clone https://github.com/sstephenson/execjs
+$ git clone https://github.com/rails/execjs
 ```
 
 Now just cd into the directory and run `bundle install` to install the
diff --git a/Gemfile b/Gemfile
index 3f1a9ea..2d5fb79 100644
--- a/Gemfile
+++ b/Gemfile
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
 gemspec
 
 group :test do
+  gem 'duktape', platform: :mri
   gem 'therubyracer', platform: :mri
   gem 'therubyrhino', ">=1.73.3", platform: :jruby
   gem 'minitest', require: false
diff --git a/LICENSE b/LICENSE
index 3b3cdd6..c9efe51 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,5 +1,5 @@
-Copyright (c) 2014 Sam Stephenson
-Copyright (c) 2014 Josh Peek
+Copyright (c) 2015 Sam Stephenson
+Copyright (c) 2015 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/MAINTAINING.md b/MAINTAINING.md
index 4ffc4e6..240c875 100644
--- a/MAINTAINING.md
+++ b/MAINTAINING.md
@@ -9,7 +9,7 @@ version "2.x.x" bump is in order.
 ### Make a release commit
 
 To prepare the release commit, edit the
-[lib/execjs/version.rb](https://github.com/sstephenson/execjs/blob/master/lib/execjs/version.rb)
+[lib/execjs/version.rb](https://github.com/rails/execjs/blob/master/lib/execjs/version.rb)
 `VERSION` value. Then make a single commit with the description as
 "ExecJS 2.x.x". Finally, tag the commit with `v2.x.x`.
 
@@ -18,7 +18,5 @@ $ git pull
 $ vim ./lib/execjs/version.rb
 $ git add ./lib/execjs/version.rb
 $ git ci -m "ExecJS 2.x.x"
-$ git tag v2.x.x
-$ git push
-$ git push --tags
+$ rake release
 ```
diff --git a/README.md b/README.md
index c7498a5..a499236 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,7 @@ ExecJS supports these runtimes:
   embedded within Ruby
 * [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
   Rhino embedded within JRuby
+* [Duktape.rb](https://github.com/judofyr/duktape.rb) - Duktape JavaScript interpreter
 * [Node.js](http://nodejs.org/)
 * Apple JavaScriptCore - Included with Mac OS X
 * [Microsoft Windows Script Host](http://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx) (JScript)
@@ -74,6 +75,6 @@ You shouldn't use `ExecJS.eval` on any inputs you wouldn't feel comfortable Ruby
 
 # License
 
-Copyright (c) 2014 Sam Stephenson and Josh Peek.
+Copyright (c) 2015 Sam Stephenson and Josh Peek.
 
 Released under the MIT license. See `LICENSE` for details.
diff --git a/Rakefile b/Rakefile
index f4ba838..628d3cf 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,5 @@
 require "rake/testtask"
+require "bundler/gem_tasks"
 
 task :default => :test
 
diff --git a/execjs.gemspec b/execjs.gemspec
index e52cf95..05b7aec 100644
--- a/execjs.gemspec
+++ b/execjs.gemspec
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
   s.name    = "execjs"
   s.version = ExecJS::VERSION
 
-  s.homepage    = "https://github.com/sstephenson/execjs"
+  s.homepage    = "https://github.com/rails/execjs"
   s.summary     = "Run JavaScript code from Ruby"
   s.description = "ExecJS lets you run JavaScript code from Ruby."
 
@@ -17,4 +17,7 @@ Gem::Specification.new do |s|
 
   s.authors = ["Sam Stephenson", "Josh Peek"]
   s.email   = ["sstephenson at gmail.com", "josh at joshpeek.com"]
+
+  # We only support MRI 2+ but this is needed to work with JRuby 1.7.
+  s.required_ruby_version = '>= 1.9.3'
 end
diff --git a/lib/execjs/duktape_runtime.rb b/lib/execjs/duktape_runtime.rb
new file mode 100644
index 0000000..cfbc7f9
--- /dev/null
+++ b/lib/execjs/duktape_runtime.rb
@@ -0,0 +1,68 @@
+require "execjs/runtime"
+require "json"
+
+module ExecJS
+  class DuktapeRuntime < Runtime
+    class Context < Runtime::Context
+      def initialize(runtime, source = "")
+        @ctx = Duktape::Context.new(complex_object: nil)
+        @ctx.exec_string(encode(source), '(execjs)')
+      rescue Exception => e
+        raise wrap_error(e)
+      end
+
+      def exec(source, options = {})
+        return unless /\S/ =~ source
+        @ctx.eval_string("(function(){#{encode(source)}})()", '(execjs)')
+      rescue Exception => e
+        raise wrap_error(e)
+      end
+
+      def eval(source, options = {})
+        return unless /\S/ =~ source
+        @ctx.eval_string("(#{encode(source)})", '(execjs)')
+      rescue Exception => e
+        raise wrap_error(e)
+      end
+
+      def call(identifier, *args)
+        @ctx.call_prop(identifier.split("."), *args)
+      rescue Exception => e
+        raise wrap_error(e)
+      end
+
+      private
+        def wrap_error(e)
+          klass = case e
+          when Duktape::SyntaxError
+            RuntimeError
+          when Duktape::Error
+            ProgramError
+          when Duktape::InternalError
+            RuntimeError
+          end
+
+          if klass
+            re = / \(line (\d+)\)$/
+            lineno = e.message[re, 1] || 1
+            error = klass.new(e.message.sub(re, ""))
+            error.set_backtrace(["(execjs):#{lineno}"] + e.backtrace)
+            error
+          else
+            e
+          end
+        end
+    end
+
+    def name
+      "Duktape"
+    end
+
+    def available?
+      require "duktape"
+      true
+    rescue LoadError
+      false
+    end
+  end
+end
diff --git a/lib/execjs/external_runtime.rb b/lib/execjs/external_runtime.rb
index 811dd69..8a924d6 100644
--- a/lib/execjs/external_runtime.rb
+++ b/lib/execjs/external_runtime.rb
@@ -28,8 +28,15 @@ module ExecJS
         source = @runtime.compile_source(source)
 
         tmpfile = write_to_tempfile(source)
+
+        if ExecJS.cygwin?
+          filepath = `cygpath -m #{tmpfile.path}`.rstrip
+        else
+          filepath = tmpfile.path
+        end
+
         begin
-          extract_result(@runtime.exec_runtime(tmpfile.path), tmpfile.path)
+          extract_result(@runtime.exec_runtime(filepath), filepath)
         ensure
           File.unlink(tmpfile)
         end
diff --git a/lib/execjs/module.rb b/lib/execjs/module.rb
index 6d155af..8b2566a 100644
--- a/lib/execjs/module.rb
+++ b/lib/execjs/module.rb
@@ -34,5 +34,9 @@ module ExecJS
     def windows?
       @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
     end
+
+    def cygwin?
+      @cygwin ||= RbConfig::CONFIG["host_os"] =~ /cygwin/
+    end
   end
 end
diff --git a/lib/execjs/runtimes.rb b/lib/execjs/runtimes.rb
index f646db6..5079a48 100644
--- a/lib/execjs/runtimes.rb
+++ b/lib/execjs/runtimes.rb
@@ -1,5 +1,6 @@
 require "execjs/module"
 require "execjs/disabled_runtime"
+require "execjs/duktape_runtime"
 require "execjs/external_runtime"
 require "execjs/ruby_racer_runtime"
 require "execjs/ruby_rhino_runtime"
@@ -8,6 +9,8 @@ module ExecJS
   module Runtimes
     Disabled = DisabledRuntime.new
 
+    Duktape = DuktapeRuntime.new
+
     RubyRacer = RubyRacerRuntime.new
 
     RubyRhino = RubyRhinoRuntime.new
@@ -43,7 +46,7 @@ module ExecJS
     def self.autodetect
       from_environment || best_available ||
         raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
-          "See https://github.com/sstephenson/execjs for a list of available runtimes.")
+          "See https://github.com/rails/execjs for a list of available runtimes.")
     end
 
     def self.best_available
@@ -52,15 +55,11 @@ module ExecJS
 
     def self.from_environment
       if name = ENV["EXECJS_RUNTIME"]
-        if runtime = const_get(name)
-          if runtime.available?
-            runtime if runtime.available?
-          else
-            raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system"
-          end
-        elsif !name.empty?
-          raise RuntimeUnavailable, "#{name} runtime is not defined"
-        end
+        raise RuntimeUnavailable, "#{name} runtime is not defined" unless const_defined?(name)
+        runtime = const_get(name)
+        
+        raise RuntimeUnavailable, "#{runtime.name} runtime is not available on this system" unless runtime.available?
+        runtime
       end
     end
 
@@ -72,6 +71,7 @@ module ExecJS
       @runtimes ||= [
         RubyRacer,
         RubyRhino,
+        Duktape,
         JavaScriptCore,
         Node,
         SpiderMonkey,
diff --git a/lib/execjs/version.rb b/lib/execjs/version.rb
index a87567b..2c8b468 100644
--- a/lib/execjs/version.rb
+++ b/lib/execjs/version.rb
@@ -1,3 +1,3 @@
 module ExecJS
-  VERSION = "2.4.0"
+  VERSION = "2.5.2"
 end
diff --git a/test/fixtures/coffee-script.js b/test/fixtures/coffee-script.js
index 0e63a65..5e84e1e 100644
--- a/test/fixtures/coffee-script.js
+++ b/test/fixtures/coffee-script.js
@@ -1,12 +1,12 @@
 /**
- * CoffeeScript Compiler v1.8.0
+ * CoffeeScript Compiler v1.9.1
  * http://coffeescript.org
  *
  * Copyright 2011, Jeremy Ashkenas
  * Released under the MIT License
  */
-(function(root){var CoffeeScript=function(){function require(e){return require[e]}return require["./helpers"]=function(){var e={},t={exports:e};return function(){var t,n,i,r,s,o,a;e.starts=function(e,t,n){return t===e.substr(n,t.length)},e.ends=function(e,t,n){var i;return i=t.length,t===e.substr(e.length-i-(n||0),i)},e.repeat=s=function(e,t){var n;for(n="";t>0;)1&t&&(n+=e),t>>>=1,e+=e;return n},e.compact=function(e){var t,n,i,r;for(r=[],n=0,i=e.length;i>n;n++)t=e[n],t&&r.push(t);return  [...]
-break;case 31:this.$=i.addLocationDataFn(o[a],o[a])(new i.Literal(s[a]));break;case 32:this.$=i.addLocationDataFn(o[a],o[a])(new i.Undefined);break;case 33:this.$=i.addLocationDataFn(o[a],o[a])(new i.Null);break;case 34:this.$=i.addLocationDataFn(o[a],o[a])(new i.Bool(s[a]));break;case 35:this.$=i.addLocationDataFn(o[a-2],o[a])(new i.Assign(s[a-2],s[a]));break;case 36:this.$=i.addLocationDataFn(o[a-3],o[a])(new i.Assign(s[a-3],s[a]));break;case 37:this.$=i.addLocationDataFn(o[a-4],o[a])( [...]
-this.trace(e)},parse:function(e){function t(){var e;return e=n.lexer.lex()||p,"number"!=typeof e&&(e=n.symbols_[e]||e),e}var n=this,i=[0],r=[null],s=[],o=this.table,a="",c=0,h=0,l=0,u=2,p=1,d=s.slice.call(arguments,1);this.lexer.setInput(e),this.lexer.yy=this.yy,this.yy.lexer=this.lexer,this.yy.parser=this,this.lexer.yylloc===void 0&&(this.lexer.yylloc={});var f=this.lexer.yylloc;s.push(f);var m=this.lexer.options&&this.lexer.options.ranges;this.parseError="function"==typeof this.yy.pars [...]
-},n.prototype.compilePatternMatch=function(e){var i,r,s,o,a,c,h,l,u,d,f,m,g,k,y,v,w,F,L,E,S,R,A,I,_,$,O,B;if(v=e.level===x,F=this.value,m=this.variable.base.objects,!(g=m.length))return s=F.compileToFragments(e),e.level>=N?this.wrapInBraces(s):s;if(l=this.variable.isObject(),v&&1===g&&!((f=m[0])instanceof G))return f instanceof n?(A=f,I=A.variable,h=I.base,f=A.value):h=l?f["this"]?f.properties[0].name:f:new D(0),i=b.test(h.unwrap().value||0),F=new Z(F),F.properties.push(new(i?t:T)(h)),_= [...]
-null==t&&(t=!1),s=o.readFileSync(e,"utf8"),a=65279===s.charCodeAt(0)?s.substring(1):s;try{n=i(a,{filename:e,sourceMap:t,literate:c.isLiterate(e)})}catch(h){throw r=h,c.updateSyntaxError(r,a,e)}return n},h=new t,l.lexer={lex:function(){var e,t;return t=this.tokens[this.pos++],t?(e=t[0],this.yytext=t[1],this.yylloc=t[2],this.errorToken=t.origin||t,this.yylineno=this.yylloc.first_line):e="",e},setInput:function(e){return this.tokens=e,this.pos=0},upcomingInput:function(){return""}},l.yy=req [...]
\ No newline at end of file
+(function(root){var CoffeeScript=function(){function require(e){return require[e]}return require["./helpers"]=function(){var e={},t={exports:e};return function(){var t,n,i,r,s,o;e.starts=function(e,t,n){return t===e.substr(n,t.length)},e.ends=function(e,t,n){var i;return i=t.length,t===e.substr(e.length-i-(n||0),i)},e.repeat=s=function(e,t){var n;for(n="";t>0;)1&t&&(n+=e),t>>>=1,e+=e;return n},e.compact=function(e){var t,n,i,r;for(r=[],t=0,i=e.length;i>t;t++)n=e[t],n&&r.push(n);return r} [...]
+switch(r){case 1:return this.$=i.addLocationDataFn(o[a],o[a])(new i.Block);case 2:return this.$=s[a];case 3:this.$=i.addLocationDataFn(o[a],o[a])(i.Block.wrap([s[a]]));break;case 4:this.$=i.addLocationDataFn(o[a-2],o[a])(s[a-2].push(s[a]));break;case 5:this.$=s[a-1];break;case 6:case 7:case 8:case 9:case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 27:case 32:case 34:case 45:case 46:case 47:case 48:case 56:case 57:case 67:case 68:case 69 [...]
+this.trace(e)},parse:function(e){function t(){var e;return e=f.lex()||p,"number"!=typeof e&&(e=n.symbols_[e]||e),e}var n=this,i=[0],r=[null],s=[],o=this.table,a="",c=0,l=0,h=0,u=2,p=1,d=s.slice.call(arguments,1),f=Object.create(this.lexer),m={yy:{}};for(var g in this.yy)Object.prototype.hasOwnProperty.call(this.yy,g)&&(m.yy[g]=this.yy[g]);f.setInput(e,m.yy),m.yy.lexer=f,m.yy.parser=this,f.yylloc===void 0&&(f.yylloc={});var v=f.yylloc;s.push(v);var y=f.options&&f.options.ranges;this.parse [...]
+},n.prototype.assigns=function(e){return this["object"===this.context?"value":"variable"].assigns(e)},n.prototype.unfoldSoak=function(e){return yt(e,this,"variable")},n.prototype.compileNode=function(e){var t,n,i,r,s,o,a,l,h,u,p,d,f,m;if(i=this.variable instanceof z){if(this.variable.isArray()||this.variable.isObject())return this.compilePatternMatch(e);if(this.variable.isSplice())return this.compileSplice(e);if("||="===(l=this.context)||"&&="===l||"?="===l)return this.compileConditional [...]
+}catch(r){throw i=r,l.updateSyntaxError(i,t,n.filename)}}},e.compile=r=y(function(e,t){var i,r,s,o,a,c,h,u,f,m,g,v,y,b,k;for(v=l.merge,o=l.extend,t=o({},t),t.sourceMap&&(g=new n),k=p.tokenize(e,t),t.referencedVars=function(){var e,t,n;for(n=[],e=0,t=k.length;t>e;e++)b=k[e],b.variable&&n.push(b[1]);return n}(),c=d.parse(k).compileToFragments(t),s=0,t.header&&(s+=1),t.shiftLine&&(s+=1),r=0,f="",u=0,m=c.length;m>u;u++)a=c[u],t.sourceMap&&(a.locationData&&g.add([a.locationData.first_line,a.l [...]
\ No newline at end of file

-- 
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