History

script-engine: force callers of register* functions to hold a scope guard

v8 allows us to enter an Isolate::scope multiple times in the same thread, so I widened it to our ScopeGuard as well.

RTUnreal committed 9 months ago

Commit 3a6d77a1 parent 82fb89f14 files · +165 −132Browse files

Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 14 files). Show all

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+25−23
@@ -772,6 +772,8 @@ void ScriptManager::initMetaTypes() { · 771 unmodified lines
772772 }
773773
774774 void ScriptManager::init() {
775+ auto scopeGuard = engine()->getScopeGuard();
776+ auto* sgp = scopeGuard.get();
775777 if (_isInitialized) {
776778 return; // only initialize once
777779 }
@@ -809,7 +811,7 @@ void ScriptManager::init() { · 31 unmodified lines
809811 // NOTE: You do not want to end up creating new instances of singletons here. They will be on the ScriptManager thread
810812 // and are likely to be unusable if we "reset" the ScriptManager by creating a new one (on a whole new thread).
811813
812− scriptEngine->registerGlobalObject("Script", _scriptingInterface.get());
814+ scriptEngine->registerGlobalObject(sgp, "Script", _scriptingInterface.get());
813815
814816 {
815817 // set up Script.require.resolve and Script.require.cache
@@ -822,29 +824,29 @@ void ScriptManager::init() { · 6 unmodified lines
822824 resetModuleCache();
823825 }
824826
825− scriptEngine->registerEnum("Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>());
827+ scriptEngine->registerEnum(sgp, "Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>());
826828
827− scriptEngine->registerGlobalObject("Quat", _quatLibrary.get());
828− scriptEngine->registerGlobalObject("Vec3", _vec3Library.get());
829− scriptEngine->registerGlobalObject("Mat4", _mat4Library.get());
830− scriptEngine->registerGlobalObject("Uuid", _uuidLibrary.get());
829+ scriptEngine->registerGlobalObject(sgp, "Quat", _quatLibrary.get());
830+ scriptEngine->registerGlobalObject(sgp, "Vec3", _vec3Library.get());
831+ scriptEngine->registerGlobalObject(sgp, "Mat4", _mat4Library.get());
832+ scriptEngine->registerGlobalObject(sgp, "Uuid", _uuidLibrary.get());
831833
832834 if (_context != NETWORKLESS_TEST_SCRIPT) {
833835 // This requires networking, we want to avoid the need for it in test scripts
834− scriptEngine->registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
836+ scriptEngine->registerGlobalObject(sgp, "Messages", DependencyManager::get<MessagesClient>().data());
835837 }
836838
837− scriptEngine->registerGlobalObject("console", _consoleScriptingInterface.get());
838− scriptEngine->registerFunction("console", "info", ConsoleScriptingInterface::info, scriptEngine->currentContext()->argumentCount());
839− scriptEngine->registerFunction("console", "log", ConsoleScriptingInterface::log, scriptEngine->currentContext()->argumentCount());
840− scriptEngine->registerFunction("console", "debug", ConsoleScriptingInterface::debug, scriptEngine->currentContext()->argumentCount());
841− scriptEngine->registerFunction("console", "warn", ConsoleScriptingInterface::warn, scriptEngine->currentContext()->argumentCount());
842− scriptEngine->registerFunction("console", "error", ConsoleScriptingInterface::error, scriptEngine->currentContext()->argumentCount());
843− scriptEngine->registerFunction("console", "exception", ConsoleScriptingInterface::exception, scriptEngine->currentContext()->argumentCount());
844− scriptEngine->registerFunction("console", "assert", ConsoleScriptingInterface::assertion, scriptEngine->currentContext()->argumentCount());
845− scriptEngine->registerFunction("console", "group", ConsoleScriptingInterface::group, 1);
846− scriptEngine->registerFunction("console", "groupCollapsed", ConsoleScriptingInterface::groupCollapsed, 1);
847− scriptEngine->registerFunction("console", "groupEnd", ConsoleScriptingInterface::groupEnd, 0);
839+ scriptEngine->registerGlobalObject(sgp, "console", _consoleScriptingInterface.get());
840+ scriptEngine->registerFunction(sgp, "console", "info", ConsoleScriptingInterface::info, scriptEngine->currentContext()->argumentCount());
841+ scriptEngine->registerFunction(sgp, "console", "log", ConsoleScriptingInterface::log, scriptEngine->currentContext()->argumentCount());
842+ scriptEngine->registerFunction(sgp, "console", "debug", ConsoleScriptingInterface::debug, scriptEngine->currentContext()->argumentCount());
843+ scriptEngine->registerFunction(sgp, "console", "warn", ConsoleScriptingInterface::warn, scriptEngine->currentContext()->argumentCount());
844+ scriptEngine->registerFunction(sgp, "console", "error", ConsoleScriptingInterface::error, scriptEngine->currentContext()->argumentCount());
845+ scriptEngine->registerFunction(sgp, "console", "exception", ConsoleScriptingInterface::exception, scriptEngine->currentContext()->argumentCount());
846+ scriptEngine->registerFunction(sgp, "console", "assert", ConsoleScriptingInterface::assertion, scriptEngine->currentContext()->argumentCount());
847+ scriptEngine->registerFunction(sgp, "console", "group", ConsoleScriptingInterface::group, 1);
848+ scriptEngine->registerFunction(sgp, "console", "groupCollapsed", ConsoleScriptingInterface::groupCollapsed, 1);
849+ scriptEngine->registerFunction(sgp, "console", "groupEnd", ConsoleScriptingInterface::groupEnd, 0);
848850
849851 // constants
850852 scriptEngine->globalObject().setProperty("TREE_SCALE", scriptEngine->newValue(TREE_SCALE));
@@ -855,16 +857,16 @@ void ScriptManager::init() { · 4 unmodified lines
855857 scriptEngine->globalObject().setProperty("Resource", resourcePrototype);
856858 scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype);
857859
858− scriptEngine->registerGlobalObject("Assets", _assetScriptingInterface.get());
859− scriptEngine->registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
860+ scriptEngine->registerGlobalObject(sgp, "Assets", _assetScriptingInterface.get());
861+ scriptEngine->registerGlobalObject(sgp, "Resources", DependencyManager::get<ResourceScriptingInterface>().data());
860862
861− scriptEngine->registerGlobalObject("DebugDraw", &DebugDraw::getInstance());
863+ scriptEngine->registerGlobalObject(sgp, "DebugDraw", &DebugDraw::getInstance());
862864
863− scriptEngine->registerGlobalObject("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data());
865+ scriptEngine->registerGlobalObject(sgp, "UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data());
864866 }
865867
866868 #if DEV_BUILD || PR_BUILD
867− scriptEngine->registerGlobalObject("StackTest", new StackTestScriptingInterface(this));
869+ scriptEngine->registerGlobalObject(sgp, "StackTest", new StackTestScriptingInterface(this));
868870 #endif
869871
870872 qCDebug(scriptengine) << "Engine initialized";