зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1617972
. Add a table that stores the exception type of DOM errors. r=peterv
The callsite in DOMIntersectionObserver did end up throwing a RangeError, as the spec requires, because in the end we just used the exception code to determine the kind of exception to throw, but was misleading about what it was doing. Differential Revision: https://phabricator.services.mozilla.com/D64175 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
2fb25f9104
Коммит
9d69c2d87d
|
@ -118,7 +118,7 @@ already_AddRefed<DOMIntersectionObserver> DOMIntersectionObserver::Constructor(
|
|||
observer->mThresholds.SetCapacity(thresholds.Length());
|
||||
for (const auto& thresh : thresholds) {
|
||||
if (thresh < 0.0 || thresh > 1.0) {
|
||||
aRv.ThrowTypeError<dom::MSG_THRESHOLD_RANGE_ERROR>();
|
||||
aRv.ThrowRangeError<dom::MSG_THRESHOLD_RANGE_ERROR>();
|
||||
return nullptr;
|
||||
}
|
||||
observer->mThresholds.AppendElement(thresh);
|
||||
|
@ -127,7 +127,7 @@ already_AddRefed<DOMIntersectionObserver> DOMIntersectionObserver::Constructor(
|
|||
} else {
|
||||
double thresh = aOptions.mThreshold.GetAsDouble();
|
||||
if (thresh < 0.0 || thresh > 1.0) {
|
||||
aRv.ThrowTypeError<dom::MSG_THRESHOLD_RANGE_ERROR>();
|
||||
aRv.ThrowRangeError<dom::MSG_THRESHOLD_RANGE_ERROR>();
|
||||
return nullptr;
|
||||
}
|
||||
observer->mThresholds.AppendElement(thresh);
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <utility>
|
||||
|
||||
#include "js/GCAnnotations.h"
|
||||
#include "js/ErrorReport.h"
|
||||
#include "js/Value.h"
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
@ -76,6 +77,13 @@ bool constexpr ErrorFormatHasContext[] = {
|
|||
#undef MSG_DEF
|
||||
};
|
||||
|
||||
// Table of the kinds of exceptions error messages will produce.
|
||||
JSExnType constexpr ErrorExceptionType[] = {
|
||||
#define MSG_DEF(_name, _argc, _has_context, _exn, _str) _exn,
|
||||
#include "mozilla/dom/Errors.msg"
|
||||
#undef MSG_DEF
|
||||
};
|
||||
|
||||
uint16_t GetErrorArgCount(const ErrNum aErrorNumber);
|
||||
|
||||
namespace binding_detail {
|
||||
|
@ -289,6 +297,8 @@ class TErrorResult {
|
|||
template <dom::ErrNum errorNumber, typename... Ts>
|
||||
void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
|
||||
ThrowTypeError(Ts&&... messageArgs) {
|
||||
static_assert(dom::ErrorExceptionType[errorNumber] == JSEXN_TYPEERR,
|
||||
"Throwing a non-TypeError via ThrowTypeError");
|
||||
ThrowErrorWithMessage<errorNumber>(NS_ERROR_INTERNAL_ERRORRESULT_TYPEERROR,
|
||||
std::forward<Ts>(messageArgs)...);
|
||||
}
|
||||
|
@ -311,6 +321,8 @@ class TErrorResult {
|
|||
template <dom::ErrNum errorNumber, typename... Ts>
|
||||
void MOZ_MUST_RETURN_FROM_CALLER_IF_THIS_IS_ARG
|
||||
ThrowRangeError(Ts&&... messageArgs) {
|
||||
static_assert(dom::ErrorExceptionType[errorNumber] == JSEXN_RANGEERR,
|
||||
"Throwing a non-RangeError via ThrowRangeError");
|
||||
ThrowErrorWithMessage<errorNumber>(NS_ERROR_INTERNAL_ERRORRESULT_RANGEERROR,
|
||||
std::forward<Ts>(messageArgs)...);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче