1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

LibJS: Remove duplicated error message from ErrorTypes.h

ErrorType::IntlInvalidCode has almost exactly the same message as
ErrorType::OptionIsNotValidValue. Remove it, as all uses of the former
are semantically interchangeable with the latter.
This commit is contained in:
Timothy Flynn 2021-09-01 18:25:25 -04:00 committed by Linus Groh
parent 21c4922ac0
commit fdedb3ab33
3 changed files with 8 additions and 9 deletions

View file

@ -31,7 +31,6 @@
M(InOperatorWithObject, "'in' operator must be used on an object") \
M(InstanceOfOperatorBadPrototype, "'prototype' property of {} is not an object") \
M(IntlInvalidLanguageTag, "{} is not a structurally valid language tag") \
M(IntlInvalidCode, "'{}' is not a valid value for option type {}") \
M(InvalidAssignToConst, "Invalid assignment to const variable") \
M(InvalidCodePoint, "Invalid code point {}, must be an integer no less than 0 and no greater than 0x10FFFF") \
M(InvalidFormat, "Invalid {} format") \

View file

@ -445,7 +445,7 @@ Value canonical_code_for_display_names(GlobalObject& global_object, DisplayNames
if (type == DisplayNames::Type::Language) {
// a. If code does not match the unicode_language_id production, throw a RangeError exception.
if (!Unicode::parse_unicode_language_id(code).has_value()) {
vm.throw_exception<RangeError>(global_object, ErrorType::IntlInvalidCode, code, "language"sv);
vm.throw_exception<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "language"sv);
return {};
}
@ -466,7 +466,7 @@ Value canonical_code_for_display_names(GlobalObject& global_object, DisplayNames
if (type == DisplayNames::Type::Region) {
// a. If code does not match the unicode_region_subtag production, throw a RangeError exception.
if (!Unicode::is_unicode_region_subtag(code)) {
vm.throw_exception<RangeError>(global_object, ErrorType::IntlInvalidCode, code, "region"sv);
vm.throw_exception<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "region"sv);
return {};
}
@ -479,7 +479,7 @@ Value canonical_code_for_display_names(GlobalObject& global_object, DisplayNames
if (type == DisplayNames::Type::Script) {
// a. If code does not match the unicode_script_subtag production, throw a RangeError exception.
if (!Unicode::is_unicode_script_subtag(code)) {
vm.throw_exception<RangeError>(global_object, ErrorType::IntlInvalidCode, code, "script"sv);
vm.throw_exception<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "script"sv);
return {};
}
@ -493,7 +493,7 @@ Value canonical_code_for_display_names(GlobalObject& global_object, DisplayNames
// 5. If ! IsWellFormedCurrencyCode(code) is false, throw a RangeError exception.
if (!is_well_formed_currency_code(code)) {
vm.throw_exception<RangeError>(global_object, ErrorType::IntlInvalidCode, code, "currency"sv);
vm.throw_exception<RangeError>(global_object, ErrorType::OptionIsNotValidValue, code, "currency"sv);
return {};
}

View file

@ -2,25 +2,25 @@ describe("errors", () => {
test("invalid language", () => {
expect(() => {
new Intl.DisplayNames("en", { type: "language" }).of("hello!");
}).toThrowWithMessage(RangeError, "'hello!' is not a valid value for option type language");
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option language");
});
test("invalid region", () => {
expect(() => {
new Intl.DisplayNames("en", { type: "region" }).of("hello!");
}).toThrowWithMessage(RangeError, "'hello!' is not a valid value for option type region");
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option region");
});
test("invalid script", () => {
expect(() => {
new Intl.DisplayNames("en", { type: "script" }).of("hello!");
}).toThrowWithMessage(RangeError, "'hello!' is not a valid value for option type script");
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option script");
});
test("invalid currency", () => {
expect(() => {
new Intl.DisplayNames("en", { type: "currency" }).of("hello!");
}).toThrowWithMessage(RangeError, "'hello!' is not a valid value for option type currency");
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option currency");
});
});