1
0
Fork 0
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:
Joshua Peek 2014-12-11 10:57:49 -08:00
parent 6c7d9f4818
commit 5fd5af3145
3 changed files with 32 additions and 2 deletions

View file

@ -9,6 +9,9 @@ module ExecJS
@runtime = runtime
@source = source
# Test compile context source
exec("")
end
def eval(source, options = {})

View file

@ -8,7 +8,16 @@ module ExecJS
lock do
@v8_context = ::V8::Context.new
@v8_context.eval(source)
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

View file

@ -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