Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 3 files). Show all
Unified · Split
| @@ -899,9 +899,11 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi · 898 unmodified lines | ||
| 899 | 899 | |
| 900 | 900 | QScriptValue result; |
| 901 | 901 | { |
| 902 | − // catch any exceptions throw by nested operations | |
| 903 | − ExceptionEmitter tryCatch(this, __FUNCTION__); | |
| 904 | 902 | result = BaseScriptEngine::evaluate(program); |
| 903 | + if (!isEvaluating() && hasUncaughtException()) { | |
| 904 | + emit unhandledException(cloneUncaughtException(__FUNCTION__)); | |
| 905 | + clearExceptions(); | |
| 906 | + } | |
| 905 | 907 | } |
| 906 | 908 | return result; |
| 907 | 909 | } |
| @@ -923,9 +925,11 @@ void ScriptEngine::run() { · 15 unmodified lines | ||
| 923 | 925 | emit runningStateChanged(); |
| 924 | 926 | |
| 925 | 927 | { |
| 926 | − // catch any exceptions throw by nested operations | |
| 927 | − ExceptionEmitter tryCatch(this, __FUNCTION__); | |
| 928 | 928 | evaluate(_scriptContents, _fileNameString); |
| 929 | + if (!isEvaluating() && hasUncaughtException()) { | |
| 930 | + emit unhandledException(cloneUncaughtException(__FUNCTION__)); | |
| 931 | + clearExceptions(); | |
| 932 | + } | |
| 929 | 933 | } |
| 930 | 934 | #ifdef _WIN32 |
| 931 | 935 | // 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 | ||
| 1361 | 1365 | evaluate(contents, url.toString()); |
| 1362 | 1366 | }; |
| 1363 | 1367 | |
| 1364 | − ExceptionEmitter tryCatch(this, "include"); | |
| 1365 | 1368 | 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(); | |
| 1374 | 1372 | } |
| 1375 | 1373 | } else { |
| 1376 | 1374 | 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 | ||
| 1508 | 1506 | for (int i=0; i < RETRY_ATTEMPT_BATCH && !_pendingLoadEntities.isEmpty(); i++) { |
| 1509 | 1507 | auto retry = _pendingLoadEntities.takeFirst(); |
| 1510 | 1508 | qCDebug(scriptengine) << "deferLoadEntityScript.retry[" << i << "]:" << retry.entityID << retry.entityScript; |
| 1511 | − if(!_entityScripts.contains(retry.entityID)) { | |
| 1509 | + if (!_entityScripts.contains(retry.entityID)) { | |
| 1512 | 1510 | qCDebug(scriptengine) << "deferLoadEntityScript.retry -- entity details gone (entity deleted?)"; |
| 1513 | 1511 | } else { |
| 1514 | 1512 | auto details = _entityScripts[retry.entityID]; |
| @@ -1715,7 +1713,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 200 unmodified lines | ||
| 1715 | 1713 | sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT); |
| 1716 | 1714 | QScriptValue testConstructor, exception; |
| 1717 | 1715 | { |
| 1718 | − ExceptionEmitter tryCatch(&sandbox, QString("(preflight %1)").arg(entityID.toString())); | |
| 1719 | 1716 | QTimer timeout; |
| 1720 | 1717 | timeout.setSingleShot(true); |
| 1721 | 1718 | timeout.start(SANDBOX_TIMEOUT); |
| @@ -1731,8 +1728,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 9 unmodified lines | ||
| 1731 | 1728 | |
| 1732 | 1729 | testConstructor = sandbox.evaluate(program); |
| 1733 | 1730 | |
| 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(); | |
| 1736 | 1734 | } else if (testConstructor.isError()) { |
| 1737 | 1735 | exception = testConstructor; |
| 1738 | 1736 | } |
| @@ -1780,13 +1778,12 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 41 unmodified lines | ||
| 1780 | 1778 | QScriptValue entityScriptConstructor, entityScriptObject; |
| 1781 | 1779 | QUrl sandboxURL = currentSandboxURL.isEmpty() ? scriptOrURL : currentSandboxURL; |
| 1782 | 1780 | auto initialization = [&]{ |
| 1783 | − ExceptionEmitter tryCatch(this, "(construct " + entityID.toString() + ")"); | |
| 1784 | − | |
| 1785 | 1781 | entityScriptConstructor = evaluate(contents, fileName); |
| 1786 | 1782 | entityScriptObject = entityScriptConstructor.construct(); |
| 1787 | 1783 | |
| 1788 | − if (tryCatch.hasPending()) { | |
| 1789 | − entityScriptObject = tryCatch.consume(); | |
| 1784 | + if (hasUncaughtException()) { | |
| 1785 | + entityScriptObject = cloneUncaughtException("(construct " + entityID.toString() + ")"); | |
| 1786 | + clearExceptions(); | |
| 1790 | 1787 | } |
| 1791 | 1788 | }; |
| 1792 | 1789 | |
| @@ -1914,8 +1911,6 @@ void ScriptEngine::doWithEnvironment(const EntityItemID& entityID, const QUrl& s · 121 unmodified lines | ||
| 1914 | 1911 | currentEntityIdentifier = entityID; |
| 1915 | 1912 | currentSandboxURL = sandboxURL; |
| 1916 | 1913 | |
| 1917 | − ExceptionEmitter tryCatcher(this, !entityID.isNull() ? entityID.toString() : __FUNCTION__); | |
| 1918 | − | |
| 1919 | 1914 | #if DEBUG_CURRENT_ENTITY |
| 1920 | 1915 | QScriptValue oldData = this->globalObject().property("debugEntityID"); |
| 1921 | 1916 | 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 | ||
| 1924 | 1919 | #else |
| 1925 | 1920 | operation(); |
| 1926 | 1921 | #endif |
| 1922 | + if (!isEvaluating() && hasUncaughtException()) { | |
| 1923 | + emit unhandledException(cloneUncaughtException(!entityID.isNull() ? entityID.toString() : __FUNCTION__)); | |
| 1924 | + clearExceptions(); | |
| 1925 | + } | |
| 1927 | 1926 | currentEntityIdentifier = oldIdentifier; |
| 1928 | 1927 | currentSandboxURL = oldSandboxURL; |
| 1929 | 1928 | } |