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); |
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."); |
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 |
|
} |
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 |