Skip to content
Snippets Groups Projects
Commit b7c2ba58 authored by rswindell's avatar rswindell
Browse files

Bug-fix: prompt() no longer returns the \n with the string (whoops).

js_exec() now displays the number of seconds/milliseconds it took to compile
and execute a script (if either duration is greater than 0).
parent d1733834
No related branches found
No related tags found
No related merge requests found
......@@ -430,7 +430,7 @@ js_prompt(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
if(!fgets(instr,sizeof(instr),stdin))
return(JS_TRUE);
if((str=JS_NewStringCopyZ(cx, instr))==NULL)
if((str=JS_NewStringCopyZ(cx, truncnl(instr)))==NULL)
return(JS_FALSE);
*rval = STRING_TO_JSVAL(str);
......@@ -613,6 +613,8 @@ long js_exec(const char *fname, char** args)
jsval val;
jsval rval=JSVAL_VOID;
int32 result=0;
clock_t start;
clock_t diff;
if(fname!=NULL) {
if(strcspn(fname,"/\\")==strlen(fname)) {
......@@ -707,14 +709,27 @@ long js_exec(const char *fname, char** args)
if(fp!=NULL && fp!=stdin)
fclose(fp);
start=msclock();
if((js_script=JS_CompileScript(js_cx, js_glob, js_buf, js_buflen, fname==NULL ? NULL : path, 1))==NULL) {
lprintf(LOG_ERR,"!Error compiling script from %s",path);
return(-1);
}
JS_ExecuteScript(js_cx, js_glob, js_script, &rval);
if((diff=msclock()-start) > 0)
fprintf(statfp,"%s compiled in %u.%03u seconds\n"
,path
,diff/MSCLOCKS_PER_SEC
,diff%MSCLOCKS_PER_SEC);
start=msclock();
JS_ExecuteScript(js_cx, js_glob, js_script, &rval);
js_EvalOnExit(js_cx, js_glob, &branch);
if((diff=msclock()-start) > 0)
fprintf(statfp,"%s executed in %u.%03u seconds\n"
,path
,diff/MSCLOCKS_PER_SEC
,diff%MSCLOCKS_PER_SEC);
JS_GetProperty(js_cx, js_glob, "exit_code", &rval);
if(rval!=JSVAL_VOID) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment