History

Fix V8 scope performance issue on libnode22

ksuprynowicz committed 11 months ago

Commit a9bd0781 parent 4aad6b218 files · +298 −349Browse files

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

Unified · Split

libraries/script-engine/src/ScriptManager.cpp+22−6
@@ -265,6 +265,11 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 264 unmodified lines
265 _scriptContents(scriptContents),265 _scriptContents(scriptContents),
266 _timerFunctionMap(),266 _timerFunctionMap(),
267 _fileNameString(fileNameString),267 _fileNameString(fileNameString),
268 _quatLibrary(new Quat()),
269 _vec3Library(new Vec3()),
270 _mat4Library(new Mat4()),
271 _uuidLibrary(new ScriptUUID()),
272 _consoleScriptingInterface(new ConsoleScriptingInterface()),
268 _assetScriptingInterface(new AssetScriptingInterface(this))273 _assetScriptingInterface(new AssetScriptingInterface(this))
269{274{
270 275
@@ -377,10 +382,20 @@ bool ScriptManager::isDebugMode() const { · 106 unmodified lines
377}382}
378 383
379ScriptManager::~ScriptManager() {384ScriptManager::~ScriptManager() {
385 auto scopeGuard = engine()->getScopeGuard();
380 qDebug() << "ScriptManager::~ScriptManager() : Script manager deleted, type: " << _type << " name: " << _fileNameString;386 qDebug() << "ScriptManager::~ScriptManager() : Script manager deleted, type: " << _type << " name: " << _fileNameString;
381 if (_type == ScriptManager::Type::ENTITY_CLIENT) {387 if (_type == ScriptManager::Type::ENTITY_CLIENT) {
382 printf("ScriptManager::~ScriptManager");388 printf("ScriptManager::~ScriptManager");
383 }389 }
390 // We need to make sure that these get deleted before the script engine.
391 _scriptingInterface.reset();
392 _quatLibrary.reset();
393 _vec3Library.reset();
394 _mat4Library.reset();
395 _uuidLibrary.reset();
396 _consoleScriptingInterface.reset();
397 _assetScriptingInterface.reset();
398 _returnValue = ScriptValue();
384 _isDeleted = true;399 _isDeleted = true;
385}400}
386 401
@@ -804,17 +819,17 @@ void ScriptManager::init() { · 417 unmodified lines
804 819
805 scriptEngine->registerEnum("Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>());820 scriptEngine->registerEnum("Script.ExternalPaths", QMetaEnum::fromType<ExternalResource::Bucket>());
806 821
807 scriptEngine->registerGlobalObject("Quat", &_quatLibrary);822 scriptEngine->registerGlobalObject("Quat", _quatLibrary.get());
808 scriptEngine->registerGlobalObject("Vec3", &_vec3Library);823 scriptEngine->registerGlobalObject("Vec3", _vec3Library.get());
809 scriptEngine->registerGlobalObject("Mat4", &_mat4Library);824 scriptEngine->registerGlobalObject("Mat4", _mat4Library.get());
810 scriptEngine->registerGlobalObject("Uuid", &_uuidLibrary);825 scriptEngine->registerGlobalObject("Uuid", _uuidLibrary.get());
811 826
812 if (_context != NETWORKLESS_TEST_SCRIPT) {827 if (_context != NETWORKLESS_TEST_SCRIPT) {
813 // This requires networking, we want to avoid the need for it in test scripts828 // This requires networking, we want to avoid the need for it in test scripts
814 scriptEngine->registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());829 scriptEngine->registerGlobalObject("Messages", DependencyManager::get<MessagesClient>().data());
815 }830 }
816 831
817 scriptEngine->registerGlobalObject("console", &_consoleScriptingInterface);832 scriptEngine->registerGlobalObject("console", _consoleScriptingInterface.get());
818 scriptEngine->registerFunction("console", "info", ConsoleScriptingInterface::info, scriptEngine->currentContext()->argumentCount());833 scriptEngine->registerFunction("console", "info", ConsoleScriptingInterface::info, scriptEngine->currentContext()->argumentCount());
819 scriptEngine->registerFunction("console", "log", ConsoleScriptingInterface::log, scriptEngine->currentContext()->argumentCount());834 scriptEngine->registerFunction("console", "log", ConsoleScriptingInterface::log, scriptEngine->currentContext()->argumentCount());
820 scriptEngine->registerFunction("console", "debug", ConsoleScriptingInterface::debug, scriptEngine->currentContext()->argumentCount());835 scriptEngine->registerFunction("console", "debug", ConsoleScriptingInterface::debug, scriptEngine->currentContext()->argumentCount());
@@ -835,7 +850,7 @@ void ScriptManager::init() { · 14 unmodified lines
835 scriptEngine->globalObject().setProperty("Resource", resourcePrototype);850 scriptEngine->globalObject().setProperty("Resource", resourcePrototype);
836 scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype);851 scriptEngine->setDefaultPrototype(qMetaTypeId<ScriptableResource*>(), resourcePrototype);
837 852
838 scriptEngine->registerGlobalObject("Assets", _assetScriptingInterface);853 scriptEngine->registerGlobalObject("Assets", _assetScriptingInterface.get());
839 scriptEngine->registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());854 scriptEngine->registerGlobalObject("Resources", DependencyManager::get<ResourceScriptingInterface>().data());
840 855
841 scriptEngine->registerGlobalObject("DebugDraw", &DebugDraw::getInstance());856 scriptEngine->registerGlobalObject("DebugDraw", &DebugDraw::getInstance());
@@ -941,6 +956,7 @@ bool ScriptManager::isStopped() const { · 99 unmodified lines
941}956}
942 957
943void ScriptManager::run() {958void ScriptManager::run() {
959 auto scopeGuard = _engine->getScopeGuard();
944 if (QThread::currentThread() != qApp->thread() && _context == Context::CLIENT_SCRIPT) {960 if (QThread::currentThread() != qApp->thread() && _context == Context::CLIENT_SCRIPT) {
945 // Flag that we're allowed to access local HTML files on UI created from C++ calls on this thread961 // Flag that we're allowed to access local HTML files on UI created from C++ calls on this thread
946 // (because we're a client script)962 // (because we're a client script)