mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Added Mustang V8 as runtime
This commit is contained in:
parent
8f438d81c1
commit
bffdd50b22
4 changed files with 78 additions and 0 deletions
|
@ -7,6 +7,7 @@ module ExecJS
|
|||
|
||||
autoload :ExternalRuntime, "execjs/external_runtime"
|
||||
autoload :RubyRacerRuntime, "execjs/ruby_racer_runtime"
|
||||
autoload :MustangRuntime, "execjs/mustang_runtime"
|
||||
autoload :RubyRhinoRuntime, "execjs/ruby_rhino_runtime"
|
||||
autoload :Runtimes, "execjs/runtimes"
|
||||
|
||||
|
|
73
lib/execjs/mustang_runtime.rb
Normal file
73
lib/execjs/mustang_runtime.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
module ExecJS
|
||||
class MustangRuntime
|
||||
def name
|
||||
"Mustang (Mustang::V8)"
|
||||
end
|
||||
|
||||
def exec(source)
|
||||
context = Context.new
|
||||
context.exec(source)
|
||||
end
|
||||
|
||||
def eval(source)
|
||||
context = Context.new
|
||||
context.eval(source)
|
||||
end
|
||||
|
||||
def compile(source)
|
||||
Context.new(source)
|
||||
end
|
||||
|
||||
def available?
|
||||
require "mustang"
|
||||
true
|
||||
rescue LoadError
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
module ExecJS
|
||||
class MustangRuntime::Context
|
||||
|
||||
def initialize(source = "")
|
||||
@v8_context = ::Mustang::Context.new
|
||||
@v8_context.eval(source)
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
if /\S/ =~ source
|
||||
eval "(function(){#{source}})()", options
|
||||
end
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
if /\S/ =~ source
|
||||
unbox @v8_context.eval("(#{source})")
|
||||
end
|
||||
end
|
||||
|
||||
def call(properties, *args)
|
||||
unbox @v8_context.eval(properties).call(*args)
|
||||
rescue NoMethodError
|
||||
raise ProgramError
|
||||
end
|
||||
|
||||
def unbox(value)
|
||||
case value
|
||||
when Mustang::V8::NullClass, Mustang::V8::UndefinedClass, Mustang::V8::Function
|
||||
nil
|
||||
when Mustang::V8::Array
|
||||
value.map { |v| unbox(v) }
|
||||
when Mustang::V8::SyntaxError
|
||||
raise RuntimeError
|
||||
when Mustang::V8::Error
|
||||
raise ProgramError
|
||||
else
|
||||
value.respond_to?(:delegate) ? value.delegate : value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -2,6 +2,8 @@ module ExecJS
|
|||
module Runtimes
|
||||
RubyRacer = RubyRacerRuntime.new
|
||||
|
||||
Mustang = MustangRuntime.new
|
||||
|
||||
RubyRhino = RubyRhinoRuntime.new
|
||||
|
||||
Node = ExternalRuntime.new(
|
||||
|
@ -37,6 +39,7 @@ module ExecJS
|
|||
def self.runtimes
|
||||
@runtimes ||= [
|
||||
RubyRacer,
|
||||
Mustang,
|
||||
RubyRhino,
|
||||
Node,
|
||||
JavaScriptCore,
|
||||
|
|
|
@ -57,6 +57,7 @@ module TestRuntime
|
|||
end
|
||||
|
||||
runtimes = [
|
||||
"Mustang",
|
||||
"RubyRacer",
|
||||
"RubyRhino",
|
||||
"Node",
|
||||
|
|
Loading…
Add table
Reference in a new issue