nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));  if (xpc) { nsCOMPtr<nsIXPCNativeCallContext> nccx; xpc->GetCurrentNativeCallContext(getter_AddRefs(nccx)); if (nccx) { nccx->SetExceptionWasThrown(PR_TRUE); } }
SetXPCExceptionWasThrown();
JSValueToAString(JSContext *cx, jsval val, nsAString *result,                 PRBool *isUndefined){  if (isUndefined) {    *isUndefined = JSVAL_IS_VOID(val);  }  if (!result) {    return NS_OK;  }  JSString* jsstring = ::JS_ValueToString(cx, val);  if (jsstring) {    result->Assign(NS_REINTERPRET_CAST(const PRUnichar*,                                       ::JS_GetStringChars(jsstring)),                   ::JS_GetStringLength(jsstring));  } else {    result->Truncate();    // We failed to convert val to a string. We're either OOM, or the    // security manager denied access to .toString(), or somesuch, on    // an object. Treat this case as if the result were undefined.    if (isUndefined) {      *isUndefined = PR_TRUE;    }    if (!::JS_IsExceptionPending(cx)) {      // JS_ValueToString() returned null w/o an exception      // pending. That means we're OOM.      return NS_ERROR_OUT_OF_MEMORY;    }    // We've got a pending exception. Tell XPConnect's current native    // call context (if any) about this exception so that it doesn't    // keep going as if nothing happened.    nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));    if (xpc) {      nsCOMPtr<nsIXPCNativeCallContext> nccx;      xpc->GetCurrentNativeCallContext(getter_AddRefs(nccx));      if (nccx) {        nccx->SetExceptionWasThrown(PR_TRUE);      }    }  }  return NS_OK;}