зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1333990: Follow-up: Use safer conversion functions when creating error message JS strings. r=bz
MozReview-Commit-ID: FimoWFIgUxL --HG-- extra : rebase_source : 7b9193ac1c12dc96b269ee3dea167edc4051669f
This commit is contained in:
Родитель
4af9951cec
Коммит
b3d00ca35b
|
@ -195,12 +195,15 @@ AsyncScriptCompiler::Reject(JSContext* aCx)
|
||||||
void
|
void
|
||||||
AsyncScriptCompiler::Reject(JSContext* aCx, const char* aMsg)
|
AsyncScriptCompiler::Reject(JSContext* aCx, const char* aMsg)
|
||||||
{
|
{
|
||||||
nsAutoCString msg(aMsg);
|
nsAutoString msg;
|
||||||
msg.Append(": ");
|
msg.AppendASCII(aMsg);
|
||||||
msg.Append(mURL);
|
msg.AppendLiteral(": ");
|
||||||
|
AppendUTF8toUTF16(mURL, msg);
|
||||||
|
|
||||||
RootedValue exn(aCx, StringValue(JS_NewStringCopyZ(aCx, msg.get())));
|
RootedValue exn(aCx);
|
||||||
|
if (xpc::NonVoidStringToJsval(aCx, msg, &exn)) {
|
||||||
JS_SetPendingException(aCx, exn);
|
JS_SetPendingException(aCx, exn);
|
||||||
|
}
|
||||||
|
|
||||||
Reject(aCx);
|
Reject(aCx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,17 +92,21 @@ mozJSSubScriptLoader::~mozJSSubScriptLoader()
|
||||||
NS_IMPL_ISUPPORTS(mozJSSubScriptLoader, mozIJSSubScriptLoader)
|
NS_IMPL_ISUPPORTS(mozJSSubScriptLoader, mozIJSSubScriptLoader)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReportError(JSContext* cx, const char* msg)
|
ReportError(JSContext* cx, const nsACString& msg)
|
||||||
{
|
{
|
||||||
RootedValue exn(cx, JS::StringValue(JS_NewStringCopyZ(cx, msg)));
|
NS_ConvertUTF8toUTF16 ucMsg(msg);
|
||||||
|
|
||||||
|
RootedValue exn(cx);
|
||||||
|
if (xpc::NonVoidStringToJsval(cx, ucMsg, &exn)) {
|
||||||
JS_SetPendingException(cx, exn);
|
JS_SetPendingException(cx, exn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ReportError(JSContext* cx, const char* origMsg, nsIURI* uri)
|
ReportError(JSContext* cx, const char* origMsg, nsIURI* uri)
|
||||||
{
|
{
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
ReportError(cx, origMsg);
|
ReportError(cx, nsDependentCString(origMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +118,7 @@ ReportError(JSContext* cx, const char* origMsg, nsIURI* uri)
|
||||||
nsAutoCString msg(origMsg);
|
nsAutoCString msg(origMsg);
|
||||||
msg.Append(": ");
|
msg.Append(": ");
|
||||||
msg.Append(spec);
|
msg.Append(spec);
|
||||||
ReportError(cx, msg.get());
|
ReportError(cx, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -620,7 +624,7 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
|
||||||
: nullptr;
|
: nullptr;
|
||||||
nsCOMPtr<nsIIOService> serv = do_GetService(NS_IOSERVICE_CONTRACTID);
|
nsCOMPtr<nsIIOService> serv = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||||
if (!serv) {
|
if (!serv) {
|
||||||
ReportError(cx, LOAD_ERROR_NOSERVICE);
|
ReportError(cx, NS_LITERAL_CSTRING(LOAD_ERROR_NOSERVICE));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,13 +632,13 @@ mozJSSubScriptLoader::DoLoadSubScriptWithOptions(const nsAString& url,
|
||||||
// canonicalized spec.
|
// canonicalized spec.
|
||||||
rv = NS_NewURI(getter_AddRefs(uri), NS_LossyConvertUTF16toASCII(url).get(), nullptr, serv);
|
rv = NS_NewURI(getter_AddRefs(uri), NS_LossyConvertUTF16toASCII(url).get(), nullptr, serv);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
ReportError(cx, LOAD_ERROR_NOURI);
|
ReportError(cx, NS_LITERAL_CSTRING(LOAD_ERROR_NOURI));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = uri->GetSpec(uriStr);
|
rv = uri->GetSpec(uriStr);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
ReportError(cx, LOAD_ERROR_NOSPEC);
|
ReportError(cx, NS_LITERAL_CSTRING(LOAD_ERROR_NOSPEC));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче