History

early smoketesting

Heather Anderson committed 5 years ago

Commit f209c511 parent 5f2b2c914 files · +150 −91Browse 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+14−11
@@ -87,6 +87,8 @@ int scriptManagerPointerMetaID = qRegisterMetaType<ScriptManagerPointer>(); · 86 unmodified lines
87 87
88Q_DECLARE_METATYPE(ExternalResource::Bucket);88Q_DECLARE_METATYPE(ExternalResource::Bucket);
89 89
90Q_DECLARE_METATYPE(ScriptValuePointer);
91
90// --- Static script initialization registry92// --- Static script initialization registry
91 93
92static ScriptManager::StaticInitializerNode* rootInitializer = nullptr;94static ScriptManager::StaticInitializerNode* rootInitializer = nullptr;
@@ -325,6 +327,7 @@ void ScriptManager::runInThread() { · 232 unmodified lines
325 QThread* workerThread = new QThread();327 QThread* workerThread = new QThread();
326 QString name = QString("js:") + getFilename().replace("about:","");328 QString name = QString("js:") + getFilename().replace("about:","");
327 workerThread->setObjectName(name);329 workerThread->setObjectName(name);
330 _engine->setThread(workerThread);
328 moveToThread(workerThread);331 moveToThread(workerThread);
329 332
330 // NOTE: If you connect any essential signals for proper shutdown or cleanup of333 // NOTE: If you connect any essential signals for proper shutdown or cleanup of
@@ -1256,13 +1259,13 @@ ScriptValuePointer ScriptManager::currentModule() { · 925 unmodified lines
1256 }1259 }
1257 auto jsRequire = _engine->globalObject()->property("Script")->property("require");1260 auto jsRequire = _engine->globalObject()->property("Script")->property("require");
1258 auto cache = jsRequire->property("cache");1261 auto cache = jsRequire->property("cache");
1259 auto candidate = ScriptValuePointer();1262 ScriptValuePointer candidate;
1260 ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan1263 ScriptContextPointer parentContext; // using this variable to maintain parent variable lifespan
1261 for (auto context = _engine->currentContext(); context && !candidate->isObject(); parentContext = context->parentContext(), context = parentContext.data()) {1264 for (auto context = _engine->currentContext(); context && (!candidate || !candidate->isObject()); parentContext = context->parentContext(), context = parentContext.data()) {
1262 auto contextInfo = context->functionContext();1265 auto contextInfo = context->functionContext();
1263 candidate = cache->property(contextInfo->fileName());1266 candidate = cache->property(contextInfo->fileName());
1264 }1267 }
1265 if (!candidate->isObject()) {1268 if (!candidate || !candidate->isObject()) {
1266 return ScriptValuePointer();1269 return ScriptValuePointer();
1267 }1270 }
1268 return candidate;1271 return candidate;
@@ -1589,8 +1592,8 @@ void ScriptManager::include(const QStringList& includeFiles, ScriptValuePointer · 320 unmodified lines
1589 }1592 }
1590 _parentURL = parentURL;1593 _parentURL = parentURL;
1591 1594
1592 if (callback->isFunction()) {1595 if (callback && callback->isFunction()) {
1593 callWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, ScriptValuePointer(callback), ScriptValuePointer(), ScriptValueList());1596 callWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, callback, ScriptValuePointer(), ScriptValueList());
1594 }1597 }
1595 1598
1596 loader->deleteLater();1599 loader->deleteLater();
@@ -1603,7 +1606,7 @@ void ScriptManager::include(const QStringList& includeFiles, ScriptValuePointer · 6 unmodified lines
1603 1606
1604 loader->start(processLevelMaxRetries);1607 loader->start(processLevelMaxRetries);
1605 1608
1606 if (!callback->isFunction() && !loader->isFinished()) {1609 if ((!callback || !callback->isFunction()) && !loader->isFinished()) {
1607 QEventLoop loop;1610 QEventLoop loop;
1608 QObject::connect(loader, &BatchLoader::finished, &loop, &QEventLoop::quit);1611 QObject::connect(loader, &BatchLoader::finished, &loop, &QEventLoop::quit);
1609 loop.exec();1612 loop.exec();
@@ -1963,7 +1966,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 353 unmodified lines
1963 if (sandbox->hasUncaughtException()) {1966 if (sandbox->hasUncaughtException()) {
1964 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));1967 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
1965 sandbox->clearExceptions();1968 sandbox->clearExceptions();
1966 } else if (testConstructor->isError()) {1969 } else if (testConstructor && testConstructor->isError()) {
1967 exception = testConstructor;1970 exception = testConstructor;
1968 }1971 }
1969 } else {1972 } else {
@@ -2038,7 +2041,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 68 unmodified lines
2038 if (sandbox->hasUncaughtException()) {2041 if (sandbox->hasUncaughtException()) {
2039 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));2042 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
2040 sandbox->clearExceptions();2043 sandbox->clearExceptions();
2041 } else if (testConstructor->isError()) {2044 } else if (testConstructor && testConstructor->isError()) {
2042 exception = testConstructor;2045 exception = testConstructor;
2043 }2046 }
2044 }2047 }
@@ -2048,7 +2051,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 3 unmodified lines
2048 // exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");2051 // exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");
2049 }2052 }
2050 2053
2051 if (exception->isError()) {2054 if (exception && exception->isError()) {
2052 // create a local copy using makeError to decouple from the sandbox engine2055 // create a local copy using makeError to decouple from the sandbox engine
2053 exception = _engine->makeError(exception);2056 exception = _engine->makeError(exception);
2054 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);2057 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);
@@ -2057,7 +2060,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 2 unmodified lines
2057 }2060 }
2058 2061
2059 // CONSTRUCTOR VIABILITY2062 // CONSTRUCTOR VIABILITY
2060 if (!testConstructor->isFunction()) {2063 if (!testConstructor || !testConstructor->isFunction()) {
2061 QString testConstructorType = QString(testConstructor->toVariant().typeName());2064 QString testConstructorType = QString(testConstructor->toVariant().typeName());
2062 if (testConstructorType == "") {2065 if (testConstructorType == "") {
2063 testConstructorType = "empty";2066 testConstructorType = "empty";
@@ -2100,7 +2103,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 36 unmodified lines
2100 2103
2101 doWithEnvironment(entityID, sandboxURL, initialization);2104 doWithEnvironment(entityID, sandboxURL, initialization);
2102 2105
2103 if (entityScriptObject->isError()) {2106 if (entityScriptObject && entityScriptObject->isError()) {
2104 auto exception = entityScriptObject;2107 auto exception = entityScriptObject;
2105 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);2108 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);
2106 emit unhandledException(exception);2109 emit unhandledException(exception);