Created
October 25, 2010 12:18
-
-
Save mihaisucan/644857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// static | |
nsresult | |
XPCConvert::JSErrorToXPCException(XPCCallContext& ccx, | |
const char* message, | |
const char* ifaceName, | |
const char* methodName, | |
const JSErrorReport* report, | |
nsIException** exceptn) | |
{ | |
nsresult rv = NS_ERROR_FAILURE; | |
nsScriptError* data; | |
if(report) | |
{ | |
nsAutoString bestMessage; | |
if(report && report->ucmessage) | |
{ | |
bestMessage = (const PRUnichar *)report->ucmessage; | |
} | |
else if(message) | |
{ | |
bestMessage.AssignWithConversion(message); | |
} | |
else | |
{ | |
bestMessage.AssignLiteral("JavaScript Error"); | |
} | |
data = new nsScriptError(); | |
if(!data) | |
return NS_ERROR_OUT_OF_MEMORY; | |
NS_ADDREF(data); | |
// START: new code by me | |
PRUint64 windowID = 0; | |
JSContext * cx = ccx.GetJSContext(); | |
nsIScriptContext *dynamicContext = | |
nsJSUtils::GetDynamicScriptContext(cx); | |
if (dynamicContext) { | |
nsIScriptGlobalObject *globalObject = | |
dynamicContext->GetGlobalObject(); | |
if (globalObject) { | |
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(globalObject); | |
if (win) { | |
windowID = win->WindowID(); | |
} | |
} | |
} | |
nsIScriptError2* data2 = do_QueryObject(data); | |
if (data2) { | |
data2->InitWithWindowID(bestMessage.get(), | |
NS_ConvertASCIItoUTF16(report->filename).get(), | |
(const PRUnichar *)report->uclinebuf, report->lineno, | |
report->uctokenptr - report->uclinebuf, report->flags, | |
"XPConnect JavaScript", windowID); | |
} else { | |
// END: new code by me | |
data->Init(bestMessage.get(), | |
NS_ConvertASCIItoUTF16(report->filename).get(), | |
(const PRUnichar *)report->uclinebuf, report->lineno, | |
report->uctokenptr - report->uclinebuf, report->flags, | |
"XPConnect JavaScript"); | |
} | |
} | |
else | |
data = nsnull; | |
if(data) | |
{ | |
nsCAutoString formattedMsg; | |
data->ToString(formattedMsg); | |
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS, | |
formattedMsg.get(), ifaceName, methodName, | |
static_cast<nsIScriptError*>(data), | |
exceptn, nsnull, nsnull); | |
NS_RELEASE(data); | |
} | |
else | |
{ | |
rv = ConstructException(NS_ERROR_XPC_JAVASCRIPT_ERROR, | |
nsnull, ifaceName, methodName, nsnull, | |
exceptn, nsnull, nsnull); | |
} | |
return rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment