Skip to content

Commit

Permalink
fix context::run_script() with syntax error
Browse files Browse the repository at this point in the history
Return empty result handle for a script with syntax error,
do not catch JavaScript exception.

Added a  test case.

See issue #80
  • Loading branch information
pmed committed Jul 18, 2018
1 parent 8944b49 commit d3040a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion test/test_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ void test_context()
v8pp::context context;

v8::HandleScope scope(context.isolate());
int const r = context.run_script("42")->Int32Value(context.isolate()->GetCurrentContext()).FromJust();
v8::Local<v8::Value> result = context.run_script("42");
int const r = result->Int32Value(context.isolate()->GetCurrentContext()).FromJust();
check_eq("run_script", r, 42);

v8::TryCatch try_catch(context.isolate());
result = context.run_script("syntax error");
check("script with syntax error", result.IsEmpty());
check(" has caught", try_catch.HasCaught());
}

{
Expand Down
5 changes: 3 additions & 2 deletions v8pp/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ v8::Local<v8::Value> context::run_script(std::string const& source,
v8::Local<v8::Context> context = isolate_->GetCurrentContext();

v8::ScriptOrigin origin(to_v8(isolate_, filename));
v8::Local<v8::Script> script = v8::Script::Compile(context,
to_v8(isolate_, source), &origin).ToLocalChecked();
v8::Local<v8::Script> script;
bool const is_valid = v8::Script::Compile(context,
to_v8(isolate_, source), &origin).ToLocal(&script);

v8::Local<v8::Value> result;
if (!script.IsEmpty())
Expand Down

0 comments on commit d3040a8

Please sign in to comment.