Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

context::run_script() crash #80

Closed
VitaminCpp opened this issue Jul 16, 2018 · 3 comments
Closed

context::run_script() crash #80

VitaminCpp opened this issue Jul 16, 2018 · 3 comments

Comments

@VitaminCpp
Copy link

VitaminCpp commented Jul 16, 2018

Hi,

if I try to compile a script with V8 6.4.388 with an intentional syntax error, my app crashes. This happens because of line 262. v8::Script::Compile() returns a MaybeLocal() and you're using ToLocalChecked() which will crash the current process as stated in v8.h.

To solve this issue just convert it by "ToLocal()" and then check for empty:

v8::Local<v8::Value> context::run_script(std::string const& source,
	std::string const& filename)
{
	v8::EscapableHandleScope scope(isolate_);
	v8::Local<v8::Context> context = isolate_->GetCurrentContext();

	v8::ScriptOrigin origin(to_v8(isolate_, filename));
  v8::Local<v8::Value> result;
  
  v8::Local<v8::Script> script;
  if (!v8::Script::Compile(context,
    to_v8(isolate_, source), &origin).ToLocal(&script))
  {
    return scope.Escape(result);
  }

  if (!script.IsEmpty())
  {
	script->Run(context).ToLocal(&result);
  }
  return scope.Escape(result);
}

These "ToLocalChecked()" calls are IMHO a bit dangerous for people who run the V8 on the main thread.

pmed added a commit that referenced this issue Jul 18, 2018
Return empty result handle for a script with syntax error,
do not catch JavaScript exception.

Added a  test case.

See issue #80
@pmed
Copy link
Owner

pmed commented Jul 18, 2018

Hi @VitaminCpp

Thank you for the issue reporting!

I've fixed it as you proposed. Now the run_script() function returns an empty handle in case of syntax error, but V8 will throw a JavaScript exception. Such an exception could be handled with v8::TryCatch as in the test case.

@VitaminCpp
Copy link
Author

Hi @pmed!
Thank you for this great library!
Great! I think this is a good solution.

@pmed
Copy link
Owner

pmed commented Jul 25, 2018

Hi @VitaminCpp

Thanks! It seems I have to review all the ToLocalChecked() usage in the library code. So I'd stay this issue open yet.

@pmed pmed closed this as completed Aug 7, 2018
pmed added a commit that referenced this issue Dec 25, 2018
Addition to issue #80 fix: return empty result handle on a script run error
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants