History

Add entity url back into entity script filenames

Ryan Huffman committed 10 years ago

Commit 8e3f4b71 parent e3be3331 file · +21 −2Browse 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+21−2
@@ -1096,7 +1096,7 @@ QUrl ScriptEngine::resolvePath(const QString& include) const { · 1095 unmodified lines
10961096
10971097 // we apparently weren't a fully qualified url, so, let's assume we're relative
10981098 // to the original URL of our script
1099− QUrl parentURL = contextInfo.fileName();
1099+ QUrl parentURL = extractUrlFromEntityUrl(contextInfo.fileName());
11001100 if (parentURL.isEmpty()) {
11011101 if (_parentURL.isEmpty()) {
11021102 parentURL = QUrl(_fileNameString);
@@ -1303,6 +1303,25 @@ void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const · 200 unmodified lines
13031303 }, forceRedownload);
13041304 }
13051305
1306+// The purpose of the following two function is to embed entity ids into entity script filenames
1307+// so that they show up in stacktraces
1308+//
1309+// Extract the url portion of a url that has been encoded with encodeEntityIdIntoEntityUrl(...)
1310+QString extractUrlFromEntityUrl(QString url) {
1311+ auto parts = url.split(' ', QString::SkipEmptyParts);
1312+ if (parts.length() > 0) {
1313+ return parts[0];
1314+ } else {
1315+ return "";
1316+ }
1317+}
1318+
1319+// Encode an entity id into an entity url
1320+// Example: http://www.example.com/some/path.js [EntityID:{9fdd355f-d226-4887-9484-44432d29520e}]
1321+QString encodeEntityIdIntoEntityUrl(QString url, QString entityID) {
1322+ return url + " [EntityID:" + entityID + "]";
1323+}
1324+
13061325 // since all of these operations can be asynch we will always do the actual work in the response handler
13071326 // for the download
13081327 void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {
@@ -1329,7 +1348,7 @@ void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, co · 20 unmodified lines
13291348
13301349 auto scriptCache = DependencyManager::get<ScriptCache>();
13311350 bool isFileUrl = isURL && scriptOrURL.startsWith("file://");
1332− auto fileName = isURL ? scriptOrURL : "EmbeddedEntityScript";
1351+ auto fileName = isURL ? encodeEntityIdIntoEntityUrl(scriptOrURL, entityID) : "EmbeddedEntityScript";
13331352
13341353 QScriptProgram program(contents, fileName);
13351354 if (!hasCorrectSyntax(program)) {