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
8787
8888 Q_DECLARE_METATYPE(ExternalResource::Bucket);
8989
90+Q_DECLARE_METATYPE(ScriptValuePointer);
91+
9092 // --- Static script initialization registry
9193
9294 static ScriptManager::StaticInitializerNode* rootInitializer = nullptr;
@@ -325,6 +327,7 @@ void ScriptManager::runInThread() { · 232 unmodified lines
325327 QThread* workerThread = new QThread();
326328 QString name = QString("js:") + getFilename().replace("about:","");
327329 workerThread->setObjectName(name);
330+ _engine->setThread(workerThread);
328331 moveToThread(workerThread);
329332
330333 // NOTE: If you connect any essential signals for proper shutdown or cleanup of
@@ -1256,13 +1259,13 @@ ScriptValuePointer ScriptManager::currentModule() { · 925 unmodified lines
12561259 }
12571260 auto jsRequire = _engine->globalObject()->property("Script")->property("require");
12581261 auto cache = jsRequire->property("cache");
1259− auto candidate = ScriptValuePointer();
1262+ ScriptValuePointer candidate;
12601263 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()) {
12621265 auto contextInfo = context->functionContext();
12631266 candidate = cache->property(contextInfo->fileName());
12641267 }
1265− if (!candidate->isObject()) {
1268+ if (!candidate || !candidate->isObject()) {
12661269 return ScriptValuePointer();
12671270 }
12681271 return candidate;
@@ -1589,8 +1592,8 @@ void ScriptManager::include(const QStringList& includeFiles, ScriptValuePointer · 320 unmodified lines
15891592 }
15901593 _parentURL = parentURL;
15911594
1592− if (callback->isFunction()) {
1593− callWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, ScriptValuePointer(callback), ScriptValuePointer(), ScriptValueList());
1595+ if (callback && callback->isFunction()) {
1596+ callWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, callback, ScriptValuePointer(), ScriptValueList());
15941597 }
15951598
15961599 loader->deleteLater();
@@ -1603,7 +1606,7 @@ void ScriptManager::include(const QStringList& includeFiles, ScriptValuePointer · 6 unmodified lines
16031606
16041607 loader->start(processLevelMaxRetries);
16051608
1606− if (!callback->isFunction() && !loader->isFinished()) {
1609+ if ((!callback || !callback->isFunction()) && !loader->isFinished()) {
16071610 QEventLoop loop;
16081611 QObject::connect(loader, &BatchLoader::finished, &loop, &QEventLoop::quit);
16091612 loop.exec();
@@ -1963,7 +1966,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 353 unmodified lines
19631966 if (sandbox->hasUncaughtException()) {
19641967 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
19651968 sandbox->clearExceptions();
1966− } else if (testConstructor->isError()) {
1969+ } else if (testConstructor && testConstructor->isError()) {
19671970 exception = testConstructor;
19681971 }
19691972 } else {
@@ -2038,7 +2041,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 68 unmodified lines
20382041 if (sandbox->hasUncaughtException()) {
20392042 exception = sandbox->cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
20402043 sandbox->clearExceptions();
2041− } else if (testConstructor->isError()) {
2044+ } else if (testConstructor && testConstructor->isError()) {
20422045 exception = testConstructor;
20432046 }
20442047 }
@@ -2048,7 +2051,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 3 unmodified lines
20482051 // exception = makeError("UNSAFE_ENTITY_SCRIPTS == 0");
20492052 }
20502053
2051− if (exception->isError()) {
2054+ if (exception && exception->isError()) {
20522055 // create a local copy using makeError to decouple from the sandbox engine
20532056 exception = _engine->makeError(exception);
20542057 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);
@@ -2057,7 +2060,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 2 unmodified lines
20572060 }
20582061
20592062 // CONSTRUCTOR VIABILITY
2060− if (!testConstructor->isFunction()) {
2063+ if (!testConstructor || !testConstructor->isFunction()) {
20612064 QString testConstructorType = QString(testConstructor->toVariant().typeName());
20622065 if (testConstructorType == "") {
20632066 testConstructorType = "empty";
@@ -2100,7 +2103,7 @@ void ScriptManager::entityScriptContentAvailable(const EntityItemID& entityID, c · 36 unmodified lines
21002103
21012104 doWithEnvironment(entityID, sandboxURL, initialization);
21022105
2103− if (entityScriptObject->isError()) {
2106+ if (entityScriptObject && entityScriptObject->isError()) {
21042107 auto exception = entityScriptObject;
21052108 setError(formatException(exception, _enableExtendedJSExceptions.get()), EntityScriptStatus::ERROR_RUNNING_SCRIPT);
21062109 emit unhandledException(exception);