History

Move extract/encode enitty functions in ScriptEngine

Ryan Huffman committed 10 years ago

Commit 42b0d821 parent df092541 file · +19 −19Browse 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−19
@@ -107,6 +107,25 @@ void inputControllerFromScriptValue(const QScriptValue &object, controller::Inpu · 106 unmodified lines
107 out = qobject_cast<controller::InputController*>(object.toQObject());107 out = qobject_cast<controller::InputController*>(object.toQObject());
108}108}
109 109
110// The purpose of the following two function is to embed entity ids into entity script filenames
111// so that they show up in stacktraces
112//
113// Extract the url portion of a url that has been encoded with encodeEntityIdIntoEntityUrl(...)
114QString extractUrlFromEntityUrl(const QString& url) {
115 auto parts = url.split(' ', QString::SkipEmptyParts);
116 if (parts.length() > 0) {
117 return parts[0];
118 } else {
119 return "";
120 }
121}
122
123// Encode an entity id into an entity url
124// Example: http://www.example.com/some/path.js [EntityID:{9fdd355f-d226-4887-9484-44432d29520e}]
125QString encodeEntityIdIntoEntityUrl(const QString& url, const QString& entityID) {
126 return url + " [EntityID:" + entityID + "]";
127}
128
110static bool hasCorrectSyntax(const QScriptProgram& program) {129static bool hasCorrectSyntax(const QScriptProgram& program) {
111 const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());130 const auto syntaxCheck = QScriptEngine::checkSyntax(program.sourceCode());
112 if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {131 if (syntaxCheck.state() != QScriptSyntaxCheckResult::Valid) {
@@ -1303,25 +1322,6 @@ void ScriptEngine::loadEntityScript(QWeakPointer<ScriptEngine> theEngine, const · 1190 unmodified lines
1303 }, forceRedownload);1322 }, forceRedownload);
1304}1323}
1305 1324
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(...)
1310QString extractUrlFromEntityUrl(const 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}]
1321QString encodeEntityIdIntoEntityUrl(const QString& url, const QString& entityID) {
1322 return url + " [EntityID:" + entityID + "]";
1323}
1324
1325// since all of these operations can be asynch we will always do the actual work in the response handler1325// since all of these operations can be asynch we will always do the actual work in the response handler
1326// for the download1326// for the download
1327void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {1327void ScriptEngine::entityScriptContentAvailable(const EntityItemID& entityID, const QString& scriptOrURL, const QString& contents, bool isURL, bool success) {