ok = JS_ExecuteScript(cx, obj, script, &result); if (ok && result != JSVAL_VOID) {  older = JS_SetErrorReporter(cx, NULL); str = JS_ValueToString(cx, result); JS_SetErrorReporter(cx, older);  if (str) fprintf(gOutFile, "%s\n", JS_GetStringBytes(str)); else ok = JS_FALSE; }
if (!compileOnly) { ok = JS_ExecuteScript(cx, obj, script, &result); if (ok && result != JSVAL_VOID) {  older = JS_SetErrorReporter(cx, NULL); str = JS_ValueToString(cx, result); JS_SetErrorReporter(cx, older);  if (str) fprintf(gOutFile, "%s\n", JS_GetStringBytes(str)); else ok = JS_FALSE; }
ProcessFile(JSContext *cx, JSObject *obj, const char *filename, FILE *file){    JSScript *script;    jsval result;    int lineno, startline;    JSBool ok, hitEOF;    char *bufp, buffer[4096];    JSString *str;    if (!isatty(fileno(file))) {        /*         * It's not interactive - just execute it.         *         * 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.         */        int ch = fgetc(file);        if (ch == '#') {            while((ch = fgetc(file)) != EOF) {                if(ch == '\n' || ch == '\r')                    break;            }        }        ungetc(ch, file);        DoBeginRequest(cx);        script = JS_CompileFileHandleForPrincipals(cx, obj, filename, file,                                                   gJSPrincipals);        if (script) {            (void)JS_ExecuteScript(cx, obj, script, &result);            JS_DestroyScript(cx, script);        }        DoEndRequest(cx);        return;    }    /* It's an interactive filehandle; drop into read-eval-print loop. */    lineno = 1;    hitEOF = JS_FALSE;    do {        bufp = buffer;        *bufp = '\0';        /*         * Accumulate lines until we get a 'compilable unit' - one that either         * generates an error (before running out of source) or that compiles         * cleanly.  This should be whenever we get a complete statement that         * coincides with the end of a line.         */        startline = lineno;        do {            if (!GetLine(cx, bufp, file, startline == lineno ? "js> " : "")) {                hitEOF = JS_TRUE;                break;            }            bufp += strlen(bufp);            lineno++;        } while (!JS_BufferIsCompilableUnit(cx, obj, buffer, strlen(buffer)));                DoBeginRequest(cx);        /* Clear any pending exception from previous failed compiles.  */        JS_ClearPendingException(cx);        script = JS_CompileScriptForPrincipals(cx, obj, gJSPrincipals, buffer,                                               strlen(buffer), "typein", startline);        if (script) {            JSErrorReporter older;            ok = JS_ExecuteScript(cx, obj, script, &result);            if (ok && result != JSVAL_VOID) {                /* Suppress error reports from JS_ValueToString(). */                older = JS_SetErrorReporter(cx, NULL);                str = JS_ValueToString(cx, result);                JS_SetErrorReporter(cx, older);                if (str)                    fprintf(gOutFile, "%s\n", JS_GetStringBytes(str));                else                    ok = JS_FALSE;            }#if 0#if JS_HAS_ERROR_EXCEPTIONS            /*             * Require that any time we return failure, an exception has             * been set.             */            JS_ASSERT(ok || JS_IsExceptionPending(cx));            /*             * Also that any time an exception has been set, we've             * returned failure.             */            JS_ASSERT(!JS_IsExceptionPending(cx) || !ok);#endif /* JS_HAS_ERROR_EXCEPTIONS */#endif            JS_DestroyScript(cx, script);        }        DoEndRequest(cx);    } while (!hitEOF && !gQuitting);    fprintf(gOutFile, "\n");    return;}