diff --git a/js/xpconnect/idl/xpccomponents.idl b/js/xpconnect/idl/xpccomponents.idl index 7c933820e25..bbcd413d23e 100644 --- a/js/xpconnect/idl/xpccomponents.idl +++ b/js/xpconnect/idl/xpccomponents.idl @@ -152,7 +152,7 @@ interface ScheduledGCCallback : nsISupports /** * interface of Components.utils */ -[scriptable, uuid(6b1ca9d9-a941-4ba8-8421-af72f544e795)] +[scriptable, uuid(90894460-26a2-44c2-a3fc-c96a5286614e)] interface nsIXPCComponents_Utils : nsISupports { @@ -166,7 +166,7 @@ interface nsIXPCComponents_Utils : nsISupports * an exception handler. If it is not a JS error object, the parameter * is converted to a string and reported as a new error. */ - void reportError(); + [implicit_jscontext] void reportError(in jsval error); /* lookupMethod is designed to be called from JavaScript only. * @@ -351,7 +351,7 @@ interface nsIXPCComponents_Utils : nsISupports /** * interface of JavaScript's 'Components' object */ -[scriptable, uuid(9d654574-cb2c-4bd0-a0fd-c10443fe2135)] +[scriptable, uuid(4676e9cf-2c07-423b-b161-26bb9d8067d3)] interface nsIXPCComponents : nsISupports { readonly attribute nsIXPCComponents_Interfaces interfaces; @@ -377,7 +377,7 @@ interface nsIXPCComponents : nsISupports jsval lookupMethod(in jsval obj, in jsval name); /* @deprecated Use Components.utils.reportError instead. */ - [deprecated] void reportError(); + [deprecated, implicit_jscontext] void reportError(in jsval error); /* 'lastResult' is accessible via JavaScript only */ /* 'returnCode' is accessible via JavaScript only */ diff --git a/js/xpconnect/src/XPCComponents.cpp b/js/xpconnect/src/XPCComponents.cpp index f897984dd78..c189123769c 100644 --- a/js/xpconnect/src/XPCComponents.cpp +++ b/js/xpconnect/src/XPCComponents.cpp @@ -2686,65 +2686,22 @@ nsXPCComponents_Utils::LookupMethod(const JS::Value& object, /* void reportError (); */ NS_IMETHODIMP -nsXPCComponents_Utils::ReportError() +nsXPCComponents_Utils::ReportError(const JS::Value &error, JSContext *cx) { // This function shall never fail! Silently eat any failure conditions. - nsresult rv; nsCOMPtr console(do_GetService(NS_CONSOLESERVICE_CONTRACTID)); nsCOMPtr scripterr(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID)); - nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); - if (!scripterr || !console || !xpc) - return NS_OK; - - // get the xpconnect native call context - nsAXPCNativeCallContext *cc = nsnull; - xpc->GetCurrentNativeCallContext(&cc); - if (!cc) - return NS_OK; - -// Check disabled until deprecated Components.reportError removed. -#undef CHECK_FOR_INDIRECT_CALL -#ifdef CHECK_FOR_INDIRECT_CALL - // verify that we are being called from JS (i.e. the current call is - // to this object - though we don't verify that it is to this exact method) - nsCOMPtr callee; - cc->GetCallee(getter_AddRefs(callee)); - if (!callee || callee.get() != - static_cast - (static_cast(this))) { - NS_ERROR("reportError() must only be called from JS!"); - return NS_ERROR_FAILURE; - } -#endif - - // Get JSContext of current call - JSContext* cx; - rv = cc->GetJSContext(&cx); - if (NS_FAILED(rv) || !cx) + if (!scripterr || !console) return NS_OK; JSAutoRequest ar(cx); - // get argc and argv and verify arg count - PRUint32 argc; - rv = cc->GetArgc(&argc); - if (NS_FAILED(rv)) - return NS_OK; - - if (argc < 1) - return NS_ERROR_XPC_NOT_ENOUGH_ARGS; - - jsval* argv; - rv = cc->GetArgvPtr(&argv); - if (NS_FAILED(rv) || !argv) - return NS_OK; - const PRUint64 innerWindowID = nsJSUtils::GetCurrentlyRunningCodeInnerWindowID(cx); - JSErrorReport* err = JS_ErrorFromException(cx, argv[0]); + JSErrorReport *err = JS_ErrorFromException(cx, error); if (err) { // It's a proper JS Error nsAutoString fileUni; @@ -2752,56 +2709,47 @@ nsXPCComponents_Utils::ReportError() PRUint32 column = err->uctokenptr - err->uclinebuf; - rv = scripterr->InitWithWindowID(reinterpret_cast - (err->ucmessage), - fileUni.get(), - reinterpret_cast - (err->uclinebuf), - err->lineno, - column, - err->flags, - "XPConnect JavaScript", innerWindowID); - if (NS_FAILED(rv)) - return NS_OK; + nsresult rv = scripterr->InitWithWindowID( + static_cast(err->ucmessage), fileUni.get(), + static_cast(err->uclinebuf), err->lineno, + column, err->flags, "XPConnect JavaScript", innerWindowID); + NS_ENSURE_SUCCESS(rv, NS_OK); nsCOMPtr logError = do_QueryInterface(scripterr); console->LogMessage(logError); return NS_OK; } - // It's not a JS Error object, so we synthesize as best we're able - JSString* msgstr = JS_ValueToString(cx, argv[0]); - if (msgstr) { - // Root the string during scripterr->Init - argv[0] = STRING_TO_JSVAL(msgstr); - - nsCOMPtr frame; - nsXPConnect* xpc = nsXPConnect::GetXPConnect(); - if (xpc) - xpc->GetCurrentJSStack(getter_AddRefs(frame)); - - nsXPIDLCString fileName; - PRInt32 lineNo = 0; - if (frame) { - frame->GetFilename(getter_Copies(fileName)); - frame->GetLineNumber(&lineNo); - } - - const jschar *msgchars = JS_GetStringCharsZ(cx, msgstr); - if (!msgchars) - return NS_OK; - - rv = scripterr->InitWithWindowID(reinterpret_cast(msgchars), - NS_ConvertUTF8toUTF16(fileName).get(), - nsnull, - lineNo, 0, 0, - "XPConnect JavaScript", innerWindowID); - if (NS_SUCCEEDED(rv)) { - nsCOMPtr logError = do_QueryInterface(scripterr); - console->LogMessage(logError); - } + // It's not a JS Error object, so we synthesize as best we're able. + JSString *msgstr = JS_ValueToString(cx, error); + if (!msgstr) { + return NS_OK; } + nsCOMPtr frame; + nsXPConnect *xpc = nsXPConnect::GetXPConnect(); + if (xpc) + xpc->GetCurrentJSStack(getter_AddRefs(frame)); + + nsXPIDLCString fileName; + PRInt32 lineNo = 0; + if (frame) { + frame->GetFilename(getter_Copies(fileName)); + frame->GetLineNumber(&lineNo); + } + + const jschar *msgchars = JS_GetStringCharsZ(cx, msgstr); + if (!msgchars) + return NS_OK; + + nsresult rv = scripterr->InitWithWindowID( + reinterpret_cast(msgchars), + NS_ConvertUTF8toUTF16(fileName).get(), + nsnull, lineNo, 0, 0, "XPConnect JavaScript", innerWindowID); + NS_ENSURE_SUCCESS(rv, NS_OK); + + nsCOMPtr logError = do_QueryInterface(scripterr); + console->LogMessage(logError); return NS_OK; } @@ -4281,17 +4229,16 @@ nsXPCComponents::LookupMethod(const JS::Value& object, } /* void reportError (); */ -NS_IMETHODIMP nsXPCComponents::ReportError() +NS_IMETHODIMP nsXPCComponents::ReportError(const JS::Value &error, JSContext *cx) { - nsresult rv; - nsCOMPtr utils; - NS_WARNING("Components.reportError deprecated, use Components.utils.reportError"); - rv = GetUtils(getter_AddRefs(utils)); + + nsCOMPtr utils; + nsresult rv = GetUtils(getter_AddRefs(utils)); if (NS_FAILED(rv)) return rv; - return utils->ReportError(); + return utils->ReportError(error, cx); } /* string canCreateWrapper (in nsIIDPtr iid); */