Bug 1612213 part 2. Move the DOMException definitions from ErrorResult.h into a separate file. r=smaug

This way we can use the for Promise too.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2020-01-30 08:57:42 +00:00
parent b88d5ac5a8
commit 7a16020858
3 changed files with 65 additions and 56 deletions

View File

@ -0,0 +1,53 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// NOTE: No include guard. This is meant to be included to generate different
// code based on how DOMEXCEPTION is defined, possibly multiple times in a
// single translation unit.
// XXXbz This list sort of duplicates the DOM4_MSG_DEF bits of domerr.msg,
// except that has various extra errors that are not in specs
// (e.g. InvalidPointerId) and has multiple definitions for the same error
// name using different messages, which we don't need because we get the
// message passed in. We should try to convert all consumers of the "extra"
// error codes in there to these APIs, remove the extra bits, and just
// include domerr.msg here.
DOMEXCEPTION(IndexSizeError, NS_ERROR_DOM_INDEX_SIZE_ERR)
// We don't have a DOMStringSizeError and it's deprecated anyway.
DOMEXCEPTION(HierarchyRequestError, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)
DOMEXCEPTION(WrongDocumentError, NS_ERROR_DOM_WRONG_DOCUMENT_ERR)
DOMEXCEPTION(InvalidCharacterError, NS_ERROR_DOM_INVALID_CHARACTER_ERR)
// We don't have a NoDataAllowedError and it's deprecated anyway.
DOMEXCEPTION(NoModificationAllowedError,
NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR)
DOMEXCEPTION(NotFoundError, NS_ERROR_DOM_NOT_FOUND_ERR)
DOMEXCEPTION(NotSupportedError, NS_ERROR_DOM_NOT_SUPPORTED_ERR)
DOMEXCEPTION(InUseAttributeError, NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR)
DOMEXCEPTION(InvalidStateError, NS_ERROR_DOM_INVALID_STATE_ERR)
DOMEXCEPTION(SyntaxError, NS_ERROR_DOM_SYNTAX_ERR)
DOMEXCEPTION(InvalidModificationError, NS_ERROR_DOM_INVALID_MODIFICATION_ERR)
DOMEXCEPTION(NamespaceError, NS_ERROR_DOM_NAMESPACE_ERR)
DOMEXCEPTION(InvalidAccessError, NS_ERROR_DOM_INVALID_ACCESS_ERR)
// We don't have a ValidationError and it's deprecated anyway.
DOMEXCEPTION(TypeMismatchError, NS_ERROR_DOM_TYPE_MISMATCH_ERR)
DOMEXCEPTION(SecurityError, NS_ERROR_DOM_SECURITY_ERR)
DOMEXCEPTION(NetworkError, NS_ERROR_DOM_NETWORK_ERR)
DOMEXCEPTION(AbortError, NS_ERROR_DOM_ABORT_ERR)
DOMEXCEPTION(URLMismatchError, NS_ERROR_DOM_URL_MISMATCH_ERR)
DOMEXCEPTION(QuotaExceededError, NS_ERROR_DOM_QUOTA_EXCEEDED_ERR)
DOMEXCEPTION(TimeoutError, NS_ERROR_DOM_TIMEOUT_ERR)
DOMEXCEPTION(InvalidNodeTypeError, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR)
DOMEXCEPTION(DataCloneError, NS_ERROR_DOM_DATA_CLONE_ERR)
DOMEXCEPTION(EncodingError, NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR)
DOMEXCEPTION(NotReadableError, NS_ERROR_DOM_FILE_NOT_READABLE_ERR)
DOMEXCEPTION(UnknownError, NS_ERROR_DOM_UNKNOWN_ERR)
DOMEXCEPTION(ConstraintError, NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR)
DOMEXCEPTION(DataError, NS_ERROR_DOM_DATA_ERR)
DOMEXCEPTION(TransactionInactiveError,
NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR)
DOMEXCEPTION(ReadOnlyError, NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR)
DOMEXCEPTION(VersionError, NS_ERROR_DOM_INDEXEDDB_VERSION_ERR)
DOMEXCEPTION(OperationError, NS_ERROR_DOM_OPERATION_ERR)
DOMEXCEPTION(NotAllowedError, NS_ERROR_DOM_NOT_ALLOWED_ERR)

View File

@ -165,11 +165,11 @@ class TErrorResult {
operator const ErrorResult&() const;
operator OOMReporter&();
// This method is deprecated. Consumers should ThrowDOMException if they are
// throwing a DOMException. If they have a random nsresult which may or may
// not correspond to a DOMException type, they should consider using an
// appropriate DOMException-type nsresult with an informative message and
// calling ThrowDOMException.
// This method is deprecated. Consumers should Throw*Error with the
// appropriate DOMException name if they are throwing a DOMException. If they
// have a random nsresult which may or may not correspond to a DOMException
// type, they should consider using an appropriate DOMException with an
// informative message and calling the relevant Throw*Error.
void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG Throw(nsresult rv) {
MOZ_ASSERT(NS_FAILED(rv), "Please don't try throwing success");
AssignErrorCode(rv);
@ -318,11 +318,6 @@ class TErrorResult {
return ErrorCode() == NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION;
}
// Facilities for throwing a DOMException. If an empty message string is
// passed to ThrowDOMException, the default message string for the given
// nsresult will be used. The passed-in string must be UTF-8. The nsresult
// passed in must be one we create DOMExceptions for; otherwise you may get an
// XPConnect Exception.
void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
ThrowDOMException(nsresult rv, const nsACString& message);
@ -333,7 +328,10 @@ class TErrorResult {
ThrowDOMException(rv, nsLiteralCString(aMessage));
}
// Facilities for throwing specific spec-defined DOMExceptions.
// Facilities for throwing DOMExceptions of whatever type a spec calls for.
// If an empty message string is passed to one of these Throw*Error functions,
// the default message string for the relevant type of DOMException will be
// used. The passed-in string must be UTF-8.
#define DOMEXCEPTION(name, err) \
void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG Throw##name( \
const nsACString& aMessage) { \
@ -346,50 +344,7 @@ class TErrorResult {
ThrowDOMException(err, aMessage); \
}
// XXXbz This list sort of duplicates the DOM4_MSG_DEF bits of domerr.msg,
// except that has various extra errors that are not in specs
// (e.g. InvalidPointerId) and has multiple definitions for the same error
// name using different messages, which we don't need because we get the
// message passed in. We should try to convert all consumers of the "extra"
// error codes in there to these APIs, remove the extra bits, and just
// include domerr.msg here.
DOMEXCEPTION(IndexSizeError, NS_ERROR_DOM_INDEX_SIZE_ERR)
// We don't have a DOMStringSizeError and it's deprecated anyway.
DOMEXCEPTION(HierarchyRequestError, NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)
DOMEXCEPTION(WrongDocumentError, NS_ERROR_DOM_WRONG_DOCUMENT_ERR)
DOMEXCEPTION(InvalidCharacterError, NS_ERROR_DOM_INVALID_CHARACTER_ERR)
// We don't have a NoDataAllowedError and it's deprecated anyway.
DOMEXCEPTION(NoModificationAllowedError,
NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR)
DOMEXCEPTION(NotFoundError, NS_ERROR_DOM_NOT_FOUND_ERR)
DOMEXCEPTION(NotSupportedError, NS_ERROR_DOM_NOT_SUPPORTED_ERR)
DOMEXCEPTION(InUseAttributeError, NS_ERROR_DOM_INUSE_ATTRIBUTE_ERR)
DOMEXCEPTION(InvalidStateError, NS_ERROR_DOM_INVALID_STATE_ERR)
DOMEXCEPTION(SyntaxError, NS_ERROR_DOM_SYNTAX_ERR)
DOMEXCEPTION(InvalidModificationError, NS_ERROR_DOM_INVALID_MODIFICATION_ERR)
DOMEXCEPTION(NamespaceError, NS_ERROR_DOM_NAMESPACE_ERR)
DOMEXCEPTION(InvalidAccessError, NS_ERROR_DOM_INVALID_ACCESS_ERR)
// We don't have a ValidationError and it's deprecated anyway.
DOMEXCEPTION(TypeMismatchError, NS_ERROR_DOM_TYPE_MISMATCH_ERR)
DOMEXCEPTION(SecurityError, NS_ERROR_DOM_SECURITY_ERR)
DOMEXCEPTION(NetworkError, NS_ERROR_DOM_NETWORK_ERR)
DOMEXCEPTION(AbortError, NS_ERROR_DOM_ABORT_ERR)
DOMEXCEPTION(URLMismatchError, NS_ERROR_DOM_URL_MISMATCH_ERR)
DOMEXCEPTION(QuotaExceededError, NS_ERROR_DOM_QUOTA_EXCEEDED_ERR)
DOMEXCEPTION(TimeoutError, NS_ERROR_DOM_TIMEOUT_ERR)
DOMEXCEPTION(InvalidNodeTypeError, NS_ERROR_DOM_INVALID_NODE_TYPE_ERR)
DOMEXCEPTION(DataCloneError, NS_ERROR_DOM_DATA_CLONE_ERR)
DOMEXCEPTION(EncodingError, NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR)
DOMEXCEPTION(NotReadableError, NS_ERROR_DOM_FILE_NOT_READABLE_ERR)
DOMEXCEPTION(UnknownError, NS_ERROR_DOM_UNKNOWN_ERR)
DOMEXCEPTION(ConstraintError, NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR)
DOMEXCEPTION(DataError, NS_ERROR_DOM_DATA_ERR)
DOMEXCEPTION(TransactionInactiveError,
NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR)
DOMEXCEPTION(ReadOnlyError, NS_ERROR_DOM_INDEXEDDB_READ_ONLY_ERR)
DOMEXCEPTION(VersionError, NS_ERROR_DOM_INDEXEDDB_VERSION_ERR)
DOMEXCEPTION(OperationError, NS_ERROR_DOM_OPERATION_ERR)
DOMEXCEPTION(NotAllowedError, NS_ERROR_DOM_NOT_ALLOWED_ERR)
#include "mozilla/dom/DOMExceptionNames.h"
#undef DOMEXCEPTION
@ -511,7 +466,7 @@ class TErrorResult {
"Use ThrowJSException()");
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION,
"Use ThrowDOMException()");
"Use Throw*Error for the appropriate DOMException name");
MOZ_ASSERT(!IsDOMException(), "Don't overwrite DOM exceptions");
MOZ_ASSERT(aRv != NS_ERROR_XPC_NOT_ENOUGH_ARGS,
"May need to bring back ThrowNotEnoughArgsError");

View File

@ -33,6 +33,7 @@ EXPORTS.mozilla.dom += [
'CallbackFunction.h',
'CallbackInterface.h',
'CallbackObject.h',
'DOMExceptionNames.h',
'DOMJSClass.h',
'DOMJSProxyHandler.h',
'DOMString.h',