execjs 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/execjs.rb +1 -0
- data/lib/execjs/mustang_runtime.rb +72 -0
- data/lib/execjs/runtimes.rb +3 -0
- metadata +28 -13
data/README.md
CHANGED
@@ -11,6 +11,8 @@ ExecJS supports these runtimes:
|
|
11
11
|
embedded within MRI Ruby
|
12
12
|
* [therubyrhino](https://github.com/cowboyd/therubyrhino) - Mozilla
|
13
13
|
Rhino embedded within JRuby
|
14
|
+
* [Mustang](https://github.com/nu7hatch/mustang) - Mustang V8
|
15
|
+
embedded within Ruby
|
14
16
|
* [Node.js](http://nodejs.org/)
|
15
17
|
* Apple JavaScriptCore - Included with Mac OS X
|
16
18
|
* [Mozilla Spidermonkey](http://www.mozilla.org/js/spidermonkey/)
|
data/lib/execjs.rb
CHANGED
@@ -6,6 +6,7 @@ module ExecJS
|
|
6
6
|
class ProgramError < Error; end
|
7
7
|
|
8
8
|
autoload :ExternalRuntime, "execjs/external_runtime"
|
9
|
+
autoload :MustangRuntime, "execjs/mustang_runtime"
|
9
10
|
autoload :RubyRacerRuntime, "execjs/ruby_racer_runtime"
|
10
11
|
autoload :RubyRhinoRuntime, "execjs/ruby_rhino_runtime"
|
11
12
|
autoload :Runtimes, "execjs/runtimes"
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ExecJS
|
2
|
+
class MustangRuntime
|
3
|
+
class Context
|
4
|
+
def initialize(source = "")
|
5
|
+
@v8_context = ::Mustang::Context.new
|
6
|
+
@v8_context.eval(source)
|
7
|
+
end
|
8
|
+
|
9
|
+
def exec(source, options = {})
|
10
|
+
if /\S/ =~ source
|
11
|
+
eval "(function(){#{source}})()", options
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def eval(source, options = {})
|
16
|
+
if /\S/ =~ source
|
17
|
+
unbox @v8_context.eval("(#{source})")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(properties, *args)
|
22
|
+
unbox @v8_context.eval(properties).call(*args)
|
23
|
+
rescue NoMethodError => e
|
24
|
+
raise ProgramError, e.message
|
25
|
+
end
|
26
|
+
|
27
|
+
def unbox(value)
|
28
|
+
case value
|
29
|
+
when Mustang::V8::Array
|
30
|
+
value.map { |v| unbox(v) }
|
31
|
+
when Mustang::V8::Boolean
|
32
|
+
value.to_bool
|
33
|
+
when Mustang::V8::NullClass, Mustang::V8::UndefinedClass
|
34
|
+
nil
|
35
|
+
when Mustang::V8::Function
|
36
|
+
nil
|
37
|
+
when Mustang::V8::SyntaxError
|
38
|
+
raise RuntimeError, value.message
|
39
|
+
when Mustang::V8::Error
|
40
|
+
raise ProgramError, value.message
|
41
|
+
else
|
42
|
+
value.respond_to?(:delegate) ? value.delegate : value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def name
|
48
|
+
"Mustang (V8)"
|
49
|
+
end
|
50
|
+
|
51
|
+
def exec(source)
|
52
|
+
context = Context.new
|
53
|
+
context.exec(source)
|
54
|
+
end
|
55
|
+
|
56
|
+
def eval(source)
|
57
|
+
context = Context.new
|
58
|
+
context.eval(source)
|
59
|
+
end
|
60
|
+
|
61
|
+
def compile(source)
|
62
|
+
Context.new(source)
|
63
|
+
end
|
64
|
+
|
65
|
+
def available?
|
66
|
+
require "mustang"
|
67
|
+
true
|
68
|
+
rescue LoadError
|
69
|
+
false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/execjs/runtimes.rb
CHANGED
@@ -4,6 +4,8 @@ module ExecJS
|
|
4
4
|
|
5
5
|
RubyRhino = RubyRhinoRuntime.new
|
6
6
|
|
7
|
+
Mustang = MustangRuntime.new
|
8
|
+
|
7
9
|
Node = ExternalRuntime.new(
|
8
10
|
:name => "Node.js (V8)",
|
9
11
|
:command => ["nodejs", "node"],
|
@@ -38,6 +40,7 @@ module ExecJS
|
|
38
40
|
@runtimes ||= [
|
39
41
|
RubyRacer,
|
40
42
|
RubyRhino,
|
43
|
+
Mustang,
|
41
44
|
Node,
|
42
45
|
JavaScriptCore,
|
43
46
|
Spidermonkey,
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sam Stephenson
|
@@ -16,11 +16,11 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-04-12 00:00:00 -05:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
-
name:
|
23
|
+
name: mustang
|
24
24
|
prerelease: false
|
25
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
type: :development
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
37
|
+
name: therubyracer
|
38
38
|
prerelease: false
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
@@ -47,6 +47,20 @@ dependencies:
|
|
47
47
|
version: "0"
|
48
48
|
type: :development
|
49
49
|
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: therubyrhino
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 3
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
type: :development
|
63
|
+
version_requirements: *id003
|
50
64
|
description: " ExecJS lets you run JavaScript code from Ruby.\n"
|
51
65
|
email:
|
52
66
|
- sstephenson@gmail.com
|
@@ -58,16 +72,17 @@ extensions: []
|
|
58
72
|
extra_rdoc_files: []
|
59
73
|
|
60
74
|
files:
|
75
|
+
- lib/execjs.rb
|
76
|
+
- lib/execjs/external_runtime.rb
|
77
|
+
- lib/execjs/mustang_runtime.rb
|
78
|
+
- lib/execjs/ruby_racer_runtime.rb
|
79
|
+
- lib/execjs/ruby_rhino_runtime.rb
|
80
|
+
- lib/execjs/runtimes.rb
|
61
81
|
- lib/execjs/support/basic_runner.js
|
62
82
|
- lib/execjs/support/jscript_runner.js
|
63
83
|
- lib/execjs/support/json2.js
|
64
84
|
- lib/execjs/support/node_runner.js
|
65
85
|
- lib/execjs/support/which.bat
|
66
|
-
- lib/execjs/external_runtime.rb
|
67
|
-
- lib/execjs/ruby_racer_runtime.rb
|
68
|
-
- lib/execjs/ruby_rhino_runtime.rb
|
69
|
-
- lib/execjs/runtimes.rb
|
70
|
-
- lib/execjs.rb
|
71
86
|
- LICENSE
|
72
87
|
- README.md
|
73
88
|
has_rdoc: true
|
@@ -100,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
115
|
requirements: []
|
101
116
|
|
102
117
|
rubyforge_project: execjs
|
103
|
-
rubygems_version: 1.
|
118
|
+
rubygems_version: 1.6.2
|
104
119
|
signing_key:
|
105
120
|
specification_version: 3
|
106
121
|
summary: Run JavaScript code from Ruby
|