Showing the changes to libraries/script-engine/src/ScriptManager.cpp (1 of 9 files). Show all
Unified · Split
| @@ -225,7 +225,12 @@ QString encodeEntityIdIntoEntityUrl(const QString& url, const QString& entityID) · 224 unmodified lines | |||
| 225 | 225 | ||
| 226 | QString ScriptManager::logException(const ScriptValue& exception) { | 226 | QString ScriptManager::logException(const ScriptValue& exception) { |
| 227 | auto message = formatException(exception, _enableExtendedJSExceptions.get()); | 227 | auto message = formatException(exception, _enableExtendedJSExceptions.get()); |
| 228 | scriptErrorMessage(message); | 228 | auto context = _engine->currentContext(); |
| 229 | if (context) { | ||
| 230 | scriptErrorMessage(message, context->currentFileName(), context->currentLineNumber()); | ||
| 231 | } else { | ||
| 232 | scriptErrorMessage(message, "", -1); | ||
| 233 | } | ||
| 229 | return message; | 234 | return message; |
| 230 | } | 235 | } |
| 231 | 236 | ||
| @@ -330,6 +335,11 @@ ScriptManager::ScriptManager(Context context, const QString& scriptContents, con · 98 unmodified lines | |||
| 330 | }); | 335 | }); |
| 331 | } | 336 | } |
| 332 | 337 | ||
| 338 | //Gather entity script messages for transmission when running server side. | ||
| 339 | if (_type == Type::ENTITY_SERVER) { | ||
| 340 | ; | ||
| 341 | } | ||
| 342 | |||
| 333 | if (!_areMetaTypesInitialized) { | 343 | if (!_areMetaTypesInitialized) { |
| 334 | initMetaTypes(); | 344 | initMetaTypes(); |
| 335 | } | 345 | } |
| @@ -514,7 +524,7 @@ void ScriptManager::waitTillDoneRunning(bool shutdown) { · 178 unmodified lines | |||
| 514 | } | 524 | } |
| 515 | #endif | 525 | #endif |
| 516 | 526 | ||
| 517 | scriptInfoMessage("Script Engine has stopped:" + getFilename()); | 527 | scriptInfoMessage("Script Engine has stopped:" + getFilename(), "", -1); |
| 518 | } | 528 | } |
| 519 | } | 529 | } |
| 520 | 530 | ||
| @@ -549,7 +559,7 @@ void ScriptManager::loadURL(const QUrl& scriptURL, bool reload) { · 28 unmodified lines | |||
| 549 | 559 | ||
| 550 | // Check that script has a supported file extension | 560 | // Check that script has a supported file extension |
| 551 | if (!hasValidScriptSuffix(_fileNameString)) { | 561 | if (!hasValidScriptSuffix(_fileNameString)) { |
| 552 | scriptErrorMessage("File extension of file: " + _fileNameString + " is not a currently supported script type"); | 562 | scriptErrorMessage("File extension of file: " + _fileNameString + " is not a currently supported script type", _fileNameString, -1); |
| 553 | emit errorLoadingScript(_fileNameString); | 563 | emit errorLoadingScript(_fileNameString); |
| 554 | return; | 564 | return; |
| 555 | } | 565 | } |
| @@ -559,7 +569,7 @@ void ScriptManager::loadURL(const QUrl& scriptURL, bool reload) { · 3 unmodified lines | |||
| 559 | scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) { | 569 | scriptCache->getScriptContents(url.toString(), [this](const QString& url, const QString& scriptContents, bool isURL, bool success, const QString&status) { |
| 560 | qCDebug(scriptengine) << "loadURL" << url << status << QThread::currentThread(); | 570 | qCDebug(scriptengine) << "loadURL" << url << status << QThread::currentThread(); |
| 561 | if (!success) { | 571 | if (!success) { |
| 562 | scriptErrorMessage("ERROR Loading file (" + status + "):" + url); | 572 | scriptErrorMessage("ERROR Loading file (" + status + "):" + url, url, -1); |
| 563 | emit errorLoadingScript(_fileNameString); | 573 | emit errorLoadingScript(_fileNameString); |
| 564 | return; | 574 | return; |
| 565 | } | 575 | } |
| @@ -570,40 +580,35 @@ void ScriptManager::loadURL(const QUrl& scriptURL, bool reload) { · 4 unmodified lines | |||
| 570 | }, reload, maxRetries); | 580 | }, reload, maxRetries); |
| 571 | } | 581 | } |
| 572 | 582 | ||
| 573 | void ScriptManager::scriptErrorMessage(const QString& message) { | 583 | void ScriptManager::scriptErrorMessage(const QString& message, const QString& fileName, int lineNumber) { |
| 574 | qCCritical(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); | 584 | qCCritical(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); |
| 575 | emit errorMessage(message, getFilename()); | 585 | emit errorMessage(message, getFilename()); |
| 576 | if (!currentEntityIdentifier.isInvalidID()) { | 586 | if (!currentEntityIdentifier.isInvalidID()) { |
| 577 | // TODO: add line number and proper file name | 587 | emit errorEntityMessage(message, fileName, lineNumber, currentEntityIdentifier); |
| 578 | //if (engine() && engine()->currentContext() && engine()->currentContext()->) | ||
| 579 | emit errorEntityMessage(message, getFilename(), currentEntityIdentifier); | ||
| 580 | } | 588 | } |
| 581 | } | 589 | } |
| 582 | 590 | ||
| 583 | void ScriptManager::scriptWarningMessage(const QString& message) { | 591 | void ScriptManager::scriptWarningMessage(const QString& message, const QString& fileName, int lineNumber) { |
| 584 | qCWarning(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); | 592 | qCWarning(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); |
| 585 | emit warningMessage(message, getFilename()); | 593 | emit warningMessage(message, getFilename()); |
| 586 | if (!currentEntityIdentifier.isInvalidID()) { | 594 | if (!currentEntityIdentifier.isInvalidID()) { |
| 587 | // TODO: add line number and proper file name | 595 | emit warningEntityMessage(message, fileName, lineNumber, currentEntityIdentifier); |
| 588 | emit warningEntityMessage(message, getFilename(), currentEntityIdentifier); | ||
| 589 | } | 596 | } |
| 590 | } | 597 | } |
| 591 | 598 | ||
| 592 | void ScriptManager::scriptInfoMessage(const QString& message) { | 599 | void ScriptManager::scriptInfoMessage(const QString& message, const QString& fileName, int lineNumber) { |
| 593 | qCInfo(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); | 600 | qCInfo(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); |
| 594 | emit infoMessage(message, getFilename()); | 601 | emit infoMessage(message, getFilename()); |
| 595 | if (!currentEntityIdentifier.isInvalidID()) { | 602 | if (!currentEntityIdentifier.isInvalidID()) { |
| 596 | // TODO: add line number and proper file name | 603 | emit infoEntityMessage(message, fileName, lineNumber, currentEntityIdentifier); |
| 597 | emit infoEntityMessage(message, getFilename(), currentEntityIdentifier); | ||
| 598 | } | 604 | } |
| 599 | } | 605 | } |
| 600 | 606 | ||
| 601 | void ScriptManager::scriptPrintedMessage(const QString& message) { | 607 | void ScriptManager::scriptPrintedMessage(const QString& message, const QString& fileName, int lineNumber) { |
| 602 | qCDebug(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); | 608 | qCDebug(scriptengine, "[%s] %s", qUtf8Printable(getFilename()), qUtf8Printable(message)); |
| 603 | emit printedMessage(message, getFilename()); | 609 | emit printedMessage(message, getFilename()); |
| 604 | if (!currentEntityIdentifier.isInvalidID()) { | 610 | if (!currentEntityIdentifier.isInvalidID()) { |
| 605 | // TODO: add line number and proper file name | 611 | emit printedEntityMessage(message, fileName, lineNumber, currentEntityIdentifier); |
| 606 | emit printedEntityMessage(message, getFilename(), currentEntityIdentifier); | ||
| 607 | } | 612 | } |
| 608 | } | 613 | } |
| 609 | 614 | ||
| @@ -929,7 +934,7 @@ void ScriptManager::run() { · 319 unmodified lines | |||
| 929 | return; // bail early - avoid setting state in init(), as evaluate() will bail too | 934 | return; // bail early - avoid setting state in init(), as evaluate() will bail too |
| 930 | } | 935 | } |
| 931 | 936 | ||
| 932 | scriptInfoMessage("Script Engine starting:" + getFilename()); | 937 | scriptInfoMessage("Script Engine starting:" + getFilename(), getFilename(), -1); |
| 933 | 938 | ||
| 934 | if (!_isInitialized) { | 939 | if (!_isInitialized) { |
| 935 | init(); | 940 | init(); |
| @@ -1081,7 +1086,7 @@ void ScriptManager::run() { · 145 unmodified lines | |||
| 1081 | _engine->clearExceptions(); | 1086 | _engine->clearExceptions(); |
| 1082 | } | 1087 | } |
| 1083 | } | 1088 | } |
| 1084 | scriptInfoMessage("Script Engine stopping:" + getFilename()); | 1089 | scriptInfoMessage("Script Engine stopping:" + getFilename(), getFilename(), -1); |
| 1085 | 1090 | ||
| 1086 | stopAllTimers(); // make sure all our timers are stopped if the script is ending | 1091 | stopAllTimers(); // make sure all our timers are stopped if the script is ending |
| 1087 | emit scriptEnding(); | 1092 | emit scriptEnding(); |
| @@ -1156,7 +1161,7 @@ void ScriptManager::updateMemoryCost(const qint64& deltaSize) { · 68 unmodified lines | |||
| 1156 | 1161 | ||
| 1157 | void ScriptManager::timerFired() { | 1162 | void ScriptManager::timerFired() { |
| 1158 | if (isStopped()) { | 1163 | if (isStopped()) { |
| 1159 | scriptWarningMessage("Script.timerFired() while shutting down is ignored... parent script:" + getFilename()); | 1164 | scriptWarningMessage("Script.timerFired() while shutting down is ignored... parent script:" + getFilename(), getFilename(), -1); |
| 1160 | return; // bail early | 1165 | return; // bail early |
| 1161 | } | 1166 | } |
| 1162 | 1167 | ||
| @@ -1223,7 +1228,14 @@ QTimer* ScriptManager::setupTimerWithInterval(const ScriptValue& function, int i · 60 unmodified lines | |||
| 1223 | 1228 | ||
| 1224 | QTimer* ScriptManager::setInterval(const ScriptValue& function, int intervalMS) { | 1229 | QTimer* ScriptManager::setInterval(const ScriptValue& function, int intervalMS) { |
| 1225 | if (isStopped()) { | 1230 | if (isStopped()) { |
| 1226 | scriptWarningMessage("Script.setInterval() while shutting down is ignored... parent script:" + getFilename()); | 1231 | int lineNumber = -1; |
| 1232 | QString fileName = getFilename(); | ||
| 1233 | auto context = _engine->currentContext(); | ||
| 1234 | if (context) { | ||
| 1235 | lineNumber = context->currentLineNumber(); | ||
| 1236 | fileName = context->currentFileName(); | ||
| 1237 | } | ||
| 1238 | scriptWarningMessage("Script.setInterval() while shutting down is ignored... parent script:" + getFilename(), fileName, lineNumber); | ||
| 1227 | return NULL; // bail early | 1239 | return NULL; // bail early |
| 1228 | } | 1240 | } |
| 1229 | 1241 | ||
| @@ -1232,7 +1244,14 @@ QTimer* ScriptManager::setInterval(const ScriptValue& function, int intervalMS) · 2 unmodified lines | |||
| 1232 | 1244 | ||
| 1233 | QTimer* ScriptManager::setTimeout(const ScriptValue& function, int timeoutMS) { | 1245 | QTimer* ScriptManager::setTimeout(const ScriptValue& function, int timeoutMS) { |
| 1234 | if (isStopped()) { | 1246 | if (isStopped()) { |
| 1235 | scriptWarningMessage("Script.setTimeout() while shutting down is ignored... parent script:" + getFilename()); | 1247 | int lineNumber = -1; |
| 1248 | QString fileName = getFilename(); | ||
| 1249 | auto context = _engine->currentContext(); | ||
| 1250 | if (context) { | ||
| 1251 | lineNumber = context->currentLineNumber(); | ||
| 1252 | fileName = context->currentFileName(); | ||
| 1253 | } | ||
| 1254 | scriptWarningMessage("Script.setTimeout() while shutting down is ignored... parent script:" + getFilename(), fileName, lineNumber); | ||
| 1236 | return NULL; // bail early | 1255 | return NULL; // bail early |
| 1237 | } | 1256 | } |
| 1238 | 1257 | ||
| @@ -1668,8 +1687,15 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 429 unmodified lines | |||
| 1668 | return; | 1687 | return; |
| 1669 | } | 1688 | } |
| 1670 | if (isStopped()) { | 1689 | if (isStopped()) { |
| 1690 | int lineNumber = -1; | ||
| 1691 | QString fileName = getFilename(); | ||
| 1692 | auto context = _engine->currentContext(); | ||
| 1693 | if (context) { | ||
| 1694 | lineNumber = context->currentLineNumber(); | ||
| 1695 | fileName = context->currentFileName(); | ||
| 1696 | } | ||
| 1671 | scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:" | 1697 | scriptWarningMessage("Script.include() while shutting down is ignored... includeFiles:" |
| 1672 | + includeFiles.join(",") + "parent script:" + getFilename()); | 1698 | + includeFiles.join(",") + "parent script:" + getFilename(), fileName, lineNumber); |
| 1673 | return; // bail early | 1699 | return; // bail early |
| 1674 | } | 1700 | } |
| 1675 | QList<QUrl> urls; | 1701 | QList<QUrl> urls; |
| @@ -1682,8 +1708,15 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 6 unmodified lines | |||
| 1682 | thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file))); | 1708 | thisURL = expandScriptUrl(QUrl::fromLocalFile(expandScriptPath(file))); |
| 1683 | QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation(); | 1709 | QUrl defaultScriptsLoc = PathUtils::defaultScriptsLocation(); |
| 1684 | if (!defaultScriptsLoc.isParentOf(thisURL)) { | 1710 | if (!defaultScriptsLoc.isParentOf(thisURL)) { |
| 1711 | int lineNumber = -1; | ||
| 1712 | QString fileName = getFilename(); | ||
| 1713 | auto context = _engine->currentContext(); | ||
| 1714 | if (context) { | ||
| 1715 | lineNumber = context->currentLineNumber(); | ||
| 1716 | fileName = context->currentFileName(); | ||
| 1717 | } | ||
| 1685 | //V8TODO this probably needs to be done per context, otherwise file cannot be included again in a module | 1718 | //V8TODO this probably needs to be done per context, otherwise file cannot be included again in a module |
| 1686 | scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries"); | 1719 | scriptWarningMessage("Script.include() -- skipping" + file + "-- outside of standard libraries", fileName, lineNumber); |
| 1687 | continue; | 1720 | continue; |
| 1688 | } | 1721 | } |
| 1689 | isStandardLibrary = true; | 1722 | isStandardLibrary = true; |
| @@ -1693,8 +1726,15 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 3 unmodified lines | |||
| 1693 | 1726 | ||
| 1694 | bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile(); | 1727 | bool disallowOutsideFiles = thisURL.isLocalFile() && !isStandardLibrary && !currentSandboxURL.isLocalFile(); |
| 1695 | if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) { | 1728 | if (disallowOutsideFiles && !PathUtils::isDescendantOf(thisURL, currentSandboxURL)) { |
| 1729 | int lineNumber = -1; | ||
| 1730 | QString fileName = currentSandboxURL.toString(); | ||
| 1731 | auto context = _engine->currentContext(); | ||
| 1732 | if (context) { | ||
| 1733 | lineNumber = context->currentLineNumber(); | ||
| 1734 | fileName = context->currentFileName(); | ||
| 1735 | } | ||
| 1696 | scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString() | 1736 | scriptWarningMessage("Script.include() ignoring file path" + thisURL.toString() |
| 1697 | + "outside of original entity script" + currentSandboxURL.toString()); | 1737 | + "outside of original entity script" + currentSandboxURL.toString(), fileName, lineNumber); |
| 1698 | } else { | 1738 | } else { |
| 1699 | // We could also check here for CORS, but we don't yet. | 1739 | // We could also check here for CORS, but we don't yet. |
| 1700 | // It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here. | 1740 | // It turns out that QUrl.resolve will not change hosts and copy authority, so we don't need to check that here. |
| @@ -1716,7 +1756,14 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 15 unmodified lines | |||
| 1716 | for (QUrl url : urls) { | 1756 | for (QUrl url : urls) { |
| 1717 | QString contents = data[url]; | 1757 | QString contents = data[url]; |
| 1718 | if (contents.isNull()) { | 1758 | if (contents.isNull()) { |
| 1719 | scriptErrorMessage("Error loading file (" + status[url] +"): " + url.toString()); | 1759 | int lineNumber = -1; |
| 1760 | QString fileName = url.toString(); | ||
| 1761 | auto context = _engine->currentContext(); | ||
| 1762 | if (context) { | ||
| 1763 | lineNumber = context->currentLineNumber(); | ||
| 1764 | fileName = context->currentFileName(); | ||
| 1765 | } | ||
| 1766 | scriptErrorMessage("Error loading file (" + status[url] +"): " + url.toString(), fileName, lineNumber); | ||
| 1720 | } else { | 1767 | } else { |
| 1721 | std::lock_guard<std::recursive_mutex> lock(_lock); | 1768 | std::lock_guard<std::recursive_mutex> lock(_lock); |
| 1722 | if (!_includedURLs.contains(url)) { | 1769 | if (!_includedURLs.contains(url)) { |
| @@ -1736,7 +1783,14 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 13 unmodified lines | |||
| 1736 | _engine->clearExceptions(); | 1783 | _engine->clearExceptions(); |
| 1737 | } | 1784 | } |
| 1738 | } else { | 1785 | } else { |
| 1739 | scriptPrintedMessage("Script.include() skipping evaluation of previously included url:" + url.toString()); | 1786 | int lineNumber = -1; |
| 1787 | QString fileName = url.toString(); | ||
| 1788 | auto context = _engine->currentContext(); | ||
| 1789 | if (context) { | ||
| 1790 | lineNumber = context->currentLineNumber(); | ||
| 1791 | fileName = context->currentFileName(); | ||
| 1792 | } | ||
| 1793 | scriptPrintedMessage("Script.include() skipping evaluation of previously included url:" + url.toString(), fileName, lineNumber); | ||
| 1740 | } | 1794 | } |
| 1741 | } | 1795 | } |
| 1742 | } | 1796 | } |
| @@ -1765,8 +1819,15 @@ void ScriptManager::include(const QStringList& includeFiles, const ScriptValue& · 22 unmodified lines | |||
| 1765 | 1819 | ||
| 1766 | void ScriptManager::include(const QString& includeFile, const ScriptValue& callback) { | 1820 | void ScriptManager::include(const QString& includeFile, const ScriptValue& callback) { |
| 1767 | if (isStopped()) { | 1821 | if (isStopped()) { |
| 1822 | int lineNumber = -1; | ||
| 1823 | QString fileName = currentSandboxURL.toString(); | ||
| 1824 | auto context = _engine->currentContext(); | ||
| 1825 | if (context) { | ||
| 1826 | lineNumber = context->currentLineNumber(); | ||
| 1827 | fileName = context->currentFileName(); | ||
| 1828 | } | ||
| 1768 | scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:" | 1829 | scriptWarningMessage("Script.include() while shutting down is ignored... includeFile:" |
| 1769 | + includeFile + "parent script:" + getFilename()); | 1830 | + includeFile + "parent script:" + getFilename(), fileName, lineNumber); |
| 1770 | return; // bail early | 1831 | return; // bail early |
| 1771 | } | 1832 | } |
| 1772 | 1833 | ||
| @@ -1782,14 +1843,21 @@ void ScriptManager::load(const QString& loadFile) { · 9 unmodified lines | |||
| 1782 | if (!_engine->IS_THREADSAFE_INVOCATION(__FUNCTION__)) { | 1843 | if (!_engine->IS_THREADSAFE_INVOCATION(__FUNCTION__)) { |
| 1783 | return; | 1844 | return; |
| 1784 | } | 1845 | } |
| 1846 | int lineNumber = -1; | ||
| 1847 | QString fileName = getFilename(); | ||
| 1848 | auto context = _engine->currentContext(); | ||
| 1849 | if (context) { | ||
| 1850 | lineNumber = context->currentLineNumber(); | ||
| 1851 | fileName = context->currentFileName(); | ||
| 1852 | } | ||
| 1785 | if (isStopped()) { | 1853 | if (isStopped()) { |
| 1786 | scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:" | 1854 | scriptWarningMessage("Script.load() while shutting down is ignored... loadFile:" |
| 1787 | + loadFile + "parent script:" + getFilename()); | 1855 | + loadFile + "parent script:" + getFilename(), fileName, lineNumber); |
| 1788 | return; // bail early | 1856 | return; // bail early |
| 1789 | } | 1857 | } |
| 1790 | if (!currentEntityIdentifier.isInvalidID()) { | 1858 | if (!currentEntityIdentifier.isInvalidID()) { |
| 1791 | scriptWarningMessage("Script.load() from entity script is ignored... loadFile:" | 1859 | scriptWarningMessage("Script.load() from entity script is ignored... loadFile:" |
| 1792 | + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString()); | 1860 | + loadFile + "parent script:" + getFilename() + "entity: " + currentEntityIdentifier.toString(), fileName, lineNumber); |
| 1793 | return; // bail early | 1861 | return; // bail early |
| 1794 | } | 1862 | } |
| 1795 | 1863 | ||
| @@ -2457,7 +2525,7 @@ void ScriptManager::refreshFileScript(const EntityItemID& entityID) { · 661 unmodified lines | |||
| 2457 | QString filePath = QUrl(details.scriptText).toLocalFile(); | 2525 | QString filePath = QUrl(details.scriptText).toLocalFile(); |
| 2458 | auto lastModified = QFileInfo(filePath).lastModified().toMSecsSinceEpoch(); | 2526 | auto lastModified = QFileInfo(filePath).lastModified().toMSecsSinceEpoch(); |
| 2459 | if (lastModified > details.lastModified) { | 2527 | if (lastModified > details.lastModified) { |
| 2460 | scriptInfoMessage("Reloading modified script " + details.scriptText); | 2528 | scriptInfoMessage("Reloading modified script " + details.scriptText, filePath, -1); |
| 2461 | loadEntityScript(entityID, details.scriptText, true); | 2529 | loadEntityScript(entityID, details.scriptText, true); |
| 2462 | } | 2530 | } |
| 2463 | } | 2531 | } |