Issue #2053 - Part 5: Throw a DOMException instead of a JS exception for some errors

This commit is contained in:
FranklinDM
2023-04-06 23:22:50 +08:00
committed by roytam1
parent a0d52c0094
commit ef8e3b5419
7 changed files with 23 additions and 8 deletions
+6
View File
@@ -157,6 +157,12 @@ DOM4_MSG_DEF(NotSupportedError, "The media resource indicated by the src attribu
DOM4_MSG_DEF(SyntaxError, "The URI is malformed.", NS_ERROR_DOM_MALFORMED_URI)
DOM4_MSG_DEF(SyntaxError, "Invalid header name.", NS_ERROR_DOM_INVALID_HEADER_NAME)
/* User Timing API errors */
DOM4_MSG_DEF(SyntaxError, "An unknown mark name was provided.", NS_ERROR_DOM_UT_UNKNOWN_MARK_NAME)
DOM4_MSG_DEF(SyntaxError, "markName cannot be a performance timing attribute.", NS_ERROR_DOM_UT_INVALID_TIMING_ATTR)
DOM4_MSG_DEF(InvalidAccessError, "A PerformanceTiming attribute which isn't available yet was provided.", NS_ERROR_DOM_UT_UNAVAILABLE_ATTR)
DOM4_MSG_DEF(InvalidStateError, "Global object is unavailable.", NS_ERROR_DOM_UT_UNAVAILABLE_GLOBAL_OBJECT)
/* XMLHttpRequest errors. */
DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest has an invalid context.", NS_ERROR_DOM_INVALID_STATE_XHR_HAS_INVALID_CONTEXT)
DOM4_MSG_DEF(InvalidStateError, "XMLHttpRequest state must be OPENED.", NS_ERROR_DOM_INVALID_STATE_XHR_MUST_BE_OPENED)
-2
View File
@@ -104,8 +104,6 @@ MSG_DEF(MSG_NO_NEGATIVE_ATTR, 1, JSEXN_TYPEERR, "Given attribute {0} cannot be n
MSG_DEF(MSG_PMO_NO_SEPARATE_ENDMARK, 0, JSEXN_TYPEERR, "Cannot provide separate endMark argument if PerformanceMeasureOptions argument is given.")
MSG_DEF(MSG_PMO_MISSING_STARTENDMARK, 0, JSEXN_TYPEERR, "PerformanceMeasureOptions must have start and/or end member.")
MSG_DEF(MSG_PMO_INVALID_MEMBERS, 0, JSEXN_TYPEERR, "PerformanceMeasureOptions cannot have all of the following members: start, duration, and end.")
MSG_DEF(MSG_PMO_UNKNOWN_MARK_NAME, 1, JSEXN_SYNTAXERR, "Given mark name, {0}, is unknown.")
MSG_DEF(MSG_PMO_CONSTRUCTOR_INACCESSIBLE, 0, JSEXN_TYPEERR, "Can't access PerformanceMark constructor, performance is null.")
MSG_DEF(MSG_PMO_INVALID_TIMING_ATTR, 0, JSEXN_SYNTAXERR, "markName cannot be a performance timing attribute.")
MSG_DEF(MSG_PMO_UNEXPECTED_START_TIME, 0, JSEXN_TYPEERR, "Expected startTime >= 0.")
MSG_DEF(MSG_PMO_INVALID_ATTR_FOR_NON_GLOBAL, 1, JSEXN_TYPEERR, "Cannot get PerformanceTiming attribute values for non-Window global object. Given: {0}.")
+1
View File
@@ -195,6 +195,7 @@ CreateException(JSContext* aCx, nsresult aRv, const nsACString& aMessage)
case NS_ERROR_MODULE_DOM_ANIM:
case NS_ERROR_MODULE_DOM_PUSH:
case NS_ERROR_MODULE_DOM_MEDIA:
case NS_ERROR_MODULE_DOM_USER_TIMING:
if (aMessage.IsEmpty()) {
return DOMException::Create(aRv);
}
+4 -5
View File
@@ -269,13 +269,13 @@ already_AddRefed<PerformanceMark> Performance::Mark(
nsCOMPtr<nsIGlobalObject> parent = GetParentObject();
if (!parent || parent->IsDying() || !parent->GetGlobalJSObject()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
aRv.Throw(NS_ERROR_DOM_UT_UNAVAILABLE_GLOBAL_OBJECT);
return nullptr;
}
GlobalObject global(aCx, parent->GetGlobalJSObject());
if (global.Failed()) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
aRv.Throw(NS_ERROR_DOM_UT_UNAVAILABLE_GLOBAL_OBJECT);
return nullptr;
}
@@ -340,7 +340,7 @@ Performance::ConvertMarkToTimestampWithString(const nsAString& aName,
return arr.LastElement()->StartTime();
}
aRv.ThrowTypeError<MSG_PMO_UNKNOWN_MARK_NAME>(aName);
aRv.Throw(NS_ERROR_DOM_UT_UNKNOWN_MARK_NAME);
return 0;
}
@@ -403,8 +403,7 @@ DOMHighResTimeStamp Performance::ConvertNameToTimestamp(const nsAString& aName,
GetPerformanceTimingFromString(aName);
MOZ_ASSERT(endTime >= 0);
if (endTime == 0) {
// Was given a PerformanceTiming attribute which isn't available yet.
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
aRv.Throw(NS_ERROR_DOM_UT_UNAVAILABLE_ATTR);
return 0;
}
+1 -1
View File
@@ -54,7 +54,7 @@ already_AddRefed<PerformanceMark> PerformanceMark::Constructor(
if (performance->IsGlobalObjectWindow() &&
performance->IsPerformanceTimingAttribute(aMarkName)) {
aRv.ThrowTypeError<MSG_PMO_INVALID_TIMING_ATTR>();
aRv.Throw(NS_ERROR_DOM_UT_INVALID_TIMING_ATTR);
return nullptr;
}
+10
View File
@@ -990,6 +990,16 @@
ERROR(NS_ERROR_DOM_MEDIA_CUBEB_INITIALIZATION_ERR, FAILURE(101)),
#undef MODULE
/* ======================================================================= */
/* 42: NS_ERROR_MODULE_DOM_USER_TIMING */
/* ======================================================================= */
#define MODULE NS_ERROR_MODULE_DOM_USER_TIMING
ERROR(NS_ERROR_DOM_UT_UNKNOWN_MARK_NAME, FAILURE(1)),
ERROR(NS_ERROR_DOM_UT_INVALID_TIMING_ATTR, FAILURE(2)),
ERROR(NS_ERROR_DOM_UT_UNAVAILABLE_ATTR, FAILURE(3)),
ERROR(NS_ERROR_DOM_UT_UNAVAILABLE_GLOBAL_OBJECT, FAILURE(4)),
#undef MODULE
/* ======================================================================= */
/* 51: NS_ERROR_MODULE_GENERAL */
/* ======================================================================= */
+1
View File
@@ -79,6 +79,7 @@
#define NS_ERROR_MODULE_DOM_ANIM 39
#define NS_ERROR_MODULE_DOM_PUSH 40
#define NS_ERROR_MODULE_DOM_MEDIA 41
#define NS_ERROR_MODULE_DOM_USER_TIMING 42
/* NS_ERROR_MODULE_GENERAL should be used by modules that do not
* care if return code values overlap. Callers of methods that