Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all
Unified · Split
| @@ -74,13 +74,14 @@ const QString ScriptEngine::_SETTINGS_ENABLE_EXTENDED_MODULE_COMPAT { · 73 unmodified lines | ||
| 74 | 74 | "com.highfidelity.experimental.enableExtendedModuleCompatbility" |
| 75 | 75 | }; |
| 76 | 76 | |
| 77 | +static const int MAX_MODULE_ID_LENTGH { 4096 }; | |
| 78 | +static const int MAX_DEBUG_VALUE_LENGTH { 80 }; | |
| 79 | + | |
| 77 | 80 | static const QScriptEngine::QObjectWrapOptions DEFAULT_QOBJECT_WRAP_OPTIONS = |
| 78 | 81 | QScriptEngine::ExcludeDeleteLater | QScriptEngine::ExcludeChildObjects; |
| 79 | 82 | static const QScriptValue::PropertyFlags READONLY_PROP_FLAGS { QScriptValue::ReadOnly | QScriptValue::Undeletable }; |
| 80 | 83 | static const QScriptValue::PropertyFlags READONLY_HIDDEN_PROP_FLAGS { READONLY_PROP_FLAGS | QScriptValue::SkipInEnumeration }; |
| 81 | 84 | |
| 82 | − | |
| 83 | − | |
| 84 | 85 | static const bool HIFI_AUTOREFRESH_FILE_SCRIPTS { true }; |
| 85 | 86 | |
| 86 | 87 | Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature) |
| @@ -551,8 +552,9 @@ void ScriptEngine::resetModuleCache(bool deleteScriptCache) { · 464 unmodified lines | ||
| 551 | 552 | QScriptValueIterator it(cache); |
| 552 | 553 | while (it.hasNext()) { |
| 553 | 554 | it.next(); |
| 554 | − if (it.flags() & QScriptValue::SkipInEnumeration) | |
| 555 | + if (it.flags() & QScriptValue::SkipInEnumeration) { | |
| 555 | 556 | continue; |
| 557 | + } | |
| 556 | 558 | //scriptCache->deleteScript(it.name()); |
| 557 | 559 | qCDebug(scriptengine) << "resetModuleCache(true) -- staging " << it.name() << " for cache reset at next require"; |
| 558 | 560 | cacheMeta.setProperty(it.name(), true); |
| @@ -1355,29 +1357,31 @@ void ScriptEngine::print(const QString& message) { · 796 unmodified lines | ||
| 1355 | 1357 | emit printedMessage(message); |
| 1356 | 1358 | } |
| 1357 | 1359 | |
| 1358 | −static const auto MAX_MODULE_IDENTIFIER_LEN { 4096 }; | |
| 1359 | −static const auto MAX_MODULE_IDENTIFIER_LOG_LEN { 60 }; | |
| 1360 | − | |
| 1361 | 1360 | // Script.require.resolve -- like resolvePath, but performs more validation and throws exceptions on invalid module identifiers (for consistency with Node.js) |
| 1362 | 1361 | QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& relativeTo) { |
| 1363 | 1362 | QUrl defaultScriptsLoc = defaultScriptsLocation(); |
| 1364 | 1363 | QUrl url(moduleId); |
| 1365 | 1364 | |
| 1366 | 1365 | // helper to generate an exception and return a null string |
| 1367 | − auto resolverException = [=](const QString& detail) -> QString { | |
| 1368 | − currentContext()->throwError( | |
| 1366 | + auto resolverException = [=](const QString& detail, const QString& type = "Error") -> QString { | |
| 1367 | + auto displayId = moduleId; | |
| 1368 | + if (displayId.length() > MAX_DEBUG_VALUE_LENGTH) { | |
| 1369 | + displayId = displayId.mid(0, MAX_DEBUG_VALUE_LENGTH) + "..."; | |
| 1370 | + } | |
| 1371 | + currentContext()->throwValue(makeError( | |
| 1369 | 1372 | QString("Cannot find module '%1' (%2)") |
| 1370 | − .arg(moduleId.left(MAX_MODULE_IDENTIFIER_LOG_LEN)) | |
| 1371 | − .arg(detail)); | |
| 1373 | + .arg(displayId) | |
| 1374 | + .arg(detail), type)); | |
| 1372 | 1375 | return QString(); |
| 1373 | 1376 | }; |
| 1374 | 1377 | |
| 1375 | 1378 | // de-fuzz the input a little by restricting to rational sizes |
| 1376 | 1379 | auto idLength = url.toString().length(); |
| 1377 | − if (idLength < 1 || idLength > MAX_MODULE_IDENTIFIER_LEN) { | |
| 1380 | + if (idLength < 1 || idLength > MAX_MODULE_ID_LENTGH) { | |
| 1378 | 1381 | return resolverException( |
| 1379 | 1382 | QString("rejecting invalid module id size (%1 chars [1,%2])") |
| 1380 | − .arg(idLength).arg(MAX_MODULE_IDENTIFIER_LEN) | |
| 1383 | + .arg(idLength).arg(MAX_MODULE_ID_LENTGH), | |
| 1384 | + "RangeError" | |
| 1381 | 1385 | ); |
| 1382 | 1386 | } |
| 1383 | 1387 | |
| @@ -1598,7 +1602,7 @@ QScriptValue ScriptEngine::instantiateModule(const QScriptValue& module, const Q · 214 unmodified lines | ||
| 1598 | 1602 | |
| 1599 | 1603 | // CommonJS/Node.js like require/module support |
| 1600 | 1604 | QScriptValue ScriptEngine::require(const QString& moduleId) { |
| 1601 | − qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_MODULE_IDENTIFIER_LOG_LEN) << ")"; | |
| 1605 | + qCDebug(scriptengine_module) << "ScriptEngine::require(" << moduleId.left(MAX_DEBUG_VALUE_LENGTH) << ")"; | |
| 1602 | 1606 | if (QThread::currentThread() != thread()) { |
| 1603 | 1607 | qCDebug(scriptengine_module) << moduleId << " threads mismatch"; |
| 1604 | 1608 | return nullValue(); |
| @@ -2245,9 +2249,8 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 640 unmodified lines | ||
| 2245 | 2249 | testConstructorType = "empty"; |
| 2246 | 2250 | } |
| 2247 | 2251 | QString testConstructorValue = testConstructor.toString(); |
| 2248 | − const int maxTestConstructorValueSize = 80; | |
| 2249 | − if (testConstructorValue.size() > maxTestConstructorValueSize) { | |
| 2250 | − testConstructorValue = testConstructorValue.mid(0, maxTestConstructorValueSize) + "..."; | |
| 2252 | + if (testConstructorValue.size() > MAX_DEBUG_VALUE_LENGTH) { | |
| 2253 | + testConstructorValue = testConstructorValue.mid(0, MAX_DEBUG_VALUE_LENGTH) + "..."; | |
| 2251 | 2254 | } |
| 2252 | 2255 | auto message = QString("failed to load entity script -- expected a function, got %1, %2") |
| 2253 | 2256 | .arg(testConstructorType).arg(testConstructorValue); |