Kaynağa Gözat

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.
Timothy Flynn 3 yıl önce
ebeveyn
işleme
fdedb3ab33

+ 0 - 1
Userland/Libraries/LibJS/Runtime/ErrorTypes.h

@@ -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")                                                                                               \

+ 4 - 4
Userland/Libraries/LibJS/Runtime/Intl/AbstractOperations.cpp

@@ -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 {};
     }
 

+ 4 - 4
Userland/Libraries/LibJS/Tests/builtins/Intl/DisplayNames/DisplayNames.prototype.of.js

@@ -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");
     });
 });