Bug 1339540 part 2. Move the three ErrorResult-internal NS_ERROR_DOM_* values over to the ErrorResult error module. r=smaug

This commit is contained in:
Boris Zbarsky 2017-02-15 00:02:35 -05:00
parent ebf63a11ae
commit 2816ec4748
4 changed files with 43 additions and 45 deletions

View File

@ -146,9 +146,6 @@ DOM4_MSG_DEF(NetworkError, "Push service unreachable.", NS_ERROR_DOM_PUSH_SERVIC
DOM4_MSG_DEF(InvalidAccessError, "Invalid raw ECDSA P-256 public key.", NS_ERROR_DOM_PUSH_INVALID_KEY_ERR)
DOM4_MSG_DEF(InvalidStateError, "A subscription with a different application server key already exists.", NS_ERROR_DOM_PUSH_MISMATCHED_KEY_ERR)
DOM_MSG_DEF(NS_ERROR_DOM_JS_EXCEPTION, "A callback threw an exception")
DOM_MSG_DEF(NS_ERROR_DOM_DOMEXCEPTION, "A DOMException was thrown")
/* Media errors */
DOM4_MSG_DEF(AbortError, "The fetching process for the media resource was aborted by the user agent at the user's request.", NS_ERROR_DOM_MEDIA_ABORT_ERR)
DOM4_MSG_DEF(NotAllowedError, "The play method is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.", NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR)

View File

@ -289,12 +289,12 @@ TErrorResult<CleanupPolicy>::ThrowJSException(JSContext* cx, JS::Handle<JS::Valu
// root.
mJSException.setUndefined();
if (!js::AddRawValueRoot(cx, &mJSException, "TErrorResult::mJSException")) {
// Don't use NS_ERROR_DOM_JS_EXCEPTION, because that indicates we have
// in fact rooted mJSException.
// Don't use NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION, because that
// indicates we have in fact rooted mJSException.
mResult = NS_ERROR_OUT_OF_MEMORY;
} else {
mJSException = exn;
mResult = NS_ERROR_DOM_JS_EXCEPTION;
mResult = NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION;
#ifdef DEBUG
mUnionState = HasJSException;
#endif // DEBUG
@ -379,7 +379,7 @@ TErrorResult<CleanupPolicy>::ThrowDOMException(nsresult rv,
AssertInOwningThread();
ClearUnionData();
mResult = NS_ERROR_DOM_DOMEXCEPTION;
mResult = NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION;
mDOMExceptionInfo = new DOMExceptionInfo(rv, message);
#ifdef DEBUG
mUnionState = HasDOMExceptionInfo;
@ -600,7 +600,7 @@ TErrorResult<CleanupPolicy>::NoteJSContextException(JSContext* aCx)
{
AssertInOwningThread();
if (JS_IsExceptionPending(aCx)) {
mResult = NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT;
mResult = NS_ERROR_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT;
} else {
mResult = NS_ERROR_UNCATCHABLE_EXCEPTION;
}

View File

@ -189,10 +189,8 @@ public:
// Don't propagate out our internal error codes that have special meaning.
if (rv == NS_ERROR_TYPE_ERR ||
rv == NS_ERROR_RANGE_ERR ||
rv == NS_ERROR_DOM_JS_EXCEPTION ||
rv == NS_ERROR_DOM_DOMEXCEPTION) {
// What about NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT? I guess that can be
// legitimately passed on through....
rv == NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION ||
rv == NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION) {
// What to pick here?
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
@ -277,7 +275,10 @@ public:
// not have to be in the compartment of cx. If someone later uses it, they
// will wrap it into whatever compartment they're working in, as needed.
void ThrowJSException(JSContext* cx, JS::Handle<JS::Value> exn);
bool IsJSException() const { return ErrorCode() == NS_ERROR_DOM_JS_EXCEPTION; }
bool IsJSException() const
{
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
@ -285,7 +286,10 @@ public:
// passed in must be one we create DOMExceptions for; otherwise you may get an
// XPConnect Exception.
void ThrowDOMException(nsresult rv, const nsACString& message = EmptyCString());
bool IsDOMException() const { return ErrorCode() == NS_ERROR_DOM_DOMEXCEPTION; }
bool IsDOMException() const
{
return ErrorCode() == NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION;
}
// Flag on the TErrorResult that whatever needs throwing has been
// thrown on the JSContext already and we should not mess with it.
@ -295,7 +299,7 @@ public:
// Check whether the TErrorResult says to just throw whatever is on
// the JSContext already.
bool IsJSContextException() {
return ErrorCode() == NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT;
return ErrorCode() == NS_ERROR_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT;
}
// Support for uncatchable exceptions.
@ -399,18 +403,18 @@ private:
MOZ_ASSERT(aRv != NS_ERROR_TYPE_ERR, "Use ThrowTypeError()");
MOZ_ASSERT(aRv != NS_ERROR_RANGE_ERR, "Use ThrowRangeError()");
MOZ_ASSERT(!IsErrorWithMessage(), "Don't overwrite errors with message");
MOZ_ASSERT(aRv != NS_ERROR_DOM_JS_EXCEPTION, "Use ThrowJSException()");
MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION,
"Use ThrowJSException()");
MOZ_ASSERT(!IsJSException(), "Don't overwrite JS exceptions");
MOZ_ASSERT(aRv != NS_ERROR_DOM_DOMEXCEPTION, "Use ThrowDOMException()");
MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION,
"Use ThrowDOMException()");
MOZ_ASSERT(!IsDOMException(), "Don't overwrite DOM exceptions");
MOZ_ASSERT(aRv != NS_ERROR_XPC_NOT_ENOUGH_ARGS, "May need to bring back ThrowNotEnoughArgsError");
MOZ_ASSERT(aRv != NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT,
MOZ_ASSERT(aRv != NS_ERROR_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT,
"Use NoteJSContextException");
// Don't trust people anyway, though.
if (aRv == NS_ERROR_TYPE_ERR ||
aRv == NS_ERROR_RANGE_ERR ||
aRv == NS_ERROR_DOM_JS_EXCEPTION ||
aRv == NS_ERROR_DOM_DOMEXCEPTION) {
aRv == NS_ERROR_RANGE_ERR) {
mResult = NS_ERROR_UNEXPECTED;
} else {
mResult = aRv;
@ -448,9 +452,11 @@ private:
// Special values of mResult:
// NS_ERROR_TYPE_ERR -- ThrowTypeError() called on us.
// NS_ERROR_RANGE_ERR -- ThrowRangeError() called on us.
// NS_ERROR_DOM_JS_EXCEPTION -- ThrowJSException() called on us.
// NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION -- ThrowJSException() called
// on us.
// NS_ERROR_UNCATCHABLE_EXCEPTION -- ThrowUncatchableException called on us.
// NS_ERROR_DOM_DOMEXCEPTION -- ThrowDOMException() called on us.
// NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION -- ThrowDOMException() called
// on us.
nsresult mResult;
struct Message;

View File

@ -546,32 +546,21 @@
ERROR(NS_ERROR_DOM_BAD_URI, FAILURE(1012)),
ERROR(NS_ERROR_DOM_RETVAL_UNDEFINED, FAILURE(1013)),
ERROR(NS_ERROR_DOM_QUOTA_REACHED, FAILURE(1014)),
ERROR(NS_ERROR_DOM_JS_EXCEPTION, FAILURE(1015)),
/* A way to represent uncatchable exceptions */
ERROR(NS_ERROR_UNCATCHABLE_EXCEPTION, FAILURE(1016)),
ERROR(NS_ERROR_UNCATCHABLE_EXCEPTION, FAILURE(1015)),
/* An nsresult value to use in ErrorResult to indicate that we want to throw
a DOMException */
ERROR(NS_ERROR_DOM_DOMEXCEPTION, FAILURE(1017)),
ERROR(NS_ERROR_DOM_MALFORMED_URI, FAILURE(1016)),
ERROR(NS_ERROR_DOM_INVALID_HEADER_NAME, FAILURE(1017)),
/* An nsresult value to use in ErrorResult to indicate that we
* should just rethrow whatever is on the JSContext (which might be
* nothing if an uncatchable exception was thrown).
*/
ERROR(NS_ERROR_DOM_EXCEPTION_ON_JSCONTEXT, FAILURE(1018)),
ERROR(NS_ERROR_DOM_MALFORMED_URI, FAILURE(1019)),
ERROR(NS_ERROR_DOM_INVALID_HEADER_NAME, FAILURE(1020)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_INVALID_CONTEXT, FAILURE(1021)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_BE_OPENED, FAILURE(1022)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_SENDING, FAILURE(1023)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_LOADING_OR_DONE, FAILURE(1024)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSEXML, FAILURE(1025)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSETEXT, FAILURE(1026)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC, FAILURE(1027)),
ERROR(NS_ERROR_DOM_INVALID_ACCESS_XHR_TIMEOUT_AND_RESPONSETYPE_UNSUPPORTED_FOR_SYNC, FAILURE(1028)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_INVALID_CONTEXT, FAILURE(1018)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_BE_OPENED, FAILURE(1019)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_SENDING, FAILURE(1020)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_MUST_NOT_BE_LOADING_OR_DONE, FAILURE(1021)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSEXML, FAILURE(1022)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_HAS_WRONG_RESPONSETYPE_FOR_RESPONSETEXT, FAILURE(1023)),
ERROR(NS_ERROR_DOM_INVALID_STATE_XHR_CHUNKED_RESPONSETYPES_UNSUPPORTED_FOR_SYNC, FAILURE(1024)),
ERROR(NS_ERROR_DOM_INVALID_ACCESS_XHR_TIMEOUT_AND_RESPONSETYPE_UNSUPPORTED_FOR_SYNC, FAILURE(1025)),
/* May be used to indicate when e.g. setting a property value didn't
* actually change the value, like for obj.foo = "bar"; obj.foo = "bar";
@ -1012,6 +1001,12 @@
/* 43: NS_ERROR_MODULE_ERRORRESULT */
/* ======================================================================= */
#define MODULE NS_ERROR_MODULE_ERRORRESULT
/* Represents a JS Value being thrown as an exception. */
ERROR(NS_ERROR_INTERNAL_ERRORRESULT_JS_EXCEPTION, FAILURE(1)),
/* Used to indicate that we want to throw a DOMException. */
ERROR(NS_ERROR_INTERNAL_ERRORRESULT_DOMEXCEPTION, FAILURE(2)),
/* Used to indicate that an exception is already pending on the JSContext. */
ERROR(NS_ERROR_INTERNAL_ERRORRESULT_EXCEPTION_ON_JSCONTEXT, FAILURE(3)),
#undef MODULE
/* ======================================================================= */