Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -183,6 +183,7 @@ QString ScriptEngine::reportUncaughtException(const QString& overrideFileName) { · 182 unmodified lines | |||
| 183 | return message; | 183 | return message; |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | int ScriptEngine::processLevelMaxRetries { ScriptRequest::MAX_RETRIES }; | ||
| 186 | ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const QString& fileNameString) : | 187 | ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const QString& fileNameString) : |
| 187 | _context(context), | 188 | _context(context), |
| 188 | _scriptContents(scriptContents), | 189 | _scriptContents(scriptContents), |
| @@ -198,6 +199,11 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const · 9 unmodified lines | |||
| 198 | }); | 199 | }); |
| 199 | 200 | ||
| 200 | setProcessEventsInterval(MSECS_PER_SECOND); | 201 | setProcessEventsInterval(MSECS_PER_SECOND); |
| 202 | if (isEntityServerScript()) { | ||
| 203 | qCDebug(scriptengine) << "isEntityServerScript() -- limiting maxRetries to 1"; | ||
| 204 | processLevelMaxRetries = 1; | ||
| 205 | } | ||
| 206 | qCDebug(scriptengine) << getContext() << "processLevelMaxRetries =" << processLevelMaxRetries; | ||
| 201 | } | 207 | } |
| 202 | 208 | ||
| 203 | QString ScriptEngine::getContext() const { | 209 | QString ScriptEngine::getContext() const { |
| @@ -1372,7 +1378,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 1168 unmodified lines | |||
| 1372 | // If we are destroyed before the loader completes, make sure to clean it up | 1378 | // If we are destroyed before the loader completes, make sure to clean it up |
| 1373 | connect(this, &QObject::destroyed, loader, &QObject::deleteLater); | 1379 | connect(this, &QObject::destroyed, loader, &QObject::deleteLater); |
| 1374 | 1380 | ||
| 1375 | loader->start(); | 1381 | loader->start(processLevelMaxRetries); |
| 1376 | 1382 | ||
| 1377 | if (!callback.isFunction() && !loader->isFinished()) { | 1383 | if (!callback.isFunction() && !loader->isFinished()) { |
| 1378 | QEventLoop loop; | 1384 | QEventLoop loop; |
| @@ -1452,6 +1458,7 @@ int ScriptEngine::getNumRunningEntityScripts() const { · 73 unmodified lines | |||
| 1452 | } | 1458 | } |
| 1453 | } | 1459 | } |
| 1454 | return sum; | 1460 | return sum; |
| 1461 | } | ||
| 1455 | 1462 | ||
| 1456 | QString ScriptEngine::getEntityScriptStatus(const EntityItemID& entityID) { | 1463 | QString ScriptEngine::getEntityScriptStatus(const EntityItemID& entityID) { |
| 1457 | if (_entityScripts.contains(entityID)) | 1464 | if (_entityScripts.contains(entityID)) |
| @@ -1468,17 +1475,30 @@ bool ScriptEngine::getEntityScriptDetails(const EntityItemID& entityID, EntitySc · 10 unmodified lines | |||
| 1468 | return true; | 1475 | return true; |
| 1469 | } | 1476 | } |
| 1470 | 1477 | ||
| 1478 | void ScriptEngine::setEntityScriptDetails(const EntityItemID& entityID, const EntityScriptDetails& details) { | ||
| 1479 | _entityScripts[entityID] = details; | ||
| 1480 | emit entityScriptDetailsUpdated(); | ||
| 1481 | } | ||
| 1482 | |||
| 1483 | void ScriptEngine::updateEntityScriptStatus(const EntityItemID& entityID, const EntityScriptStatus &status, const QString& errorInfo) { | ||
| 1484 | EntityScriptDetails &details = _entityScripts[entityID]; | ||
| 1485 | details.status = status; | ||
| 1486 | details.errorInfo = errorInfo; | ||
| 1487 | emit entityScriptDetailsUpdated(); | ||
| 1488 | } | ||
| 1489 | |||
| 1471 | // since all of these operations can be asynch we will always do the actual work in the response handler | 1490 | // since all of these operations can be asynch we will always do the actual work in the response handler |
| 1472 | // for the download | 1491 | // for the download |
| 1473 | void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) { | 1492 | void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const EntityItemID& entityID, const QString& entityScript, bool forceRedownload) { |
| 1493 | |||
| 1474 | { | 1494 | { |
| 1475 | // set EntityScriptDetails.status to LOADING (over on theEngine's thread) | 1495 | // set EntityScriptDetails.status to LOADING (over on theEngine's thread) |
| 1476 | QObject threadPunter; | 1496 | QObject threadPunter; |
| 1477 | connect(&threadPunter, &QObject::destroyed, theEngine.data(), [=]() { | 1497 | auto engine = theEngine.data(); |
| 1478 | EntityScriptDetails &details = theEngine.data()->_entityScripts[entityID]; | 1498 | connect(&threadPunter, &QObject::destroyed, engine, [=]() { |
| 1499 | EntityScriptDetails details = engine->_entityScripts[entityID]; | ||
| 1479 | if (details.status == EntityScriptStatus::PENDING || details.status == EntityScriptStatus::UNLOADED) { | 1500 | if (details.status == EntityScriptStatus::PENDING || details.status == EntityScriptStatus::UNLOADED) { |
| 1480 | details.status = EntityScriptStatus::LOADING; | 1501 | engine->updateEntityScriptStatus(entityID, EntityScriptStatus::LOADING, QThread::currentThread()->objectName()); |
| 1481 | emit entityScriptDetailsUpdated(); | ||
| 1482 | } | 1502 | } |
| 1483 | }); | 1503 | }); |
| 1484 | } | 1504 | } |
| @@ -1496,7 +1516,7 @@ void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const · 11 unmodified lines | |||
| 1496 | #endif | 1516 | #endif |
| 1497 | strongEngine->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status); | 1517 | strongEngine->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success, status); |
| 1498 | } | 1518 | } |
| 1499 | }, forceRedownload); | 1519 | }, forceRedownload, processLevelMaxRetries); |
| 1500 | } | 1520 | } |
| 1501 | 1521 | ||
| 1502 | // since all of these operations can be asynch we will always do the actual work in the response handler | 1522 | // since all of these operations can be asynch we will always do the actual work in the response handler |
| @@ -1534,8 +1554,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 31 unmodified lines | |||
| 1534 | if (!success) { | 1554 | if (!success) { |
| 1535 | newDetails.status = EntityScriptStatus::ERROR_LOADING_SCRIPT; | 1555 | newDetails.status = EntityScriptStatus::ERROR_LOADING_SCRIPT; |
| 1536 | newDetails.errorInfo = "Failed to load script (" + status + ")"; | 1556 | newDetails.errorInfo = "Failed to load script (" + status + ")"; |
| 1537 | _entityScripts[entityID] = newDetails; | 1557 | setEntityScriptDetails(entityID, newDetails); |
| 1538 | emit entityScriptDetailsUpdated(); | ||
| 1539 | return; | 1558 | return; |
| 1540 | } | 1559 | } |
| 1541 | 1560 | ||
| @@ -1544,8 +1563,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 2 unmodified lines | |||
| 1544 | if (!syntaxError.isNull() || program.isNull()) { | 1563 | if (!syntaxError.isNull() || program.isNull()) { |
| 1545 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; | 1564 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; |
| 1546 | newDetails.errorInfo = QString("Bad syntax (%1)").arg(syntaxError); | 1565 | newDetails.errorInfo = QString("Bad syntax (%1)").arg(syntaxError); |
| 1547 | _entityScripts[entityID] = newDetails; | 1566 | setEntityScriptDetails(entityID, newDetails); |
| 1548 | emit entityScriptDetailsUpdated(); | ||
| 1549 | qCDebug(scriptengine) << newDetails.errorInfo << scriptOrURL; | 1567 | qCDebug(scriptengine) << newDetails.errorInfo << scriptOrURL; |
| 1550 | return; // done processing script | 1568 | return; // done processing script |
| 1551 | } | 1569 | } |
| @@ -1578,8 +1596,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 26 unmodified lines | |||
| 1578 | if (!exceptionMessage.isNull()) { | 1596 | if (!exceptionMessage.isNull()) { |
| 1579 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; | 1597 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; |
| 1580 | newDetails.errorInfo = exceptionMessage; | 1598 | newDetails.errorInfo = exceptionMessage; |
| 1581 | _entityScripts[entityID] = newDetails; | 1599 | setEntityScriptDetails(entityID, newDetails); |
| 1582 | emit entityScriptDetailsUpdated(); | ||
| 1583 | qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- hadUncaughtExceptions (" << scriptOrURL << ")"; | 1600 | qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- hadUncaughtExceptions (" << scriptOrURL << ")"; |
| 1584 | return; | 1601 | return; |
| 1585 | } | 1602 | } |
| @@ -1601,8 +1618,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 15 unmodified lines | |||
| 1601 | 1618 | ||
| 1602 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; | 1619 | newDetails.status = EntityScriptStatus::ERROR_RUNNING_SCRIPT; |
| 1603 | newDetails.errorInfo = "Could not find constructor"; | 1620 | newDetails.errorInfo = "Could not find constructor"; |
| 1604 | _entityScripts[entityID] = newDetails; | 1621 | setEntityScriptDetails(entityID, newDetails); |
| 1605 | emit entityScriptDetailsUpdated(); | ||
| 1606 | 1622 | ||
| 1607 | qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- failed to run (" << scriptOrURL << ")"; | 1623 | qCDebug(scriptengine) << "----- ScriptEngine::entityScriptContentAvailable -- failed to run (" << scriptOrURL << ")"; |
| 1608 | return; // done processing script | 1624 | return; // done processing script |
| @@ -1625,8 +1641,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 16 unmodified lines | |||
| 1625 | newDetails.scriptObject = entityScriptObject; | 1641 | newDetails.scriptObject = entityScriptObject; |
| 1626 | newDetails.lastModified = lastModified; | 1642 | newDetails.lastModified = lastModified; |
| 1627 | newDetails.definingSandboxURL = sandboxURL; | 1643 | newDetails.definingSandboxURL = sandboxURL; |
| 1628 | _entityScripts[entityID] = newDetails; | 1644 | setEntityScriptDetails(entityID, newDetails); |
| 1629 | emit entityScriptDetailsUpdated(); | ||
| 1630 | 1645 | ||
| 1631 | if (isURL) { | 1646 | if (isURL) { |
| 1632 | setParentURL(""); | 1647 | setParentURL(""); |
| @@ -1656,11 +1671,10 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 23 unmodified lines | |||
| 1656 | if (isEntityScriptRunning(entityID)) { | 1671 | if (isEntityScriptRunning(entityID)) { |
| 1657 | callEntityScriptMethod(entityID, "unload"); | 1672 | callEntityScriptMethod(entityID, "unload"); |
| 1658 | } | 1673 | } |
| 1659 | EntityScriptDetails details; | 1674 | EntityScriptDetails newDetails; |
| 1660 | details.status = EntityScriptStatus::UNLOADED; | 1675 | newDetails.status = EntityScriptStatus::UNLOADED; |
| 1661 | _entityScripts[entityID] = details; | 1676 | setEntityScriptDetails(entityID, newDetails); |
| 1662 | stopAllTimersForEntityScript(entityID); | 1677 | stopAllTimersForEntityScript(entityID); |
| 1663 | emit entityScriptDetailsUpdated(); | ||
| 1664 | } | 1678 | } |
| 1665 | } | 1679 | } |
| 1666 | 1680 | ||