History

Add V8 handle scopes

ksuprynowicz committed 4 years ago

Commit 2b06c091 parent b4d21c310 files · +135 −43Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptProgramV8Wrapper.cpp (1 of 10 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptProgramV8Wrapper.cpp+12−9
@@ -32,29 +32,32 @@ ScriptSyntaxCheckResultPointer ScriptProgramV8Wrapper::checkSyntax() { · 31 unmodified lines
3232 }
3333
3434 bool ScriptProgramV8Wrapper::compile() {
35+ auto isolate = _engine->getIsolate();
36+ v8::HandleScope handleScope(isolate);
37+ auto context = _engine->getContext();
3538 int errorColumnNumber = 0;
3639 int errorLineNumber = 0;
3740 QString errorMessage = "";
3841 QString errorBacktrace = "";
3942 ScriptSyntaxCheckResult::State state;
40− v8::TryCatch tryCatch(_engine->getIsolate());
41− v8::ScriptOrigin scriptOrigin(_engine->getIsolate(), v8::String::NewFromUtf8(_engine->getIsolate(), _url.toStdString().c_str()).ToLocalChecked());
43+ v8::TryCatch tryCatch(isolate);
44+ v8::ScriptOrigin scriptOrigin(isolate, v8::String::NewFromUtf8(isolate, _url.toStdString().c_str()).ToLocalChecked());
4245 v8::Local<v8::Script> script;
43− if (v8::Script::Compile(_engine->getContext(), v8::String::NewFromUtf8(_engine->getIsolate(), _source.toStdString().c_str()).ToLocalChecked(), &scriptOrigin).ToLocal(&script)) {
46+ if (v8::Script::Compile(context, v8::String::NewFromUtf8(isolate, _source.toStdString().c_str()).ToLocalChecked(), &scriptOrigin).ToLocal(&script)) {
4447 _compileResult = ScriptSyntaxCheckResultV8Wrapper(ScriptSyntaxCheckResult::Valid);
45− _value = V8ScriptProgram(_engine->getIsolate(), script);
48+ _value = V8ScriptProgram(isolate, script);
4649 return true;
4750 }
48− v8::String::Utf8Value utf8Value(_engine->getIsolate(), tryCatch.Exception());
51+ v8::String::Utf8Value utf8Value(isolate, tryCatch.Exception());
4952 errorMessage = QString(*utf8Value);
5053 v8::Local<v8::Message> exceptionMessage = tryCatch.Message();
5154 if (!exceptionMessage.IsEmpty()) {
52− errorLineNumber = exceptionMessage->GetLineNumber(_engine->getContext()).FromJust();
53− errorColumnNumber = exceptionMessage->GetStartColumn(_engine->getContext()).FromJust();
55+ errorLineNumber = exceptionMessage->GetLineNumber(context).FromJust();
56+ errorColumnNumber = exceptionMessage->GetStartColumn(context).FromJust();
5457 v8::Local<v8::Value> backtraceV8String;
55− if (tryCatch.StackTrace(_engine->getContext()).ToLocal(&backtraceV8String) && backtraceV8String->IsString() &&
58+ if (tryCatch.StackTrace(context).ToLocal(&backtraceV8String) && backtraceV8String->IsString() &&
5659 v8::Local<v8::String>::Cast(backtraceV8String)->Length() > 0) {
57− v8::String::Utf8Value backtraceUtf8Value(_engine->getIsolate(), backtraceV8String);
60+ v8::String::Utf8Value backtraceUtf8Value(isolate, backtraceV8String);
5861 errorBacktrace = *backtraceUtf8Value;
5962 }
6063 }