if (JS_IsExceptionPending(cx) && JS_GetPendingException(cx, &result)) {  JSErrorReporter older; older = JS_SetErrorReporter(cx, NULL); str = JS_ValueToString(cx, result); JS_SetErrorReporter(cx, older);   if (str) { fprintf(stderr, "Uncaught javascript exception: %s\n", JS_GetStringBytes(str)); } else { fprintf(stderr, "Uncaught javascript exception\n"); } JS_ClearPendingException(cx); }
Process(JSContext *cx, JSObject *obj, char *filename){    JSTokenStream *ts;    JSCodeGenerator cg;    JSBool ok;    JSScript *script;    jsval result;    JSString *str;    ts = js_NewFileTokenStream(cx, filename, stdin);    if (!ts)	goto out;#ifdef JSDEBUGGER    if (!filename)	ts->filename = "typein";#endif    if (isatty(fileno(ts->file))) {	ts->flags |= TSF_INTERACTIVE;    } else {        /* Support the UNIX #! shell hack; gobble the first line if it starts         * with '#'.  TODO - this isn't quite compatible with sharp variables,         * as a legal js program (using sharp variables) might start with '#'.         * But that would require multi-character lookahead.         */        char ch = fgetc(ts->file);        if (ch == '#') {            while((ch = fgetc(ts->file)) != EOF) {                if(ch == '\n' || ch == '\r')                    break;            }        }        ungetc(ch, ts->file);    }    do {	js_InitCodeGenerator(cx, &cg, ts->filename, ts->lineno, ts->principals);	do {	    if (ts->flags & TSF_INTERACTIVE)		printf("js> ");	    ok = js_CompileTokenStream(cx, obj, ts, &cg);	    if (ts->flags & TSF_ERROR) {		ts->flags &= ~TSF_ERROR;		CLEAR_PUSHBACK(ts);		ok = JS_TRUE;	    }	} while (ok && !(ts->flags & TSF_EOF) && CG_OFFSET(&cg) == 0);	if (ok) {	    script = js_NewScriptFromCG(cx, &cg, NULL);	    if (script) {		if (JS_ExecuteScript(cx, obj, script, &result) &&		    (ts->flags & TSF_INTERACTIVE) &&		    result != JSVAL_VOID) {		    str = JS_ValueToString(cx, result);		    if (str)			printf("%s\n", JS_GetStringBytes(str));		}		JS_DestroyScript(cx, script);	    }	}	cg.firstLine = ts->lineno;	js_ResetCodeGenerator(cx, &cg);	RESET_TOKENBUF(ts);    } while (!(ts->flags & TSF_EOF));out:    if (ts)	(void) js_CloseTokenStream(cx, ts);    PR_FreeArenaPool(&cx->codePool);    PR_FreeArenaPool(&cx->tempPool);}