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
899 899
900 QScriptValue result;900 QScriptValue result;
901 {901 {
902 // catch any exceptions throw by nested operations
903 ExceptionEmitter tryCatch(this, __FUNCTION__);
904 result = BaseScriptEngine::evaluate(program);902 result = BaseScriptEngine::evaluate(program);
903 if (!isEvaluating() && hasUncaughtException()) {
904 emit unhandledException(cloneUncaughtException(__FUNCTION__));
905 clearExceptions();
906 }
905 }907 }
906 return result;908 return result;
907}909}
@@ -923,9 +925,11 @@ void ScriptEngine::run() { · 15 unmodified lines
923 emit runningStateChanged();925 emit runningStateChanged();
924 926
925 {927 {
926 // catch any exceptions throw by nested operations
927 ExceptionEmitter tryCatch(this, __FUNCTION__);
928 evaluate(_scriptContents, _fileNameString);928 evaluate(_scriptContents, _fileNameString);
929 if (!isEvaluating() && hasUncaughtException()) {
930 emit unhandledException(cloneUncaughtException(__FUNCTION__));
931 clearExceptions();
932 }
929 }933 }
930#ifdef _WIN32934#ifdef _WIN32
931 // VS13 does not sleep_until unless it uses the system_clock, see: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 evaluate(contents, url.toString());1365 evaluate(contents, url.toString());
1362 };1366 };
1363 1367
1364 ExceptionEmitter tryCatch(this, "include");
1365 doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);1368 doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
1366 if (tryCatch.hasPending()) {1369 if (hasUncaughtException()) {
1367 // match previous include behavior where possible by logging, not propagating, exceptions.1370 emit unhandledException(cloneUncaughtException(__FUNCTION__));
1368 auto err = tryCatch.pending();1371 clearExceptions();
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 //}
1374 }1372 }
1375 } else {1373 } else {
1376 scriptWarningMessage("Script.include() skipping evaluation of previously included url:" + url.toString());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 for (int i=0; i < RETRY_ATTEMPT_BATCH && !_pendingLoadEntities.isEmpty(); i++) {1506 for (int i=0; i < RETRY_ATTEMPT_BATCH && !_pendingLoadEntities.isEmpty(); i++) {
1509 auto retry = _pendingLoadEntities.takeFirst();1507 auto retry = _pendingLoadEntities.takeFirst();
1510 qCDebug(scriptengine) << "deferLoadEntityScript.retry[" << i << "]:" << retry.entityID << retry.entityScript;1508 qCDebug(scriptengine) << "deferLoadEntityScript.retry[" << i << "]:" << retry.entityID << retry.entityScript;
1511 if(!_entityScripts.contains(retry.entityID)) {1509 if (!_entityScripts.contains(retry.entityID)) {
1512 qCDebug(scriptengine) << "deferLoadEntityScript.retry -- entity details gone (entity deleted?)";1510 qCDebug(scriptengine) << "deferLoadEntityScript.retry -- entity details gone (entity deleted?)";
1513 } else {1511 } else {
1514 auto details = _entityScripts[retry.entityID];1512 auto details = _entityScripts[retry.entityID];
@@ -1715,7 +1713,6 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 200 unmodified lines
1715 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);1713 sandbox.setProcessEventsInterval(SANDBOX_TIMEOUT);
1716 QScriptValue testConstructor, exception;1714 QScriptValue testConstructor, exception;
1717 {1715 {
1718 ExceptionEmitter tryCatch(&sandbox, QString("(preflight %1)").arg(entityID.toString()));
1719 QTimer timeout;1716 QTimer timeout;
1720 timeout.setSingleShot(true);1717 timeout.setSingleShot(true);
1721 timeout.start(SANDBOX_TIMEOUT);1718 timeout.start(SANDBOX_TIMEOUT);
@@ -1731,8 +1728,9 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 9 unmodified lines
1731 1728
1732 testConstructor = sandbox.evaluate(program);1729 testConstructor = sandbox.evaluate(program);
1733 1730
1734 if (tryCatch.hasPending()) {1731 if (sandbox.hasUncaughtException()) {
1735 exception = tryCatch.consume();1732 exception = sandbox.cloneUncaughtException(QString("(preflight %1)").arg(entityID.toString()));
1733 sandbox.clearExceptions();
1736 } else if (testConstructor.isError()) {1734 } else if (testConstructor.isError()) {
1737 exception = testConstructor;1735 exception = testConstructor;
1738 }1736 }
@@ -1780,13 +1778,12 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 41 unmodified lines
1780 QScriptValue entityScriptConstructor, entityScriptObject;1778 QScriptValue entityScriptConstructor, entityScriptObject;
1781 QUrl sandboxURL = currentSandboxURL.isEmpty() ? scriptOrURL : currentSandboxURL;1779 QUrl sandboxURL = currentSandboxURL.isEmpty() ? scriptOrURL : currentSandboxURL;
1782 auto initialization = [&]{1780 auto initialization = [&]{
1783 ExceptionEmitter tryCatch(this, "(construct " + entityID.toString() + ")");
1784
1785 entityScriptConstructor = evaluate(contents, fileName);1781 entityScriptConstructor = evaluate(contents, fileName);
1786 entityScriptObject = entityScriptConstructor.construct();1782 entityScriptObject = entityScriptConstructor.construct();
1787 1783
1788 if (tryCatch.hasPending()) {1784 if (hasUncaughtException()) {
1789 entityScriptObject = tryCatch.consume();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 currentEntityIdentifier = entityID;1911 currentEntityIdentifier = entityID;
1915 currentSandboxURL = sandboxURL;1912 currentSandboxURL = sandboxURL;
1916 1913
1917 ExceptionEmitter tryCatcher(this, !entityID.isNull() ? entityID.toString() : __FUNCTION__);
1918
1919#if DEBUG_CURRENT_ENTITY1914#if DEBUG_CURRENT_ENTITY
1920 QScriptValue oldData = this->globalObject().property("debugEntityID");1915 QScriptValue oldData = this->globalObject().property("debugEntityID");
1921 this->globalObject().setProperty("debugEntityID", entityID.toScriptValue(this)); // Make the entityID available to javascript as a global.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#else1919#else
1925 operation();1920 operation();
1926#endif1921#endif
1922 if (!isEvaluating() && hasUncaughtException()) {
1923 emit unhandledException(cloneUncaughtException(!entityID.isNull() ? entityID.toString() : __FUNCTION__));
1924 clearExceptions();
1925 }
1927 currentEntityIdentifier = oldIdentifier;1926 currentEntityIdentifier = oldIdentifier;
1928 currentSandboxURL = oldSandboxURL;1927 currentSandboxURL = oldSandboxURL;
1929}1928}