mirror of
https://github.com/rails/execjs
synced 2023-03-27 23:21:20 -04:00
Ensure compile errors are wrapped
This commit is contained in:
parent
6c7d9f4818
commit
5fd5af3145
3 changed files with 32 additions and 2 deletions
|
@ -9,6 +9,9 @@ module ExecJS
|
|||
|
||||
@runtime = runtime
|
||||
@source = source
|
||||
|
||||
# Test compile context source
|
||||
exec("")
|
||||
end
|
||||
|
||||
def eval(source, options = {})
|
||||
|
|
|
@ -8,7 +8,16 @@ module ExecJS
|
|||
|
||||
lock do
|
||||
@v8_context = ::V8::Context.new
|
||||
|
||||
begin
|
||||
@v8_context.eval(source)
|
||||
rescue ::V8::JSError => e
|
||||
if e.value["name"] == "SyntaxError"
|
||||
raise RuntimeError, e.value.to_s
|
||||
else
|
||||
raise ProgramError, e.value.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -206,7 +206,25 @@ class TestExecJS < Test
|
|||
end
|
||||
end
|
||||
|
||||
def test_thrown_exception
|
||||
def test_compile_syntax_error
|
||||
assert_raises ExecJS::RuntimeError do
|
||||
ExecJS.compile(")")
|
||||
end
|
||||
end
|
||||
|
||||
def test_exec_thrown_exception
|
||||
assert_raises ExecJS::ProgramError do
|
||||
ExecJS.exec("throw 'hello'")
|
||||
end
|
||||
end
|
||||
|
||||
def test_eval_thrown_exception
|
||||
assert_raises ExecJS::ProgramError do
|
||||
ExecJS.exec("throw 'hello'")
|
||||
end
|
||||
end
|
||||
|
||||
def test_compile_thrown_exception
|
||||
assert_raises ExecJS::ProgramError do
|
||||
ExecJS.exec("throw 'hello'")
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue