JS_SetPendingException(cx, OBJECT_TO_JSVAL(errObject));
js_ErrorToException(JSContext *cx, const char *message, JSErrorReport *reportp){    JSErrNum errorNumber;    JSExnType exn;    JSBool ok;    JSObject *errProto, *errObject;    JSString *messageStr, *filenameStr;    uintN lineno;    JSExnPrivate *privateData;    /* Find the exception index associated with this error. */    JS_ASSERT(reportp);    if (JSREPORT_IS_WARNING(reportp->flags))        return JS_FALSE;    errorNumber = (JSErrNum) reportp->errorNumber;    exn = errorToExceptionNum[errorNumber];    JS_ASSERT(exn < JSEXN_LIMIT);#if defined( DEBUG_mccabe ) && defined ( PRINTNAMES )    /* Print the error name and the associated exception name to stderr */    fprintf(stderr, "%s\t%s\n",            errortoexnname[errorNumber].name,            errortoexnname[errorNumber].exception);#endif    /*     * Return false (no exception raised) if no exception is associated     * with the given error number.     */    if (exn == JSEXN_NONE)        return JS_FALSE;    /*     * Prevent runaway recursion, just as the Exception native constructor     * must do, via cx->creatingException.  If an out-of-memory error occurs,     * no exception object will be created, but we don't assume that OOM is     * the only kind of error that subroutines of this function called below     * might raise.     */    if (cx->creatingException)        return JS_FALSE;    cx->creatingException = JS_TRUE;    /*     * Try to get an appropriate prototype by looking up the corresponding     * exception constructor name in the scope chain of the current context's     * top stack frame, or in the global object if no frame is active.     *     * XXXbe hack around JSCLASS_NEW_RESOLVE code in js_LookupProperty that     *       checks cx->fp, cx->fp->pc, and js_CodeSpec[*cx->fp->pc] in order     *       to compute resolve flags such as JSRESOLVE_ASSIGNING.  The bug     *       is that this "internal" js_GetClassPrototype call may trigger a     *       resolve of exceptions[exn].name if the global object uses a lazy     *       standard class resolver (see JS_ResolveStandardClass), but the     *       current frame and bytecode end up affecting the resolve flags.     */    {        JSStackFrame *fp = cx->fp;        jsbytecode *pc = NULL;        if (fp) {            pc = fp->pc;            fp->pc = NULL;        }        ok = js_GetClassPrototype(cx, exceptions[exn].name, &errProto);        if (pc)            fp->pc = pc;        if (!ok)            goto out;    }    errObject = js_NewObject(cx, &ExceptionClass, errProto, NULL);    if (!errObject) {        ok = JS_FALSE;        goto out;    }    messageStr = JS_NewStringCopyZ(cx, message);    if (!messageStr) {        ok = JS_FALSE;        goto out;    }    if (reportp) {        filenameStr = JS_NewStringCopyZ(cx, reportp->filename);        if (!filenameStr) {            ok = JS_FALSE;            goto out;        }        lineno = reportp->lineno;    } else {        filenameStr = cx->runtime->emptyString;        lineno = 0;    }    ok = InitExceptionObject(cx, errObject, messageStr, filenameStr, lineno);    if (!ok)        goto out;    /*     * Construct a new copy of the error report struct, and store it in the     * exception object's private data.  We can't use the error report struct     * that was passed in, because it's stack-allocated, and also because it     * may point to transient data in the JSTokenStream.     */    privateData = exn_newPrivate(cx, reportp);    if (!privateData) {        ok = JS_FALSE;        goto out;    }    OBJ_SET_SLOT(cx, errObject, JSSLOT_PRIVATE, PRIVATE_TO_JSVAL(privateData));    /* Set the generated Exception object as the current exception. */    JS_SetPendingException(cx, OBJECT_TO_JSVAL(errObject));    /* Flag the error report passed in to indicate an exception was raised. */    reportp->flags |= JSREPORT_EXCEPTION;out:    cx->creatingException = JS_FALSE;    return ok;}