mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Catch errors on context compile
This commit is contained in:
parent
86f93d4269
commit
900da3c817
1 changed files with 19 additions and 12 deletions
|
@ -9,6 +9,8 @@ module ExecJS
|
|||
@rhino_context = ::Rhino::Context.new
|
||||
fix_memory_limit! @rhino_context
|
||||
@rhino_context.eval(source)
|
||||
rescue Exception => e
|
||||
reraise_error(e)
|
||||
end
|
||||
|
||||
def exec(source, options = {})
|
||||
|
@ -25,22 +27,14 @@ module ExecJS
|
|||
if /\S/ =~ source
|
||||
unbox @rhino_context.eval("(#{source})")
|
||||
end
|
||||
rescue ::Rhino::JSError => e
|
||||
if e.message =~ /^syntax error/
|
||||
raise RuntimeError, e.message
|
||||
else
|
||||
raise ProgramError, e.message
|
||||
end
|
||||
rescue Exception => e
|
||||
reraise_error(e)
|
||||
end
|
||||
|
||||
def call(properties, *args)
|
||||
unbox @rhino_context.eval(properties).call(*args)
|
||||
rescue ::Rhino::JSError => e
|
||||
if e.message == "syntax error"
|
||||
raise RuntimeError, e.message
|
||||
else
|
||||
raise ProgramError, e.message
|
||||
end
|
||||
rescue Exception => e
|
||||
reraise_error(e)
|
||||
end
|
||||
|
||||
def unbox(value)
|
||||
|
@ -64,6 +58,19 @@ module ExecJS
|
|||
end
|
||||
end
|
||||
|
||||
def reraise_error(e)
|
||||
case e
|
||||
when ::Rhino::JSError
|
||||
if e.message == "syntax error"
|
||||
raise RuntimeError, e.message
|
||||
else
|
||||
raise ProgramError, e.message
|
||||
end
|
||||
else
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Disables bytecode compiling which limits you to 64K scripts
|
||||
def fix_memory_limit!(context)
|
||||
|
|
Loading…
Reference in a new issue