Skip to content

context::run_script() crash #80

@VitaminCpp

Description

@VitaminCpp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions