v8 allows us to enter an Isolate::scope multiple times in the same thread, so I widened it to our ScopeGuard as well.
Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 14 files). Show all
Unified · Split
| @@ -772,6 +772,8 @@ void ScriptManager::initMetaTypes() { · 771 unmodified lines | ||
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | void ScriptManager::init() { |
| 775 | + auto scopeGuard = engine()->getScopeGuard(); | |
| 776 | + auto* sgp = scopeGuard.get(); | |
| 775 | 777 | if (_isInitialized) { |
| 776 | 778 | return; // only initialize once |
| 777 | 779 | } |
| @@ -809,7 +811,7 @@ void ScriptManager::init() { · 31 unmodified lines | ||
| 809 | 811 | // NOTE: You do not want to end up creating new instances of singletons here. They will be on the ScriptManager thread |
| 810 | 812 | // and are likely to be unusable if we "reset" the ScriptManager by creating a new one (on a whole new thread). |
| 811 | 813 | |
| 812 | − scriptEngine->registerGlobalObject("Script", _scriptingInterface.get()); | |
| 814 | + scriptEngine->registerGlobalObject(sgp, "Script", _scriptingInterface.get()); | |
| 813 | 815 | |
| 814 | 816 | { |
| 815 | 817 | // set up Script.require.resolve and Script.require.cache |
| @@ -822,29 +824,29 @@ void ScriptManager::init() { · 6 unmodified lines | ||
| 822 | 824 | resetModuleCache(); |
| 823 | 825 | } |
| 824 | 826 | |
| 825 | − scriptEngine->registerEnum("Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>()); | |
| 827 | + scriptEngine->registerEnum(sgp, "Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>()); | |
| 826 | 828 | |
| 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()); | |
| 831 | 833 | |
| 832 | 834 | if (_context != NETWORKLESS_TEST_SCRIPT) { |
| 833 | 835 | // 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()); | |
| 835 | 837 | } |
| 836 | 838 | |
| 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); | |
| 848 | 850 | |
| 849 | 851 | // constants |
| 850 | 852 | scriptEngine->globalObject().setProperty("TREE_SCALE", scriptEngine->newValue(TREE_SCALE)); |
| @@ -855,16 +857,16 @@ void ScriptManager::init() { · 4 unmodified lines | ||
| 855 | 857 | scriptEngine->globalObject().setProperty("Resource", resourcePrototype); |
| 856 | 858 | scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype); |
| 857 | 859 | |
| 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()); | |
| 860 | 862 | |
| 861 | − scriptEngine->registerGlobalObject("DebugDraw", &DebugDraw::getInstance()); | |
| 863 | + scriptEngine->registerGlobalObject(sgp, "DebugDraw", &DebugDraw::getInstance()); | |
| 862 | 864 | |
| 863 | − scriptEngine->registerGlobalObject("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data()); | |
| 865 | + scriptEngine->registerGlobalObject(sgp, "UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data()); | |
| 864 | 866 | } |
| 865 | 867 | |
| 866 | 868 | #if DEV_BUILD || PR_BUILD |
| 867 | − scriptEngine->registerGlobalObject("StackTest", new StackTestScriptingInterface(this)); | |
| 869 | + scriptEngine->registerGlobalObject(sgp, "StackTest", new StackTestScriptingInterface(this)); | |
| 868 | 870 | #endif |
| 869 | 871 | |
| 870 | 872 | qCDebug(scriptengine) << "Engine initialized"; |