ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/XmlTools2/trunk/xmlpatch.cpp
(Generate patch)

Comparing XmlTools2/trunk/xmlpatch.cpp (file contents):
Revision 955 by iritscen, Tue Feb 11 17:08:41 2014 UTC vs.
Revision 956 by s10k, Wed Feb 12 22:15:52 2014 UTC

# Line 242 | Line 242 | void XmlPatch::executeCustomCommandOpera
242  
243          QString currXmlFileString;
244  
245 #ifdef _USE_OLD_JS_ENGINE
245          QScriptEngine engine;
246          QScriptValue engineResult; // variable to check for js_errors
248 #else
249        QJSEngine engine;
250        QJSValue engineResult; // variable to check for js_errors
251 #endif
247  
248          // Add echo function so user can debug the code
249          QScriptValue echoFunction = engine.newFunction(echo);
# Line 276 | Line 271 | void XmlPatch::executeCustomCommandOpera
271          // main needs to be called so the user code is evaluated
272          engineResult=engine.evaluate("main(); function main() {"+jsString+"}"); // main funtion allows to use return to exit prematurely from user code
273  
279 #ifdef _USE_OLD_JS_ENGINE
274          if (engine.hasUncaughtException()) {
275              displayJsException(engine,engineResult);
276          }
283 #else
284        checkForJsException(engineResult);
285 #endif
277  
278          if(!currXmlFile.open(QFile::WriteOnly | QFile::Text | QIODevice::Truncate)){
279              UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Error loading '" + filesToProcess[i] + "' file for @CUSTOM_CODE write operation.");
# Line 290 | Line 281 | void XmlPatch::executeCustomCommandOpera
281  
282          engineResult=engine.globalObject().property("$xmlData");
283  
293 #ifdef _USE_OLD_JS_ENGINE
284          if (engine.hasUncaughtException()) {
285              displayJsException(engine,engineResult);
286          }
297 #else
298        checkForJsException(engineResult);
299 #endif
287  
288          QTextStream(&currXmlFile) << engineResult.toString(); // retreive the modified xml by javascript and save it to the file
289      }
# Line 510 | Line 497 | QString XmlPatch::getPatchParameterValue
497      return line.mid(startValueIdx,endValueIdx-startValueIdx); // return the value of the parameter (is in the middle of the mandatory quotes)
498   }
499  
513 #ifdef _USE_OLD_JS_ENGINE
500   void XmlPatch::displayJsException(QScriptEngine &engine, QScriptValue &engineResult){
501      if (engine.hasUncaughtException()) {
502          UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Uncaught js exception (user code) at line " +QString::number(engine.uncaughtExceptionLineNumber()) + ":\n" + engineResult.toString());
503      }
504   }
519 #else
520 void XmlPatch::checkForJsException(QJSValue &engineResult){
521    if (engineResult.isError()) {
522        UtilXmlTools::displayErrorMessage("@CUSTOM_CODE","Uncaught js exception (user code):\n" + engineResult.toString());
523    }
524 }
525 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)