History

* Inline / duplicate exception checking per CR feedback * Coding standards

humbletim committed 9 years ago

Commit 3ad3fd41 parent 0b73cef3 files · +24 −76Browse files

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

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+22−23
@@ -899,9 +899,11 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 898 unmodified lines
899899
900900 QScriptValue result;
901901 {
902− // catch any exceptions throw by nested operations
903− ExceptionEmitter tryCatch(this, __FUNCTION__);
904902 result = BaseScriptEngine::evaluate(program);
903+ if (!isEvaluating() && hasUncaughtException()) {
904+ emit unhandledException(cloneUncaughtException(__FUNCTION__));
905+ clearExceptions();
906+ }
905907 }
906908 return result;
907909 }
@@ -923,9 +925,11 @@ void ScriptEngine::run() { · 15 unmodified lines
923925 emit runningStateChanged();
924926
925927 {
926− // catch any exceptions throw by nested operations
927− ExceptionEmitter tryCatch(this, __FUNCTION__);
928928 evaluate(_scriptContents, _fileNameString);
929+ if (!isEvaluating() && hasUncaughtException()) {
930+ emit unhandledException(cloneUncaughtException(__FUNCTION__));
931+ clearExceptions();
932+ }
929933 }
930934 #ifdef _WIN32
931935 // VS13 does not sleep_until unless it uses the system_clock, see:
@@ -1361,16 +1365,10 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 429 unmodified lines
13611365 evaluate(contents, url.toString());
13621366 };
13631367
1364− ExceptionEmitter tryCatch(this, "include");
13651368 doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
1366− if (tryCatch.hasPending()) {
1367− // match previous include behavior where possible by logging, not propagating, exceptions.
1368− auto err = tryCatch.pending();
1369− emit unhandledException(err);
1370− // FIXME: to be revisited with next PR 21114-part3 for compat with require/module
1371− //if (tryCatch.wouldEmit()) {
1372− tryCatch.consume();
1373− //}
1369+ if (hasUncaughtException()) {
1370+ emit unhandledException(cloneUncaughtException(__FUNCTION__));
1371+ clearExceptions();
13741372 }
13751373 } else {
13761374 scriptWarningMessage("Script.include() skipping evaluation of previously included url:" + url.toString());
@@ -1508,7 +1506,7 @@ void ScriptEngine::deferLoadEntityScript(const EntityItemID& entityID, const QSt · 131 unmodified lines
15081506 for (int i=0; i < RETRY_ATTEMPT_BATCH && !_pendingLoadEntities.isEmpty(); i++) {
15091507 auto retry = _pendingLoadEntities.takeFirst();
15101508 qCDebug(scriptengine) << "deferLoadEntityScript.retry[" << i << "]:" << retry.entityID << retry.entityScript;
1511− if(!_entityScripts.contains(retry.entityID)) {
1509+ if (!_entityScripts.contains(retry.entityID)) {
15121510 qCDebug(scriptengine) << "deferLoadEntityScript.retry -- entity details gone (entity deleted?)";
15131511 } else {
15141512 auto details = _entityScripts[retry.entityID];
@@ -1715,7 +1713,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 200 unmodified lines
17151713 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);
17161714 QScriptValue testConstructor, exception;
17171715 {
1718− ExceptionEmitter tryCatch(&sandbox, QString("(preflight %1)").arg(entityID.toString()));
17191716 QTimer timeout;
17201717 timeout.setSingleShot(true);
17211718 timeout.start(SANDBOX_TIMEOUT);
@@ -1731,8 +1728,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 9 unmodified lines
17311728
17321729 testConstructor = sandbox.evaluate(program);
17331730
1734− if (tryCatch.hasPending()) {
1735− exception = tryCatch.consume();
1731+ if (sandbox.hasUncaughtException()) {
1732+ exception = sandbox.cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
1733+ sandbox.clearExceptions();
17361734 } else if (testConstructor.isError()) {
17371735 exception = testConstructor;
17381736 }
@@ -1780,13 +1778,12 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 41 unmodified lines
17801778 QScriptValue entityScriptConstructor, entityScriptObject;
17811779 QUrl sandboxURL = currentSandboxURL.isEmpty() ? scriptOrURL : currentSandboxURL;
17821780 auto initialization = [&]{
1783− ExceptionEmitter tryCatch(this, "(construct " + entityID.toString() + ")");
1784−
17851781 entityScriptConstructor = evaluate(contents, fileName);
17861782 entityScriptObject = entityScriptConstructor.construct();
17871783
1788− if (tryCatch.hasPending()) {
1789− entityScriptObject = tryCatch.consume();
1784+ if (hasUncaughtException()) {
1785+ entityScriptObject = cloneUncaughtException("(construct " + entityID.toString() + ")");
1786+ clearExceptions();
17901787 }
17911788 };
17921789
@@ -1914,8 +1911,6 @@ void ScriptEngine::doWithEnvironment(const EntityItemID& entityID, const QUrl& s · 121 unmodified lines
19141911 currentEntityIdentifier = entityID;
19151912 currentSandboxURL = sandboxURL;
19161913
1917− ExceptionEmitter tryCatcher(this, !entityID.isNull() ? entityID.toString() : __FUNCTION__);
1918−
19191914 #if DEBUG_CURRENT_ENTITY
19201915 QScriptValue oldData = this->globalObject().property("debugEntityID");
19211916 this->globalObject().setProperty("debugEntityID", entityID.toScriptValue(this)); // Make the entityID available to javascript as a global.
@@ -1924,6 +1919,10 @@ void ScriptEngine::doWithEnvironment(const EntityItemID& entityID, const QUrl& s · 2 unmodified lines
19241919 #else
19251920 operation();
19261921 #endif
1922+ if (!isEvaluating() && hasUncaughtException()) {
1923+ emit unhandledException(cloneUncaughtException(!entityID.isNull() ? entityID.toString() : __FUNCTION__));
1924+ clearExceptions();
1925+ }
19271926 currentEntityIdentifier = oldIdentifier;
19281927 currentSandboxURL = oldSandboxURL;
19291928 }