History

* use explicit int's for moduleId constants * maxTestConstructorValueSize was already limiting debug output size -- adopt its strategy, use shared MAX_DEBUG_VALUE_LENGTH const

humbletim committed 9 years ago

Commit efc61c21 parent 9d860a81 file · +19 −16Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 1 file). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+19−16
@@ -74,13 +74,14 @@ const QString ScriptEngine::_SETTINGS_ENABLE_EXTENDED_MODULE_COMPAT { · 73 unmodified lines
7474 "com.highfidelity.experimental.enableExtendedModuleCompatbility"
7575 };
7676
77+static const int MAX_MODULE_ID_LENTGH { 4096 };
78+static const int MAX_DEBUG_VALUE_LENGTH { 80 };
79+
7780 static const QScriptEngine::QObjectWrapOptions DEFAULT_QOBJECT_WRAP_OPTIONS =
7881 QScriptEngine::ExcludeDeleteLater | QScriptEngine::ExcludeChildObjects;
7982 static const QScriptValue::PropertyFlags READONLY_PROP_FLAGS { QScriptValue::ReadOnly | QScriptValue::Undeletable };
8083 static const QScriptValue::PropertyFlags READONLY_HIDDEN_PROP_FLAGS { READONLY_PROP_FLAGS | QScriptValue::SkipInEnumeration };
8184
82−
83−
8485 static const bool HIFI_AUTOREFRESH_FILE_SCRIPTS { true };
8586
8687 Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature)
@@ -551,8 +552,9 @@ void ScriptEngine::resetModuleCache(bool deleteScriptCache) { · 464 unmodified lines
551552 QScriptValueIterator it(cache);
552553 while (it.hasNext()) {
553554 it.next();
554− if (it.flags() & QScriptValue::SkipInEnumeration)
555+ if (it.flags() & QScriptValue::SkipInEnumeration) {
555556 continue;
557+ }
556558 //scriptCache->deleteScript(it.name());
557559 qCDebug(scriptengine) << "resetModuleCache(true) -- staging " << it.name() << " for cache reset at next require";
558560 cacheMeta.setProperty(it.name(), true);
@@ -1355,29 +1357,31 @@ void ScriptEngine::print(const QString& message) { · 796 unmodified lines
13551357 emit printedMessage(message);
13561358 }
13571359
1358−static const auto MAX_MODULE_IDENTIFIER_LEN { 4096 };
1359−static const auto MAX_MODULE_IDENTIFIER_LOG_LEN { 60 };
1360−
13611360 // Script.require.resolve -- like resolvePath, but performs more validation and throws exceptions on invalid module identifiers (for consistency with Node.js)
13621361 QString ScriptEngine::_requireResolve(const QString& moduleId, const QString& relativeTo) {
13631362 QUrl defaultScriptsLoc = defaultScriptsLocation();
13641363 QUrl url(moduleId);
13651364
13661365 // 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(
13691372 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));
13721375 return QString();
13731376 };
13741377
13751378 // de-fuzz the input a little by restricting to rational sizes
13761379 auto idLength = url.toString().length();
1377− if (idLength < 1 || idLength > MAX_MODULE_IDENTIFIER_LEN) {
1380+ if (idLength < 1 || idLength > MAX_MODULE_ID_LENTGH) {
13781381 return resolverException(
13791382 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"
13811385 );
13821386 }
13831387
@@ -1598,7 +1602,7 @@ QScriptValue ScriptEngine::instantiateModule(const QScriptValue& module, const Q · 214 unmodified lines
15981602
15991603 // CommonJS/Node.js like require/module support
16001604 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) << ")";
16021606 if (QThread::currentThread() != thread()) {
16031607 qCDebug(scriptengine_module) << moduleId << " threads mismatch";
16041608 return nullValue();
@@ -2245,9 +2249,8 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 640 unmodified lines
22452249 testConstructorType = "empty";
22462250 }
22472251 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) + "...";
22512254 }
22522255 auto message = QString("failed to load entity script -- expected a function, got %1, %2")
22532256 .arg(testConstructorType).arg(testConstructorValue);