Bug 1619112 part 5. Stop accepting nsAString in ErrorResult error-throwing. r=smaug

Callers should pass in UTF-8, since that's what the JS engine ends up with in the end anyway.

The various URL changes are because NS_NewURI converts incoming nsAString to
UTF-8 anyway.  So we might as well do that up-front and then use the UTF-8
string for both the NS_NewURI call and the error-reporting if it fails.

Differential Revision: https://phabricator.services.mozilla.com/D65543

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-03-06 21:08:02 +00:00
Родитель b3ccd8dfb9
Коммит 00cd5d4380
35 изменённых файлов: 197 добавлений и 181 удалений

Просмотреть файл

@ -60,8 +60,7 @@ already_AddRefed<DocumentTimeline> DocumentTimeline::Constructor(
if (originTime == TimeDuration::Forever() ||
originTime == -TimeDuration::Forever()) {
aRv.ThrowTypeError<dom::MSG_TIME_VALUE_OUT_OF_RANGE>(
NS_LITERAL_STRING("Origin time"));
aRv.ThrowTypeError<dom::MSG_TIME_VALUE_OUT_OF_RANGE>("Origin time");
return nullptr;
}
RefPtr<DocumentTimeline> timeline = new DocumentTimeline(doc, originTime);

Просмотреть файл

@ -745,7 +745,8 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
RefPtr<nsAtom> pseudoAtom =
nsCSSPseudoElements::GetPseudoAtom(options.mPseudoElement);
if (!pseudoAtom) {
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(options.mPseudoElement);
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(
NS_ConvertUTF16toUTF8(options.mPseudoElement));
return result;
}
@ -753,7 +754,8 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
pseudoAtom, CSSEnabledState::ForAllContent);
if (!IsSupportedPseudoForWebAnimation(result.mPseudoType)) {
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(options.mPseudoElement);
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(
NS_ConvertUTF16toUTF8(options.mPseudoElement));
}
return result;
@ -1062,14 +1064,16 @@ void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
RefPtr<nsAtom> pseudoAtom =
nsCSSPseudoElements::GetPseudoAtom(aPseudoElement);
if (!pseudoAtom) {
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(aPseudoElement);
aRv.ThrowTypeError<MSG_INVALID_PSEUDO_SELECTOR>(
NS_ConvertUTF16toUTF8(aPseudoElement));
return;
}
pseudoType = nsCSSPseudoElements::GetPseudoType(
pseudoAtom, CSSEnabledState::ForAllContent);
if (!IsSupportedPseudoForWebAnimation(pseudoType)) {
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(aPseudoElement);
aRv.ThrowTypeError<MSG_UNSUPPORTED_PSEUDO_SELECTOR>(
NS_ConvertUTF16toUTF8(aPseudoElement));
return;
}

Просмотреть файл

@ -49,7 +49,7 @@ TimingParams TimingParams::FromOptionsType(const OptionsType& aOptions,
StickyTimeDuration::FromMilliseconds(durationInMs));
} else {
nsPrintfCString error("Duration value %g is less than 0", durationInMs);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(error));
aRv.ThrowTypeError(error);
return result;
}
result.Update();
@ -199,7 +199,8 @@ Maybe<ComputedTimingFunction> TimingParams::ParseEasing(
nsTimingFunction timingFunction;
RefPtr<URLExtraData> url = ServoCSSParser::GetURLExtraData(aDocument);
if (!ServoCSSParser::ParseEasing(aEasing, url, timingFunction)) {
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(aEasing);
aRv.ThrowTypeError<dom::MSG_INVALID_EASING_ERROR>(
NS_ConvertUTF16toUTF8(aEasing));
return Nothing();
}

Просмотреть файл

@ -91,11 +91,11 @@ struct TimingParams {
result.emplace(StickyTimeDuration::FromMilliseconds(durationInMs));
} else {
nsPrintfCString err("Duration (%g) must be nonnegative", durationInMs);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
}
} else if (!aDuration.GetAsString().EqualsLiteral("auto")) {
aRv.ThrowTypeError<dom::MSG_INVALID_DURATION_ERROR>(
aDuration.GetAsString());
NS_ConvertUTF16toUTF8(aDuration.GetAsString()));
}
return result;
}
@ -104,7 +104,7 @@ struct TimingParams {
if (aIterationStart < 0) {
nsPrintfCString err("Iteration start (%g) must not be negative",
aIterationStart);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
}
}
@ -116,7 +116,7 @@ struct TimingParams {
if (aIterations < 0) {
nsPrintfCString err("Iterations (%g) must not be negative", aIterations);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
}
}

Просмотреть файл

@ -658,7 +658,7 @@ bool CustomElementRegistry::JSObjectToAtomArray(
if (!iterable.isUndefined()) {
if (!iterable.isObject()) {
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(aName);
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(NS_ConvertUTF16toUTF8(aName));
return false;
}
@ -669,7 +669,7 @@ bool CustomElementRegistry::JSObjectToAtomArray(
}
if (!iter.valueIsIterable()) {
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(aName);
aRv.ThrowTypeError<MSG_NOT_SEQUENCE>(NS_ConvertUTF16toUTF8(aName));
return false;
}

Просмотреть файл

@ -60,8 +60,7 @@ static bool ValidateAndFixupMatrix2DInit(DOMMatrix2DInit& aMatrixInit,
} \
}
#define ValidateAndSet(field, alias, fieldName, aliasName, defaultValue) \
ValidateAliases((field), (alias), NS_LITERAL_STRING(fieldName), \
NS_LITERAL_STRING(aliasName)); \
ValidateAliases((field), (alias), fieldName, aliasName); \
SetFromAliasOrDefault((field), (alias), (defaultValue));
ValidateAndSet(aMatrixInit.mM11, aMatrixInit.mA, "m11", "a", 1);
@ -81,17 +80,16 @@ static bool ValidateAndFixupMatrix2DInit(DOMMatrix2DInit& aMatrixInit,
// https://drafts.fxtf.org/geometry/#matrix-validate-and-fixup
static bool ValidateAndFixupMatrixInit(DOMMatrixInit& aMatrixInit,
ErrorResult& aRv) {
#define Check3DField(field, fieldName, defaultValue) \
if ((field) != (defaultValue)) { \
if (!aMatrixInit.mIs2D.WasPassed()) { \
aMatrixInit.mIs2D.Construct(false); \
return true; \
} \
if (aMatrixInit.mIs2D.Value()) { \
aRv.ThrowTypeError<MSG_MATRIX_INIT_EXCEEDS_2D>( \
NS_LITERAL_STRING(fieldName)); \
return false; \
} \
#define Check3DField(field, fieldName, defaultValue) \
if ((field) != (defaultValue)) { \
if (!aMatrixInit.mIs2D.WasPassed()) { \
aMatrixInit.mIs2D.Construct(false); \
return true; \
} \
if (aMatrixInit.mIs2D.Value()) { \
aRv.ThrowTypeError<MSG_MATRIX_INIT_EXCEEDS_2D>(fieldName); \
return false; \
} \
}
if (!ValidateAndFixupMatrix2DInit(aMatrixInit, aRv)) {
@ -726,7 +724,7 @@ static void SetDataInMatrix(DOMMatrixReadOnly* aMatrix, const T* aData,
aMatrix->SetE(aData[4]);
aMatrix->SetF(aData[5]);
} else {
nsAutoString lengthStr;
nsAutoCString lengthStr;
lengthStr.AppendInt(aLength);
aRv.ThrowTypeError<MSG_MATRIX_INIT_LENGTH_WRONG>(lengthStr);
}

Просмотреть файл

@ -49,7 +49,7 @@ already_AddRefed<nsDocShellLoadState> LocationBase::CheckURL(
if (NS_WARN_IF(NS_FAILED(rv))) {
nsAutoCString spec;
aURI->GetSpec(spec);
aRv.ThrowTypeError<MSG_URL_NOT_LOADABLE>(NS_ConvertUTF8toUTF16(spec));
aRv.ThrowTypeError<MSG_URL_NOT_LOADABLE>(spec);
return nullptr;
}

Просмотреть файл

@ -1138,13 +1138,14 @@ bool Navigator::SendBeaconInternal(const nsAString& aUrl,
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
getter_AddRefs(uri), aUrl, doc, doc->GetDocBaseURI());
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
aRv.ThrowTypeError<MSG_INVALID_URL>(NS_ConvertUTF16toUTF8(aUrl));
return false;
}
// Spec disallows any schemes save for HTTP/HTTPs
if (!uri->SchemeIs("http") && !uri->SchemeIs("https")) {
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Beacon", aUrl);
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Beacon",
uri->GetSpecOrDefault());
return false;
}
@ -1379,7 +1380,8 @@ Promise* Navigator::Share(const ShareData& aData, ErrorResult& aRv) {
if (aData.mUrl.WasPassed()) {
auto result = doc->ResolveWithBaseURI(aData.mUrl.Value());
if (NS_WARN_IF(result.isErr())) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aData.mUrl.Value());
aRv.ThrowTypeError<MSG_INVALID_URL>(
NS_ConvertUTF16toUTF8(aData.mUrl.Value()));
return nullptr;
}
url = result.unwrap();

Просмотреть файл

@ -370,7 +370,8 @@ bool nsDOMTokenList::ReplaceInternal(const nsAttrValue* aAttr,
bool nsDOMTokenList::Supports(const nsAString& aToken, ErrorResult& aError) {
if (!mSupportedTokens) {
aError.ThrowTypeError<MSG_TOKENLIST_NO_SUPPORTED_TOKENS>(
mElement->LocalName(), nsDependentAtomString(mAttrAtom));
NS_ConvertUTF16toUTF8(mElement->LocalName()),
NS_ConvertUTF16toUTF8(nsDependentAtomString(mAttrAtom)));
return false;
}

Просмотреть файл

@ -144,20 +144,6 @@ struct CStringArrayAppender {
"required by the ErrNum.");
}
// Allow passing nsAString instances for our args.
template <typename... Ts>
static void Append(nsTArray<nsCString>& aArgs, uint16_t aCount,
const nsAString& aFirst, Ts&&... aOtherArgs) {
if (aCount == 0) {
MOZ_ASSERT(false,
"There should not be more string arguments provided than are "
"required by the ErrNum.");
return;
}
aArgs.AppendElement(NS_ConvertUTF16toUTF8(aFirst));
Append(aArgs, aCount - 1, std::forward<Ts>(aOtherArgs)...);
}
// Allow passing nsACString instances for our args.
template <typename... Ts>
static void Append(nsTArray<nsCString>& aArgs, uint16_t aCount,
@ -355,11 +341,6 @@ class TErrorResult {
// To be used when throwing a TypeError with a completely custom
// message string that's only used in one spot.
inline void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
ThrowTypeError(const nsAString& aMessage) {
this->template ThrowTypeError<dom::MSG_ONE_OFF_TYPEERR>(aMessage);
}
inline void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
ThrowTypeError(const nsACString& aMessage) {
this->template ThrowTypeError<dom::MSG_ONE_OFF_TYPEERR>(aMessage);
@ -384,11 +365,6 @@ class TErrorResult {
// To be used when throwing a RangeError with a completely custom
// message string that's only used in one spot.
inline void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
ThrowRangeError(const nsAString& aMessage) {
this->template ThrowRangeError<dom::MSG_ONE_OFF_RANGEERR>(aMessage);
}
inline void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
ThrowRangeError(const nsACString& aMessage) {
this->template ThrowRangeError<dom::MSG_ONE_OFF_RANGEERR>(aMessage);

15
dom/cache/Cache.cpp поставляемый
Просмотреть файл

@ -45,7 +45,9 @@ bool IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv) {
}
if (!validScheme) {
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request", aUrl);
// `url` has been modified, so don't use it here.
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request",
NS_ConvertUTF16toUTF8(aUrl));
return false;
}
@ -56,8 +58,7 @@ static bool IsValidPutRequestMethod(const Request& aRequest, ErrorResult& aRv) {
nsAutoCString method;
aRequest.GetMethod(method);
if (!method.LowerCaseEqualsLiteral("get")) {
NS_ConvertASCIItoUTF16 label(method);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(label);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(method);
return false;
}
@ -79,13 +80,13 @@ static bool IsValidPutResponseStatus(Response& aResponse,
ErrorResult& aRv) {
if ((aPolicy == PutStatusPolicy::RequireOK && !aResponse.Ok()) ||
aResponse.Status() == 206) {
NS_ConvertASCIItoUTF16 type(
ResponseTypeValues::GetString(aResponse.Type()));
nsAutoString status;
nsCString type(ResponseTypeValues::GetString(aResponse.Type()));
nsAutoCString status;
status.AppendInt(aResponse.Status());
nsAutoString url;
aResponse.GetUrl(url);
aRv.ThrowTypeError<MSG_CACHE_ADD_FAILED_RESPONSE>(type, status, url);
aRv.ThrowTypeError<MSG_CACHE_ADD_FAILED_RESPONSE>(
type, status, NS_ConvertUTF16toUTF8(url));
return false;
}

3
dom/cache/TypeUtils.cpp поставляемый
Просмотреть файл

@ -125,8 +125,7 @@ void TypeUtils::ToCacheRequest(
}
if (!schemeValid) {
if (aSchemeAction == TypeErrorOnInvalidScheme) {
NS_ConvertUTF8toUTF16 urlUTF16(url);
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request", urlUTF16);
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>("Request", url);
return;
}
}

Просмотреть файл

@ -218,7 +218,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
// 2, if the URL fails to parse, we reject with a TypeError.
nsPrintfCString err("Invalid URL \"%s\"", aArgs.url().get());
CopyableErrorResult result;
result.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
result.ThrowTypeError(err);
return ClientOpPromise::CreateAndReject(result, __func__);
}
@ -267,7 +267,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
/// out.
nsPrintfCString err("Invalid URL \"%s\"", aArgs.url().get());
CopyableErrorResult result;
result.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
result.ThrowTypeError(err);
return ClientOpPromise::CreateAndReject(result, __func__);
}

Просмотреть файл

@ -170,14 +170,14 @@ void OpenWindow(const ClientOpenWindowArgs& aArgs, BrowsingContext** aBC,
nsresult rv = NS_NewURI(getter_AddRefs(baseURI), aArgs.baseURL());
if (NS_WARN_IF(NS_FAILED(rv))) {
nsPrintfCString err("Invalid base URL \"%s\"", aArgs.baseURL().get());
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
return;
}
rv = NS_NewURI(getter_AddRefs(uri), aArgs.url(), nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
nsPrintfCString err("Invalid URL \"%s\"", aArgs.url().get());
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
return;
}

Просмотреть файл

@ -21,7 +21,7 @@ void TextDecoder::Init(const nsAString& aLabel,
// (https://encoding.spec.whatwg.org/#dom-textdecoder).
const Encoding* encoding = Encoding::ForLabelNoReplacement(aLabel);
if (!encoding) {
nsAutoString label(aLabel);
NS_ConvertUTF16toUTF8 label(aLabel);
label.Trim(" \t\n\f\r");
aRv.ThrowRangeError<MSG_ENCODING_NOT_SUPPORTED>(label);
return;

Просмотреть файл

@ -356,8 +356,7 @@ bool InternalHeaders::IsRevalidationHeader(const nsCString& aName) {
// static
bool InternalHeaders::IsInvalidName(const nsACString& aName, ErrorResult& aRv) {
if (!NS_IsValidHTTPToken(aName)) {
NS_ConvertUTF8toUTF16 label(aName);
aRv.ThrowTypeError<MSG_INVALID_HEADER_NAME>(label);
aRv.ThrowTypeError<MSG_INVALID_HEADER_NAME>(aName);
return true;
}
@ -368,8 +367,7 @@ bool InternalHeaders::IsInvalidName(const nsACString& aName, ErrorResult& aRv) {
bool InternalHeaders::IsInvalidValue(const nsACString& aValue,
ErrorResult& aRv) {
if (!NS_IsReasonableHTTPHeaderValue(aValue)) {
NS_ConvertUTF8toUTF16 label(aValue);
aRv.ThrowTypeError<MSG_INVALID_HEADER_VALUE>(label);
aRv.ThrowTypeError<MSG_INVALID_HEADER_VALUE>(aValue);
return true;
}
return false;

Просмотреть файл

@ -84,11 +84,18 @@ already_AddRefed<nsIURI> ParseURLFromDocument(Document* aDocument,
MOZ_ASSERT(aDocument);
MOZ_ASSERT(NS_IsMainThread());
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString input;
if (!AppendUTF16toUTF8(aInput, input, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> resolvedURI;
aRv = NS_NewURI(getter_AddRefs(resolvedURI), aInput, nullptr,
aDocument->GetBaseURI());
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), input, nullptr,
aDocument->GetBaseURI());
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(input);
}
return resolvedURI.forget();
}
@ -104,7 +111,7 @@ void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
nsAutoCString credentials;
Unused << resolvedURI->GetUserPass(credentials);
if (!credentials.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
return;
}
@ -129,10 +136,17 @@ void GetRequestURLFromDocument(Document* aDocument, const nsAString& aInput,
already_AddRefed<nsIURI> ParseURLFromChrome(const nsAString& aInput,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString input;
if (!AppendUTF16toUTF8(aInput, input, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> uri;
aRv = NS_NewURI(getter_AddRefs(uri), aInput);
if (aRv.Failed()) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
nsresult rv = NS_NewURI(getter_AddRefs(uri), input);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(input);
}
return uri.forget();
}
@ -147,7 +161,7 @@ void GetRequestURLFromChrome(const nsAString& aInput, nsAString& aRequestURL,
nsAutoCString credentials;
Unused << uri->GetUserPass(credentials);
if (!credentials.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
return;
}
@ -180,7 +194,7 @@ already_AddRefed<URL> ParseURLFromWorker(const GlobalObject& aGlobal,
RefPtr<URL> url =
URL::Constructor(aGlobal.GetAsSupports(), aInput, baseURL, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aInput);
aRv.ThrowTypeError<MSG_INVALID_URL>(NS_ConvertUTF16toUTF8(aInput));
}
return url.forget();
}
@ -198,7 +212,7 @@ void GetRequestURLFromWorker(const GlobalObject& aGlobal,
url->GetPassword(password);
if (!username.IsEmpty() || !password.IsEmpty()) {
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(aInput);
aRv.ThrowTypeError<MSG_URL_HAS_CREDENTIALS>(NS_ConvertUTF16toUTF8(aInput));
return;
}
@ -352,7 +366,8 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
uri = ParseURLFromChrome(referrer, aRv);
}
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(
NS_ConvertUTF16toUTF8(referrer));
return nullptr;
}
nsAutoCString spec;
@ -372,7 +387,8 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
} else {
RefPtr<URL> url = ParseURLFromWorker(aGlobal, referrer, aRv);
if (NS_WARN_IF(aRv.Failed())) {
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(referrer);
aRv.ThrowTypeError<MSG_INVALID_REFERRER_URL>(
NS_ConvertUTF16toUTF8(referrer));
return nullptr;
}
url->GetHref(referrerURL);
@ -449,8 +465,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
if (cache != RequestCache::EndGuard_) {
if (cache == RequestCache::Only_if_cached &&
request->Mode() != RequestMode::Same_origin) {
NS_ConvertASCIItoUTF16 modeString(
RequestModeValues::GetString(request->Mode()));
nsCString modeString(RequestModeValues::GetString(request->Mode()));
aRv.ThrowTypeError<MSG_ONLY_IF_CACHED_WITHOUT_SAME_ORIGIN>(modeString);
return nullptr;
}
@ -479,8 +494,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
nsAutoCString outMethod;
nsresult rv = FetchUtil::GetValidRequestMethod(method, outMethod);
if (NS_FAILED(rv)) {
NS_ConvertUTF8toUTF16 label(method);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(label);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(method);
return nullptr;
}
@ -512,8 +526,7 @@ already_AddRefed<Request> Request::Constructor(const GlobalObject& aGlobal,
if (!request->HasSimpleMethod()) {
nsAutoCString method;
request->GetMethod(method);
NS_ConvertUTF8toUTF16 label(method);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(label);
aRv.ThrowTypeError<MSG_INVALID_REQUEST_METHOD>(method);
return nullptr;
}

Просмотреть файл

@ -103,18 +103,24 @@ already_AddRefed<Response> Response::Redirect(const GlobalObject& aGlobal,
if (doc) {
baseURI = doc->GetBaseURI();
}
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString url;
if (!AppendUTF16toUTF8(aUrl, url, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> resolvedURI;
nsresult rv =
NS_NewURI(getter_AddRefs(resolvedURI), aUrl, nullptr, baseURI);
nsresult rv = NS_NewURI(getter_AddRefs(resolvedURI), url, nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
aRv.ThrowTypeError<MSG_INVALID_URL>(url);
return nullptr;
}
nsAutoCString spec;
rv = resolvedURI->GetSpec(spec);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aUrl);
aRv.ThrowTypeError<MSG_INVALID_URL>(url);
return nullptr;
}

Просмотреть файл

@ -1799,9 +1799,8 @@ already_AddRefed<MediaRecorder> MediaRecorder::Constructor(
// Allow recording from audio node only when pref is on.
if (!Preferences::GetBool("media.recorder.audio_node.enabled", false)) {
// Pretending that this constructor is not defined.
NS_NAMED_LITERAL_STRING(argStr, "Argument 1");
NS_NAMED_LITERAL_STRING(typeStr, "MediaStream");
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>(argStr, typeStr);
aRv.ThrowTypeError<MSG_DOES_NOT_IMPLEMENT_INTERFACE>("Argument 1",
"MediaStream");
return nullptr;
}

Просмотреть файл

@ -264,7 +264,7 @@ void ChromiumCDMParent::GetStatusForPolicy(uint32_t aPromiseId,
// TypeError for invalid args, as usual.
NS_NAMED_LITERAL_CSTRING(
err, "getStatusForPolicy failed due to bad hdcp version argument");
rv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
rv.ThrowTypeError(err);
RejectPromise(aPromiseId, std::move(rv), err);
return;
}
@ -497,7 +497,7 @@ static ErrorResult ToErrorResult(uint32_t aException,
rv.ThrowInvalidStateError(aErrorMessage);
break;
case cdm::Exception::kExceptionTypeError:
rv.ThrowTypeError(NS_ConvertUTF8toUTF16(aErrorMessage));
rv.ThrowTypeError(aErrorMessage);
break;
case cdm::Exception::kExceptionQuotaExceededError:
rv.ThrowQuotaExceededError(aErrorMessage);

Просмотреть файл

@ -172,7 +172,7 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo(
// parameters.
if (videoTracks.Length() != 1) {
promise->MaybeRejectWithTypeError<MSG_NO_CODECS_PARAMETER>(
NS_ConvertUTF8toUTF16(videoContainer->OriginalString()));
videoContainer->OriginalString());
return promise.forget();
}
MOZ_DIAGNOSTIC_ASSERT(videoTracks.ElementAt(0),
@ -188,7 +188,7 @@ already_AddRefed<Promise> MediaCapabilities::DecodingInfo(
// parameters.
if (audioTracks.Length() != 1) {
promise->MaybeRejectWithTypeError<MSG_NO_CODECS_PARAMETER>(
NS_ConvertUTF8toUTF16(audioContainer->OriginalString()));
audioContainer->OriginalString());
return promise.forget();
}
MOZ_DIAGNOSTIC_ASSERT(audioTracks.ElementAt(0),

Просмотреть файл

@ -143,7 +143,7 @@ void MediaMetadata::SetArtworkInternal(const Sequence<MediaImage>& aArtwork,
for (MediaImage& image : artwork) {
nsresult rv = ResolveURL(image.mSrc, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(image.mSrc);
aRv.ThrowTypeError<MSG_INVALID_URL>(NS_ConvertUTF16toUTF8(image.mSrc));
return;
}
}

Просмотреть файл

@ -215,7 +215,7 @@ void MediaSource::SetDuration(double aDuration, ErrorResult& aRv) {
MSE_API("SetDuration(aDuration=%f, ErrorResult)", aDuration);
if (aDuration < 0 || IsNaN(aDuration)) {
nsPrintfCString error("Invalid duration value %f", aDuration);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(error));
aRv.ThrowTypeError(error);
return;
}
if (mReadyState != MediaSourceReadyState::Open ||

Просмотреть файл

@ -2147,7 +2147,7 @@ already_AddRefed<Promise> Notification::ShowPersistentNotification(
if (NS_WARN_IF(NS_FAILED(loadChecker->Result()))) {
if (loadChecker->Result() == NS_ERROR_NOT_AVAILABLE) {
aRv.ThrowTypeError<MSG_NO_ACTIVE_WORKER>(aScope);
aRv.ThrowTypeError<MSG_NO_ACTIVE_WORKER>(NS_ConvertUTF16toUTF8(aScope));
} else {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
}

Просмотреть файл

@ -108,11 +108,11 @@ void PaymentRequest::IsValidStandardizedPMI(const nsAString& aIdentifier,
while (start != end) {
// the first char must be in the range %x61-7A
if ((*start < 'a' || *start > 'z')) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. The character '");
error.Append(*start);
error.Append(NS_ConvertUTF16toUTF8(start, 1));
error.AppendLiteral(
"' at the beginning or after the '-' must be in the range [a-z].");
aRv.ThrowRangeError(error);
@ -127,11 +127,11 @@ void PaymentRequest::IsValidStandardizedPMI(const nsAString& aIdentifier,
}
// if the char is not in the range %x61-7A + DIGITs, it must be '-'
if (start != end && *start != '-') {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. The character '");
error.Append(*start);
error.Append(NS_ConvertUTF16toUTF8(start, 1));
error.AppendLiteral("' must be in the range [a-zA-z0-9-].");
aRv.ThrowRangeError(error);
return;
@ -140,11 +140,11 @@ void PaymentRequest::IsValidStandardizedPMI(const nsAString& aIdentifier,
++start;
// the last char can not be '-'
if (start == end) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. The last character '");
error.Append(*start);
error.Append(NS_ConvertUTF16toUTF8(start, 1));
error.AppendLiteral("' must be in the range [a-z0-9].");
aRv.ThrowRangeError(error);
return;
@ -177,9 +177,9 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
urlParser->ParseURL(url.get(), url.Length(), &schemePos, &schemeLen,
&authorityPos, &authorityLen, nullptr, nullptr);
if (NS_FAILED(rv)) {
nsAutoString error;
nsAutoCString error;
error.AppendLiteral("Error parsing payment method identifier '");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("'as a URL.");
aRv.ThrowRangeError(error);
return;
@ -191,17 +191,17 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
return;
}
if (!Substring(aIdentifier, schemePos, schemeLen).EqualsASCII("https")) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. The scheme must be 'https'.");
aRv.ThrowRangeError(error);
return;
}
if (Substring(aIdentifier, authorityPos, authorityLen).IsEmpty()) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. hostname can not be empty.");
aRv.ThrowRangeError(error);
return;
@ -251,9 +251,9 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
// not exist.
if ((usernameLen <= 0) && (passwordLen <= 0)) {
if (authority.Length() - atPos - 1 == 0) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. hostname can not be empty.");
aRv.ThrowRangeError(error);
return;
@ -267,9 +267,9 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
if (NS_FAILED(rv)) {
// ParseServerInfo returns NS_ERROR_MALFORMED_URI in all fail cases, we
// probably need a followup bug to figure out the fail reason.
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("Error extracting hostname from '");
error.Append(NS_ConvertUTF8toUTF16(serverInfo));
error.Append(serverInfo);
error.AppendLiteral("'.");
aRv.ThrowRangeError(error);
return;
@ -278,9 +278,9 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
}
// PMI is valid when usernameLen/passwordLen equals to -1 or 0.
if (usernameLen > 0 || passwordLen > 0) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AssignLiteral("' is not valid. Username and password must be empty.");
aRv.ThrowRangeError(error);
return;
@ -288,9 +288,9 @@ void PaymentRequest::IsValidPaymentMethodIdentifier(
// PMI is valid when hostnameLen is larger than 0
if (hostnameLen <= 0) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("'");
error.Append(aIdentifier);
error.Append(NS_ConvertUTF16toUTF8(aIdentifier));
error.AppendLiteral("' is not valid. hostname can not be empty.");
aRv.ThrowRangeError(error);
return;
@ -321,7 +321,7 @@ void PaymentRequest::IsValidMethodData(
nsAutoString error;
if (!service->IsValidBasicCardRequest(aCx, methodData.mData.Value(),
error)) {
aRv.ThrowTypeError(error);
aRv.ThrowTypeError(NS_ConvertUTF16toUTF8(error));
return;
}
}
@ -353,11 +353,11 @@ void PaymentRequest::IsValidNumber(const nsAString& aItem,
}
if (NS_FAILED(error)) {
nsAutoString errorMsg;
nsAutoCString errorMsg;
errorMsg.AssignLiteral("The amount.value of \"");
errorMsg.Append(aItem);
errorMsg.Append(NS_ConvertUTF16toUTF8(aItem));
errorMsg.AppendLiteral("\"(");
errorMsg.Append(aStr);
errorMsg.Append(NS_ConvertUTF16toUTF8(aStr));
errorMsg.AppendLiteral(") must be a valid decimal monetary value.");
aRv.ThrowTypeError(errorMsg);
return;
@ -381,11 +381,11 @@ void PaymentRequest::IsNonNegativeNumber(const nsAString& aItem,
}
if (NS_FAILED(error)) {
nsAutoString errorMsg;
nsAutoCString errorMsg;
errorMsg.AssignLiteral("The amount.value of \"");
errorMsg.Append(aItem);
errorMsg.Append(NS_ConvertUTF16toUTF8(aItem));
errorMsg.AppendLiteral("\"(");
errorMsg.Append(aStr);
errorMsg.Append(NS_ConvertUTF16toUTF8(aStr));
errorMsg.AppendLiteral(
") must be a valid and non-negative decimal monetary value.");
aRv.ThrowTypeError(errorMsg);
@ -405,11 +405,11 @@ void PaymentRequest::IsValidCurrency(const nsAString& aItem,
* "Z" (U+0041 to U+005A) or the range "a" to "z" (U+0061 to U+007A)
*/
if (aCurrency.Length() != 3) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("The length amount.currency of \"");
error.Append(aItem);
error.Append(NS_ConvertUTF16toUTF8(aItem));
error.AppendLiteral("\"(");
error.Append(aCurrency);
error.Append(NS_ConvertUTF16toUTF8(aCurrency));
error.AppendLiteral(") must be 3.");
aRv.ThrowRangeError(error);
return;
@ -421,11 +421,11 @@ void PaymentRequest::IsValidCurrency(const nsAString& aItem,
(aCurrency.CharAt(idx) >= 'a' && aCurrency.CharAt(idx) <= 'z')) {
continue;
}
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("The character amount.currency of \"");
error.Append(aItem);
error.Append(NS_ConvertUTF16toUTF8(aItem));
error.AppendLiteral("\"(");
error.Append(aCurrency);
error.Append(NS_ConvertUTF16toUTF8(aCurrency));
error.AppendLiteral(
") must be in the range 'A' to 'Z'(U+0041 to U+005A) or 'a' to "
"'z'(U+0061 to U+007A).");
@ -515,9 +515,9 @@ void PaymentRequest::IsValidDetailsBase(const PaymentDetailsBase& aDetails,
return;
}
if (seenIDs.Contains(shippingOption.mId)) {
nsAutoString error;
nsAutoCString error;
error.AssignLiteral("Duplicate shippingOption id '");
error.Append(shippingOption.mId);
error.Append(NS_ConvertUTF16toUTF8(shippingOption.mId));
error.AppendLiteral("'");
aRv.ThrowTypeError(error);
return;

Просмотреть файл

@ -244,11 +244,18 @@ already_AddRefed<Promise> ServiceWorkerContainer::Register(
return nullptr;
}
nsresult rv;
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString scriptURL;
if (!AppendUTF16toUTF8(aScriptURL, scriptURL, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> scriptURI;
rv = NS_NewURI(getter_AddRefs(scriptURI), aScriptURL, nullptr, baseURI);
nsresult rv =
NS_NewURI(getter_AddRefs(scriptURI), scriptURL, nullptr, baseURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aScriptURL);
aRv.ThrowTypeError<MSG_INVALID_URL>(scriptURL);
return nullptr;
}
@ -258,13 +265,12 @@ already_AddRefed<Promise> ServiceWorkerContainer::Register(
// Step 4. If none passed, parse against script's URL
if (!aOptions.mScope.WasPassed()) {
NS_NAMED_LITERAL_STRING(defaultScope, "./");
NS_NAMED_LITERAL_CSTRING(defaultScope, "./");
rv = NS_NewURI(getter_AddRefs(scopeURI), defaultScope, nullptr, scriptURI);
if (NS_WARN_IF(NS_FAILED(rv))) {
nsAutoCString spec;
scriptURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 wSpec(spec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(defaultScope, wSpec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(defaultScope, spec);
return nullptr;
}
} else {
@ -275,8 +281,8 @@ already_AddRefed<Promise> ServiceWorkerContainer::Register(
nsIURI* uri = baseURI ? baseURI : scriptURI;
nsAutoCString spec;
uri->GetSpec(spec);
NS_ConvertUTF8toUTF16 wSpec(spec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(aOptions.mScope.Value(), wSpec);
aRv.ThrowTypeError<MSG_INVALID_SCOPE>(
NS_ConvertUTF16toUTF8(aOptions.mScope.Value()), spec);
return nullptr;
}
}

Просмотреть файл

@ -182,15 +182,12 @@ void ServiceWorkerJob::Finish(ErrorResult& aRv) {
// Remove the old error code so we can replace it with a TypeError.
aRv.SuppressException();
NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec);
NS_ConvertUTF8toUTF16 scope(mScope);
// Throw the type error with a generic error message. We use a stack
// reference to bypass the normal static analysis for "return right after
// throwing", since it's not the right check here: this ErrorResult came in
// pre-thrown.
ErrorResult& rv = aRv;
rv.ThrowTypeError<MSG_SW_INSTALL_ERROR>(scriptSpec, scope);
rv.ThrowTypeError<MSG_SW_INSTALL_ERROR>(mScriptSpec, mScope);
}
// The final callback may drop the last ref to this object.

Просмотреть файл

@ -2523,8 +2523,7 @@ void ServiceWorkerManager::UpdateInternal(
GetRegistration(scopeKey, aScope);
if (NS_WARN_IF(!registration)) {
ErrorResult error;
error.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
NS_ConvertUTF8toUTF16(aScope), "uninstalled");
error.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(aScope, "uninstalled");
aCallback->UpdateFailed(error);
// In case the callback does not consume the exception

Просмотреть файл

@ -332,16 +332,16 @@ already_AddRefed<Promise> ServiceWorkerRegistration::ShowNotification(
return nullptr;
}
NS_ConvertUTF8toUTF16 scope(mDescriptor.Scope());
// Until we ship ServiceWorker objects on worker threads the active
// worker will always be nullptr. So limit this check to main
// thread for now.
if (mDescriptor.GetActive().isNothing() && NS_IsMainThread()) {
aRv.ThrowTypeError<MSG_NO_ACTIVE_WORKER>(scope);
aRv.ThrowTypeError<MSG_NO_ACTIVE_WORKER>(mDescriptor.Scope());
return nullptr;
}
NS_ConvertUTF8toUTF16 scope(mDescriptor.Scope());
RefPtr<Promise> p = Notification::ShowPersistentNotification(
aCx, global, scope, aTitle, aOptions, mDescriptor, aRv);
if (NS_WARN_IF(aRv.Failed())) {

Просмотреть файл

@ -231,8 +231,7 @@ void ServiceWorkerUpdateJob::AsyncExecute() {
if (!registration) {
ErrorResult rv;
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
NS_ConvertUTF8toUTF16(mScope), "uninstalled");
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(mScope, "uninstalled");
FailUpdateJob(rv);
return;
}
@ -247,8 +246,7 @@ void ServiceWorkerUpdateJob::AsyncExecute() {
// 2. Invoke Finish Job with job and abort these steps."
if (newest && !newest->ScriptSpec().Equals(mScriptSpec)) {
ErrorResult rv;
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(
NS_ConvertUTF8toUTF16(mScope), "changed");
rv.ThrowTypeError<MSG_SW_UPDATE_BAD_REGISTRATION>(mScope, "changed");
FailUpdateJob(rv);
return;
}
@ -455,10 +453,8 @@ void ServiceWorkerUpdateJob::ContinueUpdateAfterScriptEval(
if (NS_WARN_IF(!aScriptEvaluationResult)) {
ErrorResult error;
NS_ConvertUTF8toUTF16 scriptSpec(mScriptSpec);
NS_ConvertUTF8toUTF16 scope(mRegistration->Scope());
error.ThrowTypeError<MSG_SW_SCRIPT_THREW>(scriptSpec, scope);
error.ThrowTypeError<MSG_SW_SCRIPT_THREW>(mScriptSpec,
mRegistration->Scope());
FailUpdateJob(error);
return;
}

Просмотреть файл

@ -59,7 +59,7 @@ void CheckForSlashEscapedCharsInPath(nsIURI* aURI, const char* aURLDescription,
ToLowerCase(path);
if (path.Find("%2f") != kNotFound || path.Find("%5c") != kNotFound) {
nsPrintfCString err("%s contains %%2f or %%5c", aURLDescription);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
}
}

Просмотреть файл

@ -360,7 +360,7 @@ void SVGAnimatedOrient::SetBaseType(SVGEnumValue aValue,
return;
}
nsPrintfCString err("Invalid base value %u for marker orient", aValue);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
}
void SVGAnimatedOrient::SetAnimValue(float aValue, uint8_t aUnit,

Просмотреть файл

@ -50,10 +50,17 @@ already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
const nsAString& aURL,
const nsAString& aBase,
ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString base;
if (!AppendUTF16toUTF8(aBase, base, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> baseUri;
nsresult rv = NS_NewURI(getter_AddRefs(baseUri), aBase);
nsresult rv = NS_NewURI(getter_AddRefs(baseUri), base);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aBase);
aRv.ThrowTypeError<MSG_INVALID_URL>(base);
return nullptr;
}
@ -64,12 +71,19 @@ already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
already_AddRefed<URL> URL::Constructor(nsISupports* aParent,
const nsAString& aURL, nsIURI* aBase,
ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString urlStr;
if (!AppendUTF16toUTF8(aURL, urlStr, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, nullptr, aBase);
nsresult rv = NS_NewURI(getter_AddRefs(uri), urlStr, nullptr, aBase);
if (NS_FAILED(rv)) {
// No need to warn in this case. It's common to use the URL constructor
// to determine if a URL is valid and an exception will be propagated.
aRv.ThrowTypeError<MSG_INVALID_URL>(aURL);
aRv.ThrowTypeError<MSG_INVALID_URL>(urlStr);
return nullptr;
}
@ -156,10 +170,17 @@ void URL::URLSearchParamsUpdated(URLSearchParams* aSearchParams) {
void URL::GetHref(nsAString& aHref) const { URL_GETTER(aHref, GetSpec); }
void URL::SetHref(const nsAString& aHref, ErrorResult& aRv) {
// Don't use NS_ConvertUTF16toUTF8 because that doesn't let us handle OOM.
nsAutoCString href;
if (!AppendUTF16toUTF8(aHref, href, fallible)) {
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
nsresult rv = NS_NewURI(getter_AddRefs(uri), href);
if (NS_FAILED(rv)) {
aRv.ThrowTypeError<MSG_INVALID_URL>(aHref);
aRv.ThrowTypeError<MSG_INVALID_URL>(href);
return;
}

Просмотреть файл

@ -344,7 +344,7 @@ already_AddRefed<URLSearchParams> URLSearchParams::Constructor(
if (item.Length() != 2) {
nsPrintfCString err("Expected 2 items in pair but got %zu",
item.Length());
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
return nullptr;
}
sp->Append(item[0], item[1]);

Просмотреть файл

@ -3089,7 +3089,7 @@ void DataChannel::SendErrnoToErrorResult(int error, size_t aMessageSize,
case EMSGSIZE: {
nsPrintfCString err("Message size (%zu) exceeds maxMessageSize",
aMessageSize);
aRv.ThrowTypeError(NS_ConvertUTF8toUTF16(err));
aRv.ThrowTypeError(err);
break;
}
default: