244 |
|
|
245 |
|
QScriptEngine engine; |
246 |
|
QScriptValue engineResult; // variable to check for js_errors |
247 |
+ |
double elapsed_secs; // elapsed seconds that a user script took |
248 |
+ |
clock_t begin; // seconds that a script started |
249 |
|
|
250 |
|
// Add echo function so user can debug the code |
251 |
|
QScriptValue echoFunction = engine.newFunction(echo); |
270 |
|
|
271 |
|
engine.globalObject().setProperty("$xmlData",currXmlFileString); |
272 |
|
|
273 |
+ |
if(this->verboseEnabled){ |
274 |
+ |
begin = clock(); |
275 |
+ |
} |
276 |
+ |
|
277 |
|
// main needs to be called so the user code is evaluated |
278 |
+ |
// alternatively you can do: myFunc=engine.evaluate('(function main(){})'); myFunc.call(); |
279 |
+ |
// Note the () around the function |
280 |
|
engineResult=engine.evaluate("main(); function main() {"+jsString+"}"); // main funtion allows to use return to exit prematurely from user code |
281 |
|
|
282 |
+ |
if(this->verboseEnabled){ |
283 |
+ |
elapsed_secs = double(clock() - begin) / CLOCKS_PER_SEC; |
284 |
+ |
|
285 |
+ |
// Warn the user if the script took much time |
286 |
+ |
if(elapsed_secs>SLOW_SCRIPT_TIME){ |
287 |
+ |
std::cout << "Warning: Slow javascript code detected.\n" << |
288 |
+ |
"Warning: Script execution seconds: " << elapsed_secs |
289 |
+ |
<< std::endl; |
290 |
+ |
} |
291 |
+ |
} |
292 |
+ |
|
293 |
|
if (engine.hasUncaughtException()) { |
294 |
|
displayJsException(engine,engineResult); |
295 |
|
} |
451 |
|
|
452 |
|
// Add --no-backups and --no-verbose if patch was called with that arguments |
453 |
|
if(!this->backupsEnabled){ |
454 |
< |
command.append(" --no-backups"); |
454 |
> |
command.append(" --no-backups "); |
455 |
|
} |
456 |
|
|
457 |
|
if(!this->verboseEnabled){ |
458 |
< |
command.append(" --no-verbose"); |
458 |
> |
command.append(" --no-verbose "); |
459 |
|
} |
460 |
|
|
461 |
|
command.replace("'","\""); //replace apostrophe by quotes, to avoid problems |