1
0
Fork 0
mirror of https://github.com/rails/execjs synced 2023-03-27 23:21:20 -04:00

Express exec in terms of eval

This commit is contained in:
Joshua Peek 2014-12-09 14:56:43 -08:00
parent a8a2d80269
commit a3b32250cc

View file

@ -10,14 +10,25 @@ module ExecJS
end
def exec(source, options = {})
eval "(function(){#{source}})()"
end
def eval(source, options = {})
source = encode(source)
unwrap(@ctx.eval_string("(function() { #{source} })();", '(execjs)'))
if /\S/ =~ source
unwrap(@ctx.eval_string("(#{source})", '(execjs)'))
end
rescue Duktape::SyntaxError => e
raise RuntimeError, e.message
rescue Duktape::Error => e
raise ProgramError, e.message
end
def call(identifier, *args)
eval "#{identifier}.apply(this, #{::JSON.generate(args)})"
end
def unwrap(obj)
case obj
when ::Duktape::ComplexObject
@ -36,18 +47,6 @@ module ExecJS
obj
end
end
def eval(source, options = {})
source = encode(source)
if /\S/ =~ source
exec("return eval(#{::JSON.generate("(#{source})", quirks_mode: true)})")
end
end
def call(identifier, *args)
eval "#{identifier}.apply(this, #{::JSON.generate(args)})"
end
end
def name