History

Fixed contexts for V8 callbacks

ksuprynowicz committed 3 years ago

Commit db15ed21 parent ab219453 files · +37 −9Browse files

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

Unified · Split

libraries/script-engine/src/v8/ScriptObjectV8Proxy.cpp+9−9
@@ -462,6 +462,8 @@ void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCall · 461 unmodified lines
462462 }
463463 v8::Local<v8::String> v8NameString;
464464
465+ ContextScopeV8 contextScopeV8(proxy->_engine);
466+
465467 if (name->IsString()) {
466468 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
467469 uint id;
@@ -497,6 +499,8 @@ void ScriptObjectV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> v · 29 unmodified lines
497499 Q_ASSERT(false);
498500 }
499501
502+ ContextScopeV8 contextScopeV8(proxy->_engine);
503+
500504 if (name->IsString()) {
501505 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
502506 uint id;
@@ -800,6 +804,8 @@ void ScriptVariantV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCal · 297 unmodified lines
800804 }
801805 V8ScriptValue object(proxy->_engine, proxy->_v8Object.Get(info.GetIsolate()));
802806
807+ ContextScopeV8 contextScopeV8(proxy->_engine);
808+
803809 if (name->IsString()) {
804810 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
805811 uint id;
@@ -831,6 +837,7 @@ void ScriptVariantV8Proxy::v8Set(v8::Local<v8::Name> name, v8::Local<v8::Value> · 25 unmodified lines
831837 Q_ASSERT(false);
832838 }
833839
840+ ContextScopeV8 contextScopeV8(proxy->_engine);
834841 if (name->IsString()) {
835842 V8ScriptString nameString(proxy->_engine, v8::Local<v8::String>::Cast(name));
836843 uint id;
@@ -940,16 +947,8 @@ void ScriptMethodV8Proxy::callback(const v8::FunctionCallbackInfo<v8::Value>& ar · 103 unmodified lines
940947 }
941948 ScriptMethodV8Proxy *proxy = reinterpret_cast<ScriptMethodV8Proxy*>(data->GetAlignedPointerFromInternalField(1));
942949
943− // V8TODO: all other V8 callbacks need this too
944− bool isContextChangeNeeded = (proxy->_engine->getContext() != arguments.GetIsolate()->GetCurrentContext());
945− if (isContextChangeNeeded) {
946− qDebug() << "ScriptMethodV8Proxy::callback : changing context";
947− proxy->_engine->pushContext(arguments.GetIsolate()->GetCurrentContext());
948− }
950+ ContextScopeV8 contextScopeV8(proxy->_engine);
949951 proxy->call(arguments);
950− if (isContextChangeNeeded) {
951− proxy->_engine->popContext();
952− }
953952 }
954953
955954 void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& arguments) {
@@ -958,6 +957,7 @@ void ScriptMethodV8Proxy::call(const v8::FunctionCallbackInfo<v8::Value>& argume · 2 unmodified lines
958957 v8::Locker locker(isolate);
959958 v8::Isolate::Scope isolateScope(isolate);
960959 v8::HandleScope handleScope(isolate);
960+ ContextScopeV8 contextScopeV8(_engine);
961961 v8::Context::Scope contextScope(_engine->getContext());
962962 QObject* qobject = _object;
963963 if (!qobject) {