execjs 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fde57c2c3957d81859359cf4c369f608a644551b
4
- data.tar.gz: e28210a8d96d0c21c113f3cf7be58f763f42fb87
3
+ metadata.gz: b661ea567392e0b28c52fa78afd62bb2f5c92928
4
+ data.tar.gz: d311797924e04937683fce5b9a5df34aab7a19d2
5
5
  SHA512:
6
- metadata.gz: 8ee2ee0d5407bda28d4351701bbcfd0a9b39bbb0de18843c78c258cd89ee39ee73fbfb9ec2f1172b43027c2ffcf8320d9471dc98de80c3c9cfb4804be8dac8f5
7
- data.tar.gz: ac21345c3a7c2283d70f65f86f7b4577f694d184783d5d93e4d1a72d93fe3fa95c6e31612728efeb503f8216d8f4dfd7558f77cf9e94440b62ed5dbf000cdffb
6
+ metadata.gz: 30839a2f7f598ceb148df63481454de2ccb7868d9830441e64c996c01690fcd636dd76643174ed063daf73aa80534c241cd44579aa613942f6aa5981075d1af7
7
+ data.tar.gz: e026d891e649b617f2dcd526043a9a178f1eaf0659589e43e8c4cc60a3ce08452229fd929ee73c681b5d9c326f9a5904febf947deb9fffb700ae82ad9be38709
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2014 Sam Stephenson
2
- Copyright (c) 2014 Josh Peek
1
+ Copyright (c) 2015 Sam Stephenson
2
+ Copyright (c) 2015 Josh Peek
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining
5
5
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -11,6 +11,7 @@ ExecJS supports these runtimes:
11
11
  embedded within Ruby
12
12
  * [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
13
13
  Rhino embedded within JRuby
14
+ * [Duktape.rb](https://github.com/judofyr/duktape.rb) - Duktape JavaScript interpreter
14
15
  * [Node.js](http://nodejs.org/)
15
16
  * Apple JavaScriptCore - Included with Mac OS X
16
17
  * [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
74
75
 
75
76
  # License
76
77
 
77
- Copyright (c) 2014 Sam Stephenson and Josh Peek.
78
+ Copyright (c) 2015 Sam Stephenson and Josh Peek.
78
79
 
79
80
  Released under the MIT license. See `LICENSE` for details.
@@ -0,0 +1,68 @@
1
+ require "execjs/runtime"
2
+ require "json"
3
+
4
+ module ExecJS
5
+ class DuktapeRuntime < Runtime
6
+ class Context < Runtime::Context
7
+ def initialize(runtime, source = "")
8
+ @ctx = Duktape::Context.new(complex_object: nil)
9
+ @ctx.exec_string(encode(source), '(execjs)')
10
+ rescue Exception => e
11
+ raise wrap_error(e)
12
+ end
13
+
14
+ def exec(source, options = {})
15
+ return unless /\S/ =~ source
16
+ @ctx.eval_string("(function(){#{encode(source)}})()", '(execjs)')
17
+ rescue Exception => e
18
+ raise wrap_error(e)
19
+ end
20
+
21
+ def eval(source, options = {})
22
+ return unless /\S/ =~ source
23
+ @ctx.eval_string("(#{encode(source)})", '(execjs)')
24
+ rescue Exception => e
25
+ raise wrap_error(e)
26
+ end
27
+
28
+ def call(identifier, *args)
29
+ @ctx.call_prop(identifier.split("."), *args)
30
+ rescue Exception => e
31
+ raise wrap_error(e)
32
+ end
33
+
34
+ private
35
+ def wrap_error(e)
36
+ klass = case e
37
+ when Duktape::SyntaxError
38
+ RuntimeError
39
+ when Duktape::Error
40
+ ProgramError
41
+ when Duktape::InternalError
42
+ RuntimeError
43
+ end
44
+
45
+ if klass
46
+ re = / \(line (\d+)\)$/
47
+ lineno = e.message[re, 1] || 1
48
+ error = klass.new(e.message.sub(re, ""))
49
+ error.set_backtrace(["(execjs):#{lineno}"] + e.backtrace)
50
+ error
51
+ else
52
+ e
53
+ end
54
+ end
55
+ end
56
+
57
+ def name
58
+ "Duktape"
59
+ end
60
+
61
+ def available?
62
+ require "duktape"
63
+ true
64
+ rescue LoadError
65
+ false
66
+ end
67
+ end
68
+ end
@@ -28,8 +28,15 @@ module ExecJS
28
28
  source = @runtime.compile_source(source)
29
29
 
30
30
  tmpfile = write_to_tempfile(source)
31
+
32
+ if ExecJS.cygwin?
33
+ filepath = `cygpath -m #{tmpfile.path}`.rstrip
34
+ else
35
+ filepath = tmpfile.path
36
+ end
37
+
31
38
  begin
32
- extract_result(@runtime.exec_runtime(tmpfile.path), tmpfile.path)
39
+ extract_result(@runtime.exec_runtime(filepath), filepath)
33
40
  ensure
34
41
  File.unlink(tmpfile)
35
42
  end
@@ -34,5 +34,9 @@ module ExecJS
34
34
  def windows?
35
35
  @windows ||= RbConfig::CONFIG["host_os"] =~ /mswin|mingw/
36
36
  end
37
+
38
+ def cygwin?
39
+ @cygwin ||= RbConfig::CONFIG["host_os"] =~ /cygwin/
40
+ end
37
41
  end
38
42
  end
@@ -1,5 +1,6 @@
1
1
  require "execjs/module"
2
2
  require "execjs/disabled_runtime"
3
+ require "execjs/duktape_runtime"
3
4
  require "execjs/external_runtime"
4
5
  require "execjs/ruby_racer_runtime"
5
6
  require "execjs/ruby_rhino_runtime"
@@ -8,6 +9,8 @@ module ExecJS
8
9
  module Runtimes
9
10
  Disabled = DisabledRuntime.new
10
11
 
12
+ Duktape = DuktapeRuntime.new
13
+
11
14
  RubyRacer = RubyRacerRuntime.new
12
15
 
13
16
  RubyRhino = RubyRhinoRuntime.new
@@ -43,7 +46,7 @@ module ExecJS
43
46
  def self.autodetect
44
47
  from_environment || best_available ||
45
48
  raise(RuntimeUnavailable, "Could not find a JavaScript runtime. " +
46
- "See https://github.com/sstephenson/execjs for a list of available runtimes.")
49
+ "See https://github.com/rails/execjs for a list of available runtimes.")
47
50
  end
48
51
 
49
52
  def self.best_available
@@ -72,6 +75,7 @@ module ExecJS
72
75
  @runtimes ||= [
73
76
  RubyRacer,
74
77
  RubyRhino,
78
+ Duktape,
75
79
  JavaScriptCore,
76
80
  Node,
77
81
  SpiderMonkey,
@@ -1,3 +1,3 @@
1
1
  module ExecJS
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: execjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-05 00:00:00.000000000 Z
12
+ date: 2015-04-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -37,6 +37,7 @@ files:
37
37
  - README.md
38
38
  - lib/execjs.rb
39
39
  - lib/execjs/disabled_runtime.rb
40
+ - lib/execjs/duktape_runtime.rb
40
41
  - lib/execjs/encoding.rb
41
42
  - lib/execjs/external_runtime.rb
42
43
  - lib/execjs/module.rb
@@ -50,7 +51,7 @@ files:
50
51
  - lib/execjs/support/node_runner.js
51
52
  - lib/execjs/support/spidermonkey_runner.js
52
53
  - lib/execjs/version.rb
53
- homepage: https://github.com/sstephenson/execjs
54
+ homepage: https://github.com/rails/execjs
54
55
  licenses:
55
56
  - MIT
56
57
  metadata: {}
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  version: '0'
71
72
  requirements: []
72
73
  rubyforge_project:
73
- rubygems_version: 2.4.5
74
+ rubygems_version: 2.2.2
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Run JavaScript code from Ruby