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