Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all
Unified · Split
| @@ -65,9 +65,9 @@ static QScriptValue debugPrint(QScriptContext* context, QScriptEngine* engine){ · 64 unmodified lines | |||
| 65 | qCDebug(scriptengine).noquote() << "script:print()<<" << message; // noquote() so that \n is treated as newline | 65 | qCDebug(scriptengine).noquote() << "script:print()<<" << message; // noquote() so that \n is treated as newline |
| 66 | 66 | ||
| 67 | message = message.replace("\\", "\\\\") | 67 | message = message.replace("\\", "\\\\") |
| 68 | .replace("\n", "\\n") | 68 | .replace("\n", "\\n") |
| 69 | .replace("\r", "\\r") | 69 | .replace("\r", "\\r") |
| 70 | .replace("'", "\\'"); | 70 | .replace("'", "\\'"); |
| 71 | engine->evaluate("Script.print('" + message + "')"); | 71 | engine->evaluate("Script.print('" + message + "')"); |
| 72 | 72 | ||
| 73 | return QScriptValue(); | 73 | return QScriptValue(); |
| @@ -123,11 +123,11 @@ static bool hadUncaughtExceptions(QScriptEngine& engine, const QString& fileName · 49 unmodified lines | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, bool wantSignals) : | 125 | ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNameString, bool wantSignals) : |
| 126 | _scriptContents(scriptContents), | 126 | _scriptContents(scriptContents), |
| 127 | _timerFunctionMap(), | 127 | _timerFunctionMap(), |
| 128 | _wantSignals(wantSignals), | 128 | _wantSignals(wantSignals), |
| 129 | _fileNameString(fileNameString), | 129 | _fileNameString(fileNameString), |
| 130 | _arrayBufferClass(new ArrayBufferClass(this)) | 130 | _arrayBufferClass(new ArrayBufferClass(this)) |
| 131 | { | 131 | { |
| 132 | _allScriptsMutex.lock(); | 132 | _allScriptsMutex.lock(); |
| 133 | _allKnownScriptEngines.insert(this); | 133 | _allKnownScriptEngines.insert(this); |
| @@ -495,7 +495,7 @@ void ScriptEngine::registerGetterSetter(const QString& name, QScriptEngine::Func · 361 unmodified lines | |||
| 495 | if (QThread::currentThread() != thread()) { | 495 | if (QThread::currentThread() != thread()) { |
| 496 | #ifdef THREAD_DEBUGGING | 496 | #ifdef THREAD_DEBUGGING |
| 497 | qDebug() << "*** WARNING *** ScriptEngine::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 497 | qDebug() << "*** WARNING *** ScriptEngine::registerGetterSetter() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 498 | " name:" << name << "parent:" << parent; | 498 | " name:" << name << "parent:" << parent; |
| 499 | #endif | 499 | #endif |
| 500 | QMetaObject::invokeMethod(this, "registerGetterSetter", | 500 | QMetaObject::invokeMethod(this, "registerGetterSetter", |
| 501 | Q_ARG(const QString&, name), | 501 | Q_ARG(const QString&, name), |
| @@ -528,7 +528,7 @@ void ScriptEngine::removeEventHandler(const EntityItemID& entityID, const QStrin · 26 unmodified lines | |||
| 528 | if (QThread::currentThread() != thread()) { | 528 | if (QThread::currentThread() != thread()) { |
| 529 | #ifdef THREAD_DEBUGGING | 529 | #ifdef THREAD_DEBUGGING |
| 530 | qDebug() << "*** WARNING *** ScriptEngine::removeEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 530 | qDebug() << "*** WARNING *** ScriptEngine::removeEventHandler() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 531 | "entityID:" << entityID << " eventName:" << eventName; | 531 | "entityID:" << entityID << " eventName:" << eventName; |
| 532 | #endif | 532 | #endif |
| 533 | QMetaObject::invokeMethod(this, "removeEventHandler", | 533 | QMetaObject::invokeMethod(this, "removeEventHandler", |
| 534 | Q_ARG(const EntityItemID&, entityID), | 534 | Q_ARG(const EntityItemID&, entityID), |
| @@ -955,7 +955,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac · 420 unmodified lines | |||
| 955 | void ScriptEngine::include(const QString& includeFile, QScriptValue callback) { | 955 | void ScriptEngine::include(const QString& includeFile, QScriptValue callback) { |
| 956 | if (_stoppingAllScripts) { | 956 | if (_stoppingAllScripts) { |
| 957 | qCDebug(scriptengine) << "Script.include() while shutting down is ignored... " | 957 | qCDebug(scriptengine) << "Script.include() while shutting down is ignored... " |
| 958 | << "includeFile:" << includeFile << "parent script:" << getFilename(); | 958 | << "includeFile:" << includeFile << "parent script:" << getFilename(); |
| 959 | return; // bail early | 959 | return; // bail early |
| 960 | } | 960 | } |
| 961 | 961 | ||
| @@ -970,7 +970,7 @@ void ScriptEngine::include(const QString& includeFile, QScriptValue callback) { · 8 unmodified lines | |||
| 970 | void ScriptEngine::load(const QString& loadFile) { | 970 | void ScriptEngine::load(const QString& loadFile) { |
| 971 | if (_stoppingAllScripts) { | 971 | if (_stoppingAllScripts) { |
| 972 | qCDebug(scriptengine) << "Script.load() while shutting down is ignored... " | 972 | qCDebug(scriptengine) << "Script.load() while shutting down is ignored... " |
| 973 | << "loadFile:" << loadFile << "parent script:" << getFilename(); | 973 | << "loadFile:" << loadFile << "parent script:" << getFilename(); |
| 974 | return; // bail early | 974 | return; // bail early |
| 975 | } | 975 | } |
| 976 | 976 | ||
| @@ -1016,7 +1016,7 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 39 unmodified lines | |||
| 1016 | if (QThread::currentThread() != thread()) { | 1016 | if (QThread::currentThread() != thread()) { |
| 1017 | #ifdef THREAD_DEBUGGING | 1017 | #ifdef THREAD_DEBUGGING |
| 1018 | qDebug() << "*** WARNING *** ScriptEngine::loadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1018 | qDebug() << "*** WARNING *** ScriptEngine::loadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1019 | "entityID:" << entityID << "entityScript:" << entityScript <<"forceRedownload:" << forceRedownload; | 1019 | "entityID:" << entityID << "entityScript:" << entityScript <<"forceRedownload:" << forceRedownload; |
| 1020 | #endif | 1020 | #endif |
| 1021 | 1021 | ||
| 1022 | QMetaObject::invokeMethod(this, "loadEntityScript", | 1022 | QMetaObject::invokeMethod(this, "loadEntityScript", |
| @@ -1027,18 +1027,20 @@ void ScriptEngine::loadEntityScript(const EntityItemID& entityID, const QString& · 4 unmodified lines | |||
| 1027 | } | 1027 | } |
| 1028 | #ifdef THREAD_DEBUGGING | 1028 | #ifdef THREAD_DEBUGGING |
| 1029 | qDebug() << "ScriptEngine::loadEntityScript() called on correct thread [" << thread() << "] " | 1029 | qDebug() << "ScriptEngine::loadEntityScript() called on correct thread [" << thread() << "] " |
| 1030 | "entityID:" << entityID << "entityScript:" << entityScript << "forceRedownload:" << forceRedownload; | 1030 | "entityID:" << entityID << "entityScript:" << entityScript << "forceRedownload:" << forceRedownload; |
| 1031 | #endif | 1031 | #endif |
| 1032 | 1032 | ||
| 1033 | // If we've been called our known entityScripts should not know about us.. | 1033 | // If we've been called our known entityScripts should not know about us.. |
| 1034 | assert(!_entityScripts.contains(entityID)); | 1034 | assert(!_entityScripts.contains(entityID)); |
| 1035 | 1035 | ||
| 1036 | #ifdef THREAD_DEBUGGING | 1036 | #ifdef THREAD_DEBUGGING |
| 1037 | qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; | 1037 | qDebug() << "ScriptEngine::loadEntityScript() calling scriptCache->getScriptContents() on thread [" |
| 1038 | << QThread::currentThread() << "] expected thread [" << thread() << "]"; | ||
| 1038 | #endif | 1039 | #endif |
| 1039 | DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { | 1040 | DependencyManager::get<ScriptCache>()->getScriptContents(entityScript, [=](const QString& scriptOrURL, const QString& contents, bool isURL, bool success) { |
| 1040 | #ifdef THREAD_DEBUGGING | 1041 | #ifdef THREAD_DEBUGGING |
| 1041 | qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]"; | 1042 | qDebug() << "ScriptEngine::entityScriptContentAvailable() IN LAMBDA contentAvailable on thread [" |
| 1043 | << QThread::currentThread() << "] expected thread [" << thread() << "]"; | ||
| 1042 | #endif | 1044 | #endif |
| 1043 | 1045 | ||
| 1044 | this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success); | 1046 | this->entityScriptContentAvailable(entityID, scriptOrURL, contents, isURL, success); |
| @@ -1091,11 +1093,13 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 46 unmodified lines | |||
| 1091 | 1093 | ||
| 1092 | if (!testConstructor.isFunction()) { | 1094 | if (!testConstructor.isFunction()) { |
| 1093 | qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n" | 1095 | qCDebug(scriptengine) << "ScriptEngine::loadEntityScript() entity:" << entityID << "\n" |
| 1094 | " NOT CONSTRUCTOR\n" | 1096 | " NOT CONSTRUCTOR\n" |
| 1095 | " SCRIPT:" << scriptOrURL; | 1097 | " SCRIPT:" << scriptOrURL; |
| 1098 | |||
| 1096 | if (!isFileUrl) { | 1099 | if (!isFileUrl) { |
| 1097 | scriptCache->addScriptToBadScriptList(scriptOrURL); | 1100 | scriptCache->addScriptToBadScriptList(scriptOrURL); |
| 1098 | } | 1101 | } |
| 1102 | |||
| 1099 | return; // done processing script | 1103 | return; // done processing script |
| 1100 | } | 1104 | } |
| 1101 | 1105 | ||
| @@ -1121,7 +1125,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 19 unmodified lines | |||
| 1121 | if (QThread::currentThread() != thread()) { | 1125 | if (QThread::currentThread() != thread()) { |
| 1122 | #ifdef THREAD_DEBUGGING | 1126 | #ifdef THREAD_DEBUGGING |
| 1123 | qDebug() << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1127 | qDebug() << "*** WARNING *** ScriptEngine::unloadEntityScript() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1124 | "entityID:" << entityID; | 1128 | "entityID:" << entityID; |
| 1125 | #endif | 1129 | #endif |
| 1126 | 1130 | ||
| 1127 | QMetaObject::invokeMethod(this, "unloadEntityScript", | 1131 | QMetaObject::invokeMethod(this, "unloadEntityScript", |
| @@ -1130,7 +1134,7 @@ void ScriptEngine::unloadEntityScript(const EntityItemID& entityID) { · 2 unmodified lines | |||
| 1130 | } | 1134 | } |
| 1131 | #ifdef THREAD_DEBUGGING | 1135 | #ifdef THREAD_DEBUGGING |
| 1132 | qDebug() << "ScriptEngine::unloadEntityScript() called on correct thread [" << thread() << "] " | 1136 | qDebug() << "ScriptEngine::unloadEntityScript() called on correct thread [" << thread() << "] " |
| 1133 | "entityID:" << entityID; | 1137 | "entityID:" << entityID; |
| 1134 | #endif | 1138 | #endif |
| 1135 | 1139 | ||
| 1136 | if (_entityScripts.contains(entityID)) { | 1140 | if (_entityScripts.contains(entityID)) { |
| @@ -1195,7 +1199,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 58 unmodified lines | |||
| 1195 | if (QThread::currentThread() != thread()) { | 1199 | if (QThread::currentThread() != thread()) { |
| 1196 | #ifdef THREAD_DEBUGGING | 1200 | #ifdef THREAD_DEBUGGING |
| 1197 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1201 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1198 | "entityID:" << entityID << "methodName:" << methodName; | 1202 | "entityID:" << entityID << "methodName:" << methodName; |
| 1199 | #endif | 1203 | #endif |
| 1200 | 1204 | ||
| 1201 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", | 1205 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| @@ -1206,7 +1210,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 4 unmodified lines | |||
| 1206 | } | 1210 | } |
| 1207 | #ifdef THREAD_DEBUGGING | 1211 | #ifdef THREAD_DEBUGGING |
| 1208 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " | 1212 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 1209 | "entityID:" << entityID << "methodName:" << methodName; | 1213 | "entityID:" << entityID << "methodName:" << methodName; |
| 1210 | #endif | 1214 | #endif |
| 1211 | 1215 | ||
| 1212 | refreshFileScript(entityID); | 1216 | refreshFileScript(entityID); |
| @@ -1227,7 +1231,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 14 unmodified lines | |||
| 1227 | if (QThread::currentThread() != thread()) { | 1231 | if (QThread::currentThread() != thread()) { |
| 1228 | #ifdef THREAD_DEBUGGING | 1232 | #ifdef THREAD_DEBUGGING |
| 1229 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1233 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1230 | "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; | 1234 | "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; |
| 1231 | #endif | 1235 | #endif |
| 1232 | 1236 | ||
| 1233 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", | 1237 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| @@ -1238,7 +1242,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 4 unmodified lines | |||
| 1238 | } | 1242 | } |
| 1239 | #ifdef THREAD_DEBUGGING | 1243 | #ifdef THREAD_DEBUGGING |
| 1240 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " | 1244 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 1241 | "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; | 1245 | "entityID:" << entityID << "methodName:" << methodName << "event: mouseEvent"; |
| 1242 | #endif | 1246 | #endif |
| 1243 | 1247 | ||
| 1244 | refreshFileScript(entityID); | 1248 | refreshFileScript(entityID); |
| @@ -1259,7 +1263,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 14 unmodified lines | |||
| 1259 | if (QThread::currentThread() != thread()) { | 1263 | if (QThread::currentThread() != thread()) { |
| 1260 | #ifdef THREAD_DEBUGGING | 1264 | #ifdef THREAD_DEBUGGING |
| 1261 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " | 1265 | qDebug() << "*** WARNING *** ScriptEngine::callEntityScriptMethod() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "] " |
| 1262 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; | 1266 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; |
| 1263 | #endif | 1267 | #endif |
| 1264 | 1268 | ||
| 1265 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", | 1269 | QMetaObject::invokeMethod(this, "callEntityScriptMethod", |
| @@ -1271,7 +1275,7 @@ void ScriptEngine::callEntityScriptMethod(const EntityItemID& entityID, const QS · 5 unmodified lines | |||
| 1271 | } | 1275 | } |
| 1272 | #ifdef THREAD_DEBUGGING | 1276 | #ifdef THREAD_DEBUGGING |
| 1273 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " | 1277 | qDebug() << "ScriptEngine::callEntityScriptMethod() called on correct thread [" << thread() << "] " |
| 1274 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; | 1278 | "entityID:" << entityID << "methodName:" << methodName << "otherID:" << otherID << "collision: collision"; |
| 1275 | #endif | 1279 | #endif |
| 1276 | 1280 | ||
| 1277 | refreshFileScript(entityID); | 1281 | refreshFileScript(entityID); |