Bug 1612213 part 1. Switch most consumers of ThrowDOMException to the new methods. r=smaug,jgilbert

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-02-03 20:19:11 +00:00
parent 59a2e7a58b
commit b88d5ac5a8
40 changed files with 180 additions and 275 deletions

View File

@ -742,8 +742,7 @@ void CustomElementRegistry::Define(
Document* doc = mWindow->GetExtantDoc();
RefPtr<nsAtom> nameAtom(NS_Atomize(aName));
if (!nsContentUtils::IsCustomElementName(nameAtom, nameSpaceID)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_SYNTAX_ERR,
aRv.ThrowSyntaxError(
nsPrintfCString("'%s' is not a valid custom element name",
NS_ConvertUTF16toUTF8(aName).get()));
return;
@ -754,8 +753,7 @@ void CustomElementRegistry::Define(
* throw a "NotSupportedError" DOMException and abort these steps.
*/
if (mCustomDefinitions.GetWeak(nameAtom)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
nsPrintfCString("'%s' has already been defined as a custom element",
NS_ConvertUTF16toUTF8(aName).get()));
return;
@ -772,8 +770,7 @@ void CustomElementRegistry::Define(
"Definition must be found in mCustomDefinitions");
nsAutoCString name;
ptr->value()->ToUTF8String(name);
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
nsPrintfCString("'%s' and '%s' have the same constructor",
NS_ConvertUTF16toUTF8(aName).get(), name.get()));
return;
@ -807,8 +804,7 @@ void CustomElementRegistry::Define(
if (aOptions.mExtends.WasPassed()) {
RefPtr<nsAtom> extendsAtom(NS_Atomize(aOptions.mExtends.Value()));
if (nsContentUtils::IsCustomElementName(extendsAtom, kNameSpaceID_XHTML)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
nsPrintfCString("'%s' cannot extend a custom element",
NS_ConvertUTF16toUTF8(aName).get()));
return;
@ -839,8 +835,7 @@ void CustomElementRegistry::Define(
* set, then throw a "NotSupportedError" DOMException and abort these steps.
*/
if (mIsCustomDefinitionRunning) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Cannot define a custom element while defining another custom element");
return;
}
@ -1101,12 +1096,10 @@ static void DoUpgrade(Element* aElement, CustomElementDefinition* aDefinition,
CustomElementConstructor* aConstructor,
ErrorResult& aRv) {
if (aDefinition->mDisableShadow && aElement->GetShadowRoot()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"Custom element upgrade to '%s' is disabled due to shadow root "
"already exists",
NS_ConvertUTF16toUTF8(aDefinition->mType->GetUTF16String()).get()));
aRv.ThrowNotSupportedError(nsPrintfCString(
"Custom element upgrade to '%s' is disabled due to shadow root "
"already exists",
NS_ConvertUTF16toUTF8(aDefinition->mType->GetUTF16String()).get()));
return;
}

View File

@ -504,8 +504,7 @@ void DOMMatrixReadOnly::Stringify(nsAString& aResult, ErrorResult& aRv) {
auto AppendDouble = [&aRv, &cbuf, &matrixStr](double d,
bool isLastItem = false) {
if (!mozilla::IsFinite(d)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
aRv.ThrowInvalidStateError(
"Matrix with a non-finite element cannot be stringified.");
return false;
}

View File

@ -101,16 +101,14 @@ void DocumentOrShadowRoot::SetAdoptedStyleSheets(
for (const OwningNonNull<StyleSheet>& sheet : aAdoptedStyleSheets) {
// 2.1 Check if all sheets are constructed, else throw NotAllowedError
if (!sheet->IsConstructed()) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
"Each adopted style sheet must be created through the "
"Constructable StyleSheets API");
return aRv.ThrowNotAllowedError(
"Each adopted style sheet must be created through the Constructable "
"StyleSheets API");
}
// 2.2 Check if all sheets' constructor documents match the
// DocumentOrShadowRoot's node document, else throw NotAlloweError
if (!sheet->ConstructorDocumentMatches(AsNode().OwnerDoc())) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
return aRv.ThrowNotAllowedError(
"Each adopted style sheet's constructor document must match the "
"document or shadow root's node document");
}

View File

@ -847,14 +847,14 @@ void Navigator::CheckProtocolHandlerAllowed(const nsAString& aScheme,
aHandlerURI->GetSpec(spec);
nsPrintfCString message("Permission denied to add %s as a protocol handler",
spec.get());
aRv.ThrowDOMException(NS_ERROR_DOM_SECURITY_ERR, message);
aRv.ThrowSecurityError(message);
};
auto raisePermissionDeniedScheme = [&] {
nsPrintfCString message(
"Permission denied to add a protocol handler for %s",
NS_ConvertUTF16toUTF8(aScheme).get());
aRv.ThrowDOMException(NS_ERROR_DOM_SECURITY_ERR, message);
aRv.ThrowSecurityError(message);
};
if (!aDocumentURI || !aHandlerURI) {
@ -867,8 +867,7 @@ void Navigator::CheckProtocolHandlerAllowed(const nsAString& aScheme,
// If the uri doesn't contain '%s', it won't be a good handler - the %s
// gets replaced with the handled URI.
if (!FindInReadable(NS_LITERAL_CSTRING("%s"), spec)) {
aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
"Handler URI does not contain \"%s\".");
aRv.ThrowSyntaxError("Handler URI does not contain \"%s\".");
return;
}

View File

@ -2735,10 +2735,9 @@ const RawServoSelectorList* nsINode::ParseSelectorList(
if (list) {
if (!*list) {
// Invalid selector.
aRv.ThrowDOMException(
NS_ERROR_DOM_SYNTAX_ERR,
NS_LITERAL_CSTRING("'") + NS_ConvertUTF16toUTF8(aSelectorString) +
NS_LITERAL_CSTRING("' is not a valid selector"));
aRv.ThrowSyntaxError(NS_LITERAL_CSTRING("'") +
NS_ConvertUTF16toUTF8(aSelectorString) +
NS_LITERAL_CSTRING("' is not a valid selector"));
return nullptr;
}
@ -2756,9 +2755,8 @@ const RawServoSelectorList* nsINode::ParseSelectorList(
// Now make sure we throw an exception if the selector was invalid.
if (!ret) {
aRv.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR,
NS_LITERAL_CSTRING("'") + selectorString +
NS_LITERAL_CSTRING("' is not a valid selector"));
aRv.ThrowSyntaxError(NS_LITERAL_CSTRING("'") + selectorString +
NS_LITERAL_CSTRING("' is not a valid selector"));
}
return ret;

View File

@ -214,8 +214,8 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
JSObject* wrappedCallback = aCallback->CallbackPreserveColor();
if (!wrappedCallback) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Cannot execute callback from a nuked compartment.");
aRv.ThrowNotSupportedError(
"Cannot execute callback from a nuked compartment.");
return;
}
@ -231,8 +231,7 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// Make sure to use realCallback to get the global of the callback
// object, not the wrapper.
if (!xpc::Scriptability::Get(realCallback).Allowed()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Refusing to execute function from global in which script is "
"disabled.");
return;
@ -248,8 +247,7 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// We don't want to run script in windows that have been navigated away
// from.
if (!win->HasActiveDocument()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Refusing to execute function from window whose document is no "
"longer active.");
return;
@ -264,8 +262,7 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// Bail out if there's no useful global.
if (!globalObject->HasJSGlobal()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Refusing to execute function from global which is being torn down.");
return;
}
@ -280,8 +277,7 @@ CallbackObject::CallSetup::CallSetup(CallbackObject* aCallback,
// nsIGlobalObject has severed its reference to the JS global. Let's just
// be safe here, so that nobody has to waste a day debugging gaia-ui tests.
if (!incumbent->HasJSGlobal()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Refusing to execute function because our incumbent global is being "
"torn down.");
return;

View File

@ -1828,9 +1828,9 @@ already_AddRefed<dom::Promise> ClientWebGLContext::MakeXRCompatible(
global = mOffscreenCanvas->GetOwnerGlobal();
}
if (!global) {
aRv.ThrowDOMException(NS_ERROR_DOM_INVALID_ACCESS_ERR,
"Using a WebGL context that is not attached to "
"either a canvas or an OffscreenCanvas");
aRv.ThrowInvalidAccessError(
"Using a WebGL context that is not attached to either a canvas or an "
"OffscreenCanvas");
return nullptr;
}
RefPtr<dom::Promise> promise = dom::Promise::Create(global, aRv);

View File

@ -269,8 +269,7 @@ already_AddRefed<Promise> Clients::Claim(ErrorResult& aRv) {
if (serviceWorker.State() != ServiceWorkerState::Activating &&
serviceWorker.State() != ServiceWorkerState::Activated) {
aRv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Service worker is not active in Clients.claim");
aRv.ThrowInvalidStateError("Service worker is not active in Clients.claim");
return outerPromise.forget();
}

View File

@ -55,8 +55,7 @@ void ClientHandle::StartOp(const ClientOpConstructorArgs& aArgs,
[aRejectCallback] {
MOZ_DIAGNOSTIC_ASSERT(aRejectCallback);
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Client has been destroyed");
rv.ThrowInvalidStateError("Client has been destroyed");
aRejectCallback(rv);
});
}
@ -146,8 +145,7 @@ RefPtr<GenericErrorResultPromise> ClientHandle::PostMessage(
StructuredCloneData& aData, const ServiceWorkerDescriptor& aSource) {
if (IsShutdown()) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Client has been destroyed");
rv.ThrowInvalidStateError("Client has been destroyed");
return GenericErrorResultPromise::CreateAndReject(rv, __func__);
}
@ -157,8 +155,7 @@ RefPtr<GenericErrorResultPromise> ClientHandle::PostMessage(
if (!aData.BuildClonedMessageDataForBackgroundChild(
GetActor()->Manager()->Manager(), args.clonedData())) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Failed to clone data");
rv.ThrowInvalidStateError("Failed to clone data");
return GenericErrorResultPromise::CreateAndReject(rv, __func__);
}

View File

@ -14,7 +14,7 @@ namespace dom {
void ClientHandleOpChild::ActorDestroy(ActorDestroyReason aReason) {
mClientHandle = nullptr;
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client load aborted");
rv.ThrowAbortError("Client load aborted");
mRejectCallback(rv);
}

View File

@ -50,8 +50,7 @@ void ClientHandleOpParent::Init(ClientOpConstructorArgs&& aArgs) {
if (!data.BuildClonedMessageDataForBackgroundParent(
source->Manager()->Manager(), rebuild.clonedData())) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR,
"Aborting client operation");
rv.ThrowAbortError("Aborting client operation");
Unused << PClientHandleOpParent::Send__delete__(this, rv);
return;
}

View File

@ -32,7 +32,7 @@ void ClientHandleParent::ActorDestroy(ActorDestroyReason aReason) {
if (mSourcePromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client aborted");
rv.ThrowAbortError("Client aborted");
mSourcePromise->Reject(rv, __func__);
}
}
@ -91,7 +91,7 @@ void ClientHandleParent::FoundSource(ClientSourceParent* aSource) {
mPrincipalInfo)) {
if (mSourcePromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client aborted");
rv.ThrowAbortError("Client aborted");
mSourcePromise->Reject(rv, __func__);
}
Unused << Send__delete__(this);

View File

@ -191,8 +191,7 @@ RefPtr<ClientOpPromise> ClientManager::StartOp(
},
[promise] {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Client has been destroyed");
rv.ThrowInvalidStateError("Client has been destroyed");
promise->Reject(rv, __func__);
});

View File

@ -16,7 +16,7 @@ void ClientManagerOpChild::ActorDestroy(ActorDestroyReason aReason) {
mClientManager = nullptr;
if (mPromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client aborted");
rv.ThrowAbortError("Client aborted");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
}

View File

@ -281,7 +281,7 @@ RefPtr<ClientOpPromise> ClientManagerService::Navigate(
FindSource(aArgs.target().id(), aArgs.target().principalInfo());
if (!source) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Unknown client");
rv.ThrowInvalidStateError("Unknown client");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -306,7 +306,7 @@ RefPtr<ClientOpPromise> ClientManagerService::Navigate(
manager->SendPClientNavigateOpConstructor(op, args);
if (!result) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Client is aborted");
rv.ThrowInvalidStateError("Client is aborted");
promise->Reject(rv, __func__);
}
@ -449,7 +449,7 @@ RefPtr<ClientOpPromise> ClaimOnMainThread(
"Service worker at <%s> can't claim Client at <%s>",
desc.ScriptURL().get(), clientInfo.URL().get());
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, err);
rv.ThrowInvalidStateError(err);
promise->Reject(rv, __func__);
});
@ -536,7 +536,7 @@ RefPtr<ClientOpPromise> ClientManagerService::GetInfoAndState(
if (!source) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Unknown client");
rv.ThrowInvalidStateError("Unknown client");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -552,8 +552,7 @@ RefPtr<ClientOpPromise> ClientManagerService::GetInfoAndState(
if (!source) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Unknown client");
rv.ThrowInvalidStateError("Unknown client");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -619,7 +618,7 @@ class OpenWindowRunnable final : public Runnable {
// promise if we could not.
if (!targetProcess) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Opening window aborted");
rv.ThrowAbortError("Opening window aborted");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
return NS_OK;

View File

@ -54,7 +54,7 @@ class NavigateLoadListener final : public nsIWebProgressListener,
if (!channel) {
// This is not going to happen; how could it?
CopyableErrorResult result;
result.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Bad request");
result.ThrowInvalidStateError("Bad request");
mPromise->Reject(result, __func__);
return NS_OK;
}
@ -166,15 +166,14 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
ClientSource* target = targetActor->GetSource();
if (!target) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Unknown Client");
rv.ThrowInvalidStateError("Unknown Client");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
window = target->GetInnerWindow();
if (!window) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Client load for a destroyed Window");
rv.ThrowInvalidStateError("Client load for a destroyed Window");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
}
@ -193,8 +192,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
// This is rather unexpected: This is the worker URL we passed from the
// parent, so we expect this to parse fine!
CopyableErrorResult result;
result.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Invalid worker URL");
result.ThrowInvalidStateError("Invalid worker URL");
return ClientOpPromise::CreateAndReject(result, __func__);
}
@ -233,8 +231,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
RefPtr<Document> doc = window->GetExtantDoc();
if (!doc || !doc->IsActive()) {
CopyableErrorResult result;
result.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Document is not active.");
result.ThrowInvalidStateError("Document is not active.");
return ClientOpPromise::CreateAndReject(result, __func__);
}
@ -244,8 +241,8 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
nsCOMPtr<nsIWebProgress> webProgress = do_GetInterface(docShell);
if (!docShell || !webProgress) {
CopyableErrorResult result;
result.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Document's browsing context has been discarded");
result.ThrowInvalidStateError(
"Document's browsing context has been discarded");
return ClientOpPromise::CreateAndReject(result, __func__);
}

View File

@ -14,7 +14,7 @@ using mozilla::ipc::IPCResult;
void ClientNavigateOpParent::ActorDestroy(ActorDestroyReason aReason) {
if (mPromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client aborted");
rv.ThrowAbortError("Client aborted");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
}

View File

@ -14,7 +14,7 @@ using mozilla::ipc::IPCResult;
void ClientOpenWindowOpParent::ActorDestroy(ActorDestroyReason aReason) {
if (mPromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client aborted");
rv.ThrowAbortError("Client aborted");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
}

View File

@ -64,8 +64,7 @@ class WebProgressListener final : public nsIWebProgressListener,
nsCOMPtr<Document> doc = mWindow->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Document is discarded");
rv.ThrowInvalidStateError("Document is discarded");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
return NS_OK;
@ -144,7 +143,7 @@ class WebProgressListener final : public nsIWebProgressListener,
~WebProgressListener() {
if (mPromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "openWindow aborted");
rv.ThrowAbortError("openWindow aborted");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
}
@ -299,7 +298,7 @@ void WaitForLoad(const ClientOpenWindowArgs& aArgs,
if (NS_WARN_IF(NS_FAILED(rv))) {
// Shouldn't really happen, since we passed in the serialization of a URI.
CopyableErrorResult result;
result.ThrowDOMException(NS_ERROR_DOM_SYNTAX_ERR, "Bad URL");
result.ThrowSyntaxError("Bad URL");
promise->Reject(result, __func__);
return;
}
@ -309,7 +308,7 @@ void WaitForLoad(const ClientOpenWindowArgs& aArgs,
if (NS_WARN_IF(!webProgress)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "No browsing context");
rv.ThrowInvalidStateError("No browsing context");
promise->Reject(rv, __func__);
return;
}

View File

@ -85,7 +85,7 @@ Result<ClientState, ErrorResult> ClientSource::SnapshotWindowState() {
Document* doc = window->GetExtantDoc();
ErrorResult rv;
if (NS_WARN_IF(!doc)) {
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Document not active");
rv.ThrowInvalidStateError("Document not active");
return Err(std::move(rv));
}
@ -446,8 +446,7 @@ RefPtr<ClientOpPromise> ClientSource::Control(
if (NS_WARN_IF(!controlAllowed)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Client cannot be controlled");
rv.ThrowInvalidStateError("Client cannot be controlled");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -534,7 +533,7 @@ RefPtr<ClientOpPromise> ClientSource::Focus(const ClientFocusArgs& aArgs) {
if (mClientInfo.Type() != ClientType::Window) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR, "Not a Window client");
rv.ThrowNotSupportedError("Not a Window client");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
nsPIDOMWindowOuter* outer = nullptr;
@ -551,8 +550,7 @@ RefPtr<ClientOpPromise> ClientSource::Focus(const ClientFocusArgs& aArgs) {
if (!outer) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Browsing context discarded");
rv.ThrowInvalidStateError("Browsing context discarded");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -583,8 +581,7 @@ RefPtr<ClientOpPromise> ClientSource::PostMessage(
}
CopyableErrorResult rv;
rv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
rv.ThrowNotSupportedError(
"postMessage to non-Window clients is not supported yet");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -598,8 +595,7 @@ RefPtr<ClientOpPromise> ClientSource::Claim(const ClientClaimArgs& aArgs) {
nsIGlobalObject* global = GetGlobal();
if (NS_WARN_IF(!global)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Browsing context torn down");
rv.ThrowInvalidStateError("Browsing context torn down");
return ClientOpPromise::CreateAndReject(rv, __func__);
}
@ -619,8 +615,7 @@ RefPtr<ClientOpPromise> ClientSource::Claim(const ClientClaimArgs& aArgs) {
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
if (NS_WARN_IF(!swm)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Browser shutting down");
rv.ThrowInvalidStateError("Browser shutting down");
innerPromise->Reject(rv, __func__);
return;
}
@ -682,7 +677,7 @@ Result<ClientState, ErrorResult> ClientSource::SnapshotState() {
WorkerPrivate* workerPrivate = GetWorkerPrivate();
if (!workerPrivate) {
ErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR, "Worker terminated");
rv.ThrowInvalidStateError("Worker terminated");
return Err(std::move(rv));
}

View File

@ -31,7 +31,7 @@ void ClientSourceOpChild::DoSourceOp(Method aMethod, const Args& aArgs) {
ClientSource* source = GetSource();
if (!source) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Unknown Client");
rv.ThrowAbortError("Unknown Client");
Unused << PClientSourceOpChild::Send__delete__(this, rv);
return;
}

View File

@ -16,7 +16,7 @@ using mozilla::ipc::IPCResult;
void ClientSourceOpParent::ActorDestroy(ActorDestroyReason aReason) {
if (mPromise) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_ABORT_ERR, "Client torn down");
rv.ThrowAbortError("Client torn down");
mPromise->Reject(rv, __func__);
mPromise = nullptr;
}

View File

@ -2803,12 +2803,10 @@ already_AddRefed<ElementInternals> nsGenericHTMLElement::AttachInternals(
nsAtom* isAtom = ceData ? ceData->GetIs(this) : nullptr;
nsAtom* nameAtom = NodeInfo()->NameAtom();
if (isAtom) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"Cannot attach ElementInternals to a customized built-in element "
"'%s'",
NS_ConvertUTF16toUTF8(isAtom->GetUTF16String()).get()));
aRv.ThrowNotSupportedError(nsPrintfCString(
"Cannot attach ElementInternals to a customized built-in element "
"'%s'",
NS_ConvertUTF16toUTF8(isAtom->GetUTF16String()).get()));
return nullptr;
}
@ -2830,33 +2828,27 @@ already_AddRefed<ElementInternals> nsGenericHTMLElement::AttachInternals(
// 3. If definition is null, then throw an "NotSupportedError" DOMException.
if (!definition) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"Cannot attach ElementInternals to a non-custom element '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
aRv.ThrowNotSupportedError(nsPrintfCString(
"Cannot attach ElementInternals to a non-custom element '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
return nullptr;
}
// 4. If definition's disable internals is true, then throw a
// "NotSupportedError" DOMException.
if (definition->mDisableInternals) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"AttachInternal() to '%s' is disabled by disabledFeatures",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
aRv.ThrowNotSupportedError(nsPrintfCString(
"AttachInternal() to '%s' is disabled by disabledFeatures",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
return nullptr;
}
// 5. If element's attached internals is true, then throw an
// "NotSupportedError" DOMException.
if (ceData->HasAttachedInternals()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"AttachInternals() has already been called from '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
aRv.ThrowNotSupportedError(nsPrintfCString(
"AttachInternals() has already been called from '%s'",
NS_ConvertUTF16toUTF8(nameAtom->GetUTF16String()).get()));
return nullptr;
}

View File

@ -379,11 +379,9 @@ RefPtr<IDBObjectStore> IDBDatabase::CreateObjectStore(
return aName == objectStore.metadata().name();
});
if (foundIt != end) {
aRv.ThrowDOMException(
NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR,
nsPrintfCString("Object store named '%s' already exists at index '%zu'",
NS_ConvertUTF16toUTF8(aName).get(),
foundIt.GetIndex()));
aRv.ThrowConstraintError(nsPrintfCString(
"Object store named '%s' already exists at index '%zu'",
NS_ConvertUTF16toUTF8(aName).get(), foundIt.GetIndex()));
return nullptr;
}

View File

@ -1551,10 +1551,10 @@ RefPtr<IDBRequest> IDBObjectStore::AddOrPut(JSContext* aCx,
if (messageSize > kMaxMessageSize) {
IDB_REPORT_INTERNAL_ERR();
aRv.ThrowDOMException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR,
nsPrintfCString("The serialized value is too large"
" (size=%zu bytes, max=%zu bytes).",
messageSize, kMaxMessageSize));
aRv.ThrowUnknownError(
nsPrintfCString("The serialized value is too large"
" (size=%zu bytes, max=%zu bytes).",
messageSize, kMaxMessageSize));
return nullptr;
}
@ -2142,11 +2142,9 @@ RefPtr<IDBIndex> IDBObjectStore::CreateIndex(
indexes.cbegin(), end,
[&aName](const auto& index) { return aName == index.name(); });
if (foundIt != end) {
aRv.ThrowDOMException(
NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR,
nsPrintfCString("Index named '%s' already exists at index '%zu'",
NS_ConvertUTF16toUTF8(aName).get(),
foundIt.GetIndex()));
aRv.ThrowConstraintError(nsPrintfCString(
"Index named '%s' already exists at index '%zu'",
NS_ConvertUTF16toUTF8(aName).get(), foundIt.GetIndex()));
return nullptr;
}

View File

@ -873,9 +873,7 @@ RefPtr<IDBObjectStore> IDBTransaction::ObjectStore(const nsAString& aName,
AssertIsOnOwningThread();
if (IsCommittingOrFinished()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("Transaction is already committing or done."));
aRv.ThrowInvalidStateError("Transaction is already committing or done.");
return nullptr;
}

View File

@ -84,8 +84,7 @@ void ClonedErrorHolder::Init(JSContext* aCx, JS::Handle<JSObject*> aError,
} else if (NS_SUCCEEDED(UNWRAP_OBJECT(Exception, aError, exn))) {
mType = Type::Exception;
} else {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"We can only clone DOM Exceptions and native JS Error objects");
return;
}

View File

@ -119,10 +119,9 @@ JSWindowActorProtocol::FromWebIDLOptions(const nsAString& aName,
}
if (!aOptions.mChild.WasPassed() && !aOptions.mParent.WasPassed()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("No point registering an actor with neither child "
"nor parent specifications."));
aRv.ThrowNotSupportedError(
"No point registering an actor with neither child nor parent "
"specifications.");
return nullptr;
}
@ -377,9 +376,9 @@ void JSWindowActorService::RegisterWindowActor(
auto entry = mDescriptors.LookupForAdd(aName);
if (entry) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString("'%s' actor is already registered.",
NS_ConvertUTF16toUTF8(aName).get()));
aRv.ThrowNotSupportedError(
nsPrintfCString("'%s' actor is already registered.",
NS_ConvertUTF16toUTF8(aName).get()));
return;
}

View File

@ -118,7 +118,7 @@ void WindowGlobalActor::ConstructActor(const nsAString& aName,
if (NS_WARN_IF(!ctor.isObject())) {
nsPrintfCString message("Could not find actor constructor '%s'",
NS_ConvertUTF16toUTF8(ctorName).get());
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_FOUND_ERR, message);
aRv.ThrowNotFoundError(message);
return;
}

View File

@ -1452,9 +1452,8 @@ void MediaRecorder::Start(const Optional<uint32_t>& aTimeslice,
// 5. If the value of recorders state attribute is not inactive, throw an
// InvalidStateError DOMException and abort these steps.
if (mState != RecordingState::Inactive) {
aResult.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
NS_LITERAL_CSTRING("The MediaRecorder has already been started"));
aResult.ThrowInvalidStateError(
"The MediaRecorder has already been started");
return;
}
@ -1463,29 +1462,25 @@ void MediaRecorder::Start(const Optional<uint32_t>& aTimeslice,
if (mStream) {
RefPtr<nsIPrincipal> streamPrincipal = mStream->GetPrincipal();
if (!PrincipalSubsumes(this, streamPrincipal)) {
aResult.ThrowDOMException(
NS_ERROR_DOM_SECURITY_ERR,
NS_LITERAL_CSTRING("The MediaStream's isolation properties disallow "
"access from MediaRecorder"));
aResult.ThrowSecurityError(
"The MediaStream's isolation properties disallow access from "
"MediaRecorder");
return;
}
}
if (mAudioNode && !AudioNodePrincipalSubsumes(this, mAudioNode)) {
LOG(LogLevel::Warning,
("MediaRecorder %p Start AudioNode principal check failed", this));
aResult.ThrowDOMException(
NS_ERROR_DOM_SECURITY_ERR,
NS_LITERAL_CSTRING("The AudioNode's isolation properties disallow "
"access from MediaRecorder"));
aResult.ThrowSecurityError(
"The AudioNode's isolation properties disallow access from "
"MediaRecorder");
return;
}
// 7. If stream is inactive, throw a NotSupportedError DOMException and abort
// these steps.
if (mStream && !mStream->Active()) {
aResult.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
NS_LITERAL_CSTRING("The MediaStream is inactive"));
aResult.ThrowNotSupportedError("The MediaStream is inactive");
return;
}
@ -1508,23 +1503,19 @@ void MediaRecorder::Start(const Optional<uint32_t>& aTimeslice,
if (support != TypeSupport::Supported) {
nsString id;
track->GetId(id);
aResult.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"%s track cannot be recorded: %s",
track->AsAudioStreamTrack() ? "An audio" : "A video",
TypeSupportToCString(support, mConstrainedMimeType).get()));
aResult.ThrowNotSupportedError(nsPrintfCString(
"%s track cannot be recorded: %s",
track->AsAudioStreamTrack() ? "An audio" : "A video",
TypeSupportToCString(support, mConstrainedMimeType).get()));
return;
}
}
if (mAudioNode) {
TypeSupport support = CanRecordAudioTrackWith(mime, mConstrainedMimeType);
if (support != TypeSupport::Supported) {
aResult.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
nsPrintfCString(
"An AudioNode cannot be recorded: %s",
TypeSupportToCString(support, mConstrainedMimeType).get()));
aResult.ThrowNotSupportedError(nsPrintfCString(
"An AudioNode cannot be recorded: %s",
TypeSupportToCString(support, mConstrainedMimeType).get()));
return;
}
}
@ -1620,8 +1611,7 @@ void MediaRecorder::Pause(ErrorResult& aResult) {
// 1. If state is inactive, throw an InvalidStateError DOMException and abort
// these steps.
if (mState == RecordingState::Inactive) {
aResult.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
aResult.ThrowInvalidStateError(
NS_LITERAL_CSTRING("The MediaRecorder is inactive"));
return;
}
@ -1661,8 +1651,7 @@ void MediaRecorder::Resume(ErrorResult& aResult) {
// 1. If state is inactive, throw an InvalidStateError DOMException and abort
// these steps.
if (mState == RecordingState::Inactive) {
aResult.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
aResult.ThrowInvalidStateError(
NS_LITERAL_CSTRING("The MediaRecorder is inactive"));
return;
}
@ -1707,8 +1696,7 @@ void MediaRecorder::RequestData(ErrorResult& aResult) {
// data has been gathered yet.)
// 2. Create a new Blob and gather subsequent data into it.
if (mState == RecordingState::Inactive) {
aResult.ThrowDOMException(
NS_ERROR_DOM_INVALID_STATE_ERR,
aResult.ThrowInvalidStateError(
NS_LITERAL_CSTRING("The MediaRecorder is inactive"));
return;
}
@ -1748,8 +1736,8 @@ already_AddRefed<MediaRecorder> MediaRecorder::Constructor(
if (support != TypeSupport::Supported) {
// This catches also the empty string mimeType when support for any encoders
// has been disabled.
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
TypeSupportToCString(support, aOptions.mMimeType));
aRv.ThrowNotSupportedError(
TypeSupportToCString(support, aOptions.mMimeType));
return nullptr;
}
@ -1832,8 +1820,7 @@ already_AddRefed<MediaRecorder> MediaRecorder::Constructor(
// output.
if (aAudioNode.NumberOfOutputs() > 0 &&
aAudioNodeOutput >= aAudioNode.NumberOfOutputs()) {
aRv.ThrowDOMException(NS_ERROR_DOM_INDEX_SIZE_ERR,
NS_LITERAL_CSTRING("Invalid AudioNode output index"));
aRv.ThrowIndexSizeError("Invalid AudioNode output index");
return nullptr;
}
@ -1853,8 +1840,8 @@ already_AddRefed<MediaRecorder> MediaRecorder::Constructor(
if (support != TypeSupport::Supported) {
// This catches also the empty string mimeType when support for any encoders
// has been disabled.
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
TypeSupportToCString(support, aOptions.mMimeType));
aRv.ThrowNotSupportedError(
TypeSupportToCString(support, aOptions.mMimeType));
return nullptr;
}

View File

@ -97,14 +97,12 @@ void MediaSource::IsTypeSupported(const nsAString& aType,
Maybe<MediaContainerType> containerType = MakeMediaContainerType(aType);
if (!containerType) {
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Unknown type");
return aRv.ThrowNotSupportedError("Unknown type");
}
if (DecoderTraits::CanHandleContainerType(*containerType, aDiagnostics) ==
CANPLAY_NO) {
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Can't play type");
return aRv.ThrowNotSupportedError("Can't play type");
}
// Now we know that this media type could be played.
@ -115,8 +113,7 @@ void MediaSource::IsTypeSupported(const nsAString& aType,
if (!StaticPrefs::media_mediasource_mp4_enabled()) {
// Don't leak information about the fact that it's pref-disabled; just act
// like we can't play it. Or should this throw "Unknown type"?
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Can't play type");
return aRv.ThrowNotSupportedError("Can't play type");
}
return;
}
@ -133,8 +130,7 @@ void MediaSource::IsTypeSupported(const nsAString& aType,
IsWebMForced(aDiagnostics))) {
// Don't leak information about the fact that it's pref-disabled; just act
// like we can't play it. Or should this throw "Unknown type"?
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Can't play type");
return aRv.ThrowNotSupportedError("Can't play type");
}
return;
}
@ -143,14 +139,12 @@ void MediaSource::IsTypeSupported(const nsAString& aType,
StaticPrefs::media_mediasource_webm_audio_enabled())) {
// Don't leak information about the fact that it's pref-disabled; just act
// like we can't play it. Or should this throw "Unknown type"?
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Can't play type");
return aRv.ThrowNotSupportedError("Can't play type");
}
return;
}
return aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"Type not supported in MediaSource");
return aRv.ThrowNotSupportedError("Type not supported in MediaSource");
}
/* static */

View File

@ -55,8 +55,7 @@ void AudioWorkletGlobalScope::RegisterProcessor(
* a valid key.
*/
if (aName.IsEmpty()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Argument 1 of AudioWorkletGlobalScope.registerProcessor should not be "
"an empty string.");
return;
@ -70,8 +69,7 @@ void AudioWorkletGlobalScope::RegisterProcessor(
*/
if (mNameToProcessorMap.GetWeak(aName)) {
// Duplicate names are not allowed
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
"Argument 1 of AudioWorkletGlobalScope.registerProcessor is invalid: a "
"class with the same name is already registered.");
return;
@ -239,31 +237,28 @@ AudioParamDescriptorMap AudioWorkletGlobalScope::DescriptorsFromJS(
}
if (namesSet.Contains(descriptor.mName)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
NS_LITERAL_CSTRING("Duplicated name \"") +
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING("\" in parameterDescriptors."));
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING("\" in parameterDescriptors."));
return AudioParamDescriptorMap();
}
if (descriptor.mMinValue > descriptor.mMaxValue) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
NS_LITERAL_CSTRING("In parameterDescriptors, ") +
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING(" minValue should be smaller than maxValue."));
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING(" minValue should be smaller than maxValue."));
return AudioParamDescriptorMap();
}
if (descriptor.mDefaultValue < descriptor.mMinValue ||
descriptor.mDefaultValue > descriptor.mMaxValue) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_SUPPORTED_ERR,
aRv.ThrowNotSupportedError(
NS_LITERAL_CSTRING("In parameterDescriptors, ") +
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING(" defaultValue is out of the range defined by "
"minValue and maxValue."));
NS_ConvertUTF16toUTF8(descriptor.mName) +
NS_LITERAL_CSTRING(" defaultValue is out of the range defined by "
"minValue and maxValue."));
return AudioParamDescriptorMap();
}

View File

@ -56,8 +56,7 @@ void RemoteServiceWorkerContainerImpl::Register(
ServiceWorkerFailureCallback&& aFailureCB) const {
if (!mActor) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Can't register service worker");
rv.ThrowInvalidStateError("Can't register service worker");
aFailureCB(rv);
return;
}
@ -84,8 +83,7 @@ void RemoteServiceWorkerContainerImpl::Register(
[aFailureCB](ResponseRejectReason&& aReason) {
// IPC layer error
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Failed to register service worker");
rv.ThrowInvalidStateError("Failed to register service worker");
aFailureCB(rv);
});
}

View File

@ -2474,8 +2474,7 @@ RefPtr<GenericErrorResultPromise> ServiceWorkerManager::MaybeClaimClient(
if (!aWorkerRegistration->GetActive()) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Worker is not active");
rv.ThrowInvalidStateError("Worker is not active");
return GenericErrorResultPromise::CreateAndReject(rv, __func__);
}
@ -2483,8 +2482,7 @@ RefPtr<GenericErrorResultPromise> ServiceWorkerManager::MaybeClaimClient(
nsCOMPtr<nsIPrincipal> principal(aClientInfo.GetPrincipal());
if (!aWorkerRegistration->Principal()->Equals(principal)) {
CopyableErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_SECURITY_ERR,
"Worker is for a different origin");
rv.ThrowSecurityError("Worker is for a different origin");
return GenericErrorResultPromise::CreateAndReject(rv, __func__);
}

View File

@ -69,8 +69,7 @@ already_AddRefed<dom::Promise> Buffer::MapReadAsync(ErrorResult& aRv) {
return nullptr;
}
if (mMapping) {
aRv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Unable to map a buffer that is already mapped");
aRv.ThrowInvalidStateError("Unable to map a buffer that is already mapped");
return nullptr;
}
const auto checked = CheckedInt<size_t>(mSize);

View File

@ -54,16 +54,13 @@ already_AddRefed<ComputePassEncoder> CommandEncoder::BeginComputePass(
void CommandEncoder::EndComputePass(Span<const uint8_t> aData,
ErrorResult& aRv) {
if (!mValid) {
return aRv.ThrowDOMException(NS_ERROR_DOM_INVALID_STATE_ERR,
"Command encoder is not valid");
return aRv.ThrowInvalidStateError("Command encoder is not valid");
}
ipc::Shmem shmem;
if (!mBridge->AllocShmem(aData.Length(), ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_ABORT_ERR,
nsPrintfCString("Unable to allocate shmem of size %zu",
aData.Length()));
return aRv.ThrowAbortError(nsPrintfCString(
"Unable to allocate shmem of size %zu", aData.Length()));
}
memcpy(shmem.get<uint8_t>(), aData.data(), aData.Length());

View File

@ -78,8 +78,7 @@ void Device::CreateBufferMapped(JSContext* aCx,
ipc::Shmem shmem;
if (!mBridge->AllocShmem(size, ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_ABORT_ERR,
aRv.ThrowAbortError(
nsPrintfCString("Unable to allocate shmem of size %" PRIuPTR, size));
return;
}
@ -116,8 +115,7 @@ RefPtr<MappingPromise> Device::MapBufferForReadAsync(RawId aId, size_t aSize,
ipc::Shmem shmem;
if (!mBridge->AllocShmem(aSize, ipc::Shmem::SharedMemory::TYPE_BASIC,
&shmem)) {
aRv.ThrowDOMException(
NS_ERROR_DOM_ABORT_ERR,
aRv.ThrowAbortError(
nsPrintfCString("Unable to allocate shmem of size %" PRIuPTR, aSize));
return nullptr;
}

View File

@ -2288,14 +2288,18 @@ void ReportLoadError(ErrorResult& aRv, nsresult aLoadResult,
const nsAString& aScriptURL) {
MOZ_ASSERT(!aRv.Failed());
nsPrintfCString err("Failed to load worker script at \"%s\"",
NS_ConvertUTF16toUTF8(aScriptURL).get());
switch (aLoadResult) {
case NS_ERROR_FILE_NOT_FOUND:
case NS_ERROR_NOT_AVAILABLE:
aLoadResult = NS_ERROR_DOM_NETWORK_ERR;
aRv.ThrowNetworkError(err);
break;
case NS_ERROR_MALFORMED_URI:
aLoadResult = NS_ERROR_DOM_SYNTAX_ERR;
case NS_ERROR_DOM_SYNTAX_ERR:
aRv.ThrowSyntaxError(err);
break;
case NS_BINDING_ABORTED:
@ -2303,38 +2307,29 @@ void ReportLoadError(ErrorResult& aRv, nsresult aLoadResult,
// NS_BINDING_ABORTED, but then ShutdownScriptLoader did it anyway. The
// other callsite, in WorkerPrivate::Constructor, never passed in
// NS_BINDING_ABORTED. So just throw it directly here. Consumers will
// deal as needed. But note that we do NOT want to ThrowDOMException()
// for this case, because that will make it impossible for consumers to
// realize that our error was NS_BINDING_ABORTED.
// deal as needed. But note that we do NOT want to use one of the
// Throw*Error() methods on ErrorResult for this case, because that will
// make it impossible for consumers to realize that our error was
// NS_BINDING_ABORTED.
aRv.Throw(aLoadResult);
return;
case NS_ERROR_DOM_SECURITY_ERR:
case NS_ERROR_DOM_SYNTAX_ERR:
break;
case NS_ERROR_DOM_BAD_URI:
// This is actually a security error.
aLoadResult = NS_ERROR_DOM_SECURITY_ERR;
case NS_ERROR_DOM_SECURITY_ERR:
aRv.ThrowSecurityError(err);
break;
default:
// For lack of anything better, go ahead and throw a NetworkError here.
// We don't want to throw a JS exception, because for toplevel script
// loads that would get squelched.
aRv.ThrowDOMException(
NS_ERROR_DOM_NETWORK_ERR,
nsPrintfCString(
"Failed to load worker script at %s (nsresult = 0x%" PRIx32 ")",
NS_ConvertUTF16toUTF8(aScriptURL).get(),
static_cast<uint32_t>(aLoadResult)));
aRv.ThrowNetworkError(nsPrintfCString(
"Failed to load worker script at %s (nsresult = 0x%" PRIx32 ")",
NS_ConvertUTF16toUTF8(aScriptURL).get(),
static_cast<uint32_t>(aLoadResult)));
return;
}
aRv.ThrowDOMException(
aLoadResult, NS_LITERAL_CSTRING("Failed to load worker script at \"") +
NS_ConvertUTF16toUTF8(aScriptURL) +
NS_LITERAL_CSTRING("\""));
}
void LoadMainScript(WorkerPrivate* aWorkerPrivate,

View File

@ -163,7 +163,7 @@ void AccessCheck::reportCrossOriginDenial(JSContext* cx, JS::HandleId id,
NS_LITERAL_CSTRING(" on cross-origin object");
}
ErrorResult rv;
rv.ThrowDOMException(NS_ERROR_DOM_SECURITY_ERR, message);
rv.ThrowSecurityError(message);
MOZ_ALWAYS_TRUE(rv.MaybeSetPendingException(cx));
}

View File

@ -90,17 +90,15 @@ already_AddRefed<StyleSheet> StyleSheet::Constructor(
do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"CSSStyleSheet constructor not supported when there "
"is no document");
aRv.ThrowNotSupportedError(
"CSSStyleSheet constructor not supported when there is no document");
return nullptr;
}
Document* constructorDocument = window->GetExtantDoc();
if (!constructorDocument) {
aRv.ThrowDOMException(NS_ERROR_DOM_NOT_SUPPORTED_ERR,
"CSSStyleSheet constructor not supported when there "
"is no document");
aRv.ThrowNotSupportedError(
"CSSStyleSheet constructor not supported when there is no document");
return nullptr;
}
@ -586,8 +584,7 @@ already_AddRefed<dom::Promise> StyleSheet::Replace(const nsAString& aText,
// 2.1 Check if sheet is constructed, else throw.
if (!mConstructorDocument) {
aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
aRv.ThrowNotAllowedError(
"The replace() method can only be called on constructed style sheets");
return nullptr;
}
@ -617,16 +614,14 @@ void StyleSheet::ReplaceSync(const nsACString& aText, ErrorResult& aRv) {
// 2.1 Check if sheet is constructed, else throw.
if (!mConstructorDocument) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
return aRv.ThrowNotAllowedError(
"The replaceSync() method can only be called on "
"constructed style sheets");
}
// 2.2 Check if sheet is modifiable, else throw.
if (ModificationDisallowed()) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
return aRv.ThrowNotAllowedError(
"The replaceSync() method can only be called on "
"modifiable style sheets");
}
@ -654,8 +649,7 @@ void StyleSheet::ReplaceSync(const nsACString& aText, ErrorResult& aRv) {
// the document's use counters will be affected even if this function throws.
// Consider changing this to detect @import rules during parse time.
if (Servo_StyleSheet_HasImportRules(rawContent)) {
return aRv.ThrowDOMException(
NS_ERROR_DOM_NOT_ALLOWED_ERR,
return aRv.ThrowNotAllowedError(
"The replaceSync() method does not support @import "
"rules. Use the async replace() method instead.");
}
@ -1260,8 +1254,7 @@ void StyleSheet::DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv) {
// Ensure mRuleList is constructed.
GetCssRulesInternal();
if (aIndex >= mRuleList->Length()) {
aRv.ThrowDOMException(
NS_ERROR_DOM_INDEX_SIZE_ERR,
aRv.ThrowIndexSizeError(
nsPrintfCString("Cannot delete rule at index %u"
" because the number of rules is only %u",
aIndex, mRuleList->Length()));