mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:27:44 +00:00
LibJS: Convert Intl.Locale functions to ThrowCompletionOr
This commit is contained in:
parent
9fb1d7e18b
commit
351f0b70bd
2 changed files with 49 additions and 49 deletions
|
@ -25,31 +25,31 @@ void LocalePrototype::initialize(GlobalObject& global_object)
|
|||
auto& vm = this->vm();
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
define_old_native_function(vm.names.maximize, maximize, 0, attr);
|
||||
define_old_native_function(vm.names.minimize, minimize, 0, attr);
|
||||
define_old_native_function(vm.names.toString, to_string, 0, attr);
|
||||
define_native_function(vm.names.maximize, maximize, 0, attr);
|
||||
define_native_function(vm.names.minimize, minimize, 0, attr);
|
||||
define_native_function(vm.names.toString, to_string, 0, attr);
|
||||
|
||||
// 14.3.2 Intl.Locale.prototype[ @@toStringTag ], https://tc39.es/ecma402/#sec-Intl.Locale.prototype-@@tostringtag
|
||||
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.Locale"), Attribute::Configurable);
|
||||
|
||||
define_old_native_accessor(vm.names.baseName, base_name, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.calendar, calendar, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.caseFirst, case_first, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.collation, collation, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.hourCycle, hour_cycle, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.numberingSystem, numbering_system, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.numeric, numeric, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.language, language, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.script, script, {}, Attribute::Configurable);
|
||||
define_old_native_accessor(vm.names.region, region, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.baseName, base_name, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.calendar, calendar, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.caseFirst, case_first, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.collation, collation, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.hourCycle, hour_cycle, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.numberingSystem, numbering_system, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.numeric, numeric, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.language, language, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.script, script, {}, Attribute::Configurable);
|
||||
define_native_accessor(vm.names.region, region, {}, Attribute::Configurable);
|
||||
}
|
||||
|
||||
// 14.3.3 Intl.Locale.prototype.maximize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.maximize
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::maximize)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
VERIFY(locale.has_value());
|
||||
|
@ -63,11 +63,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::maximize)
|
|||
}
|
||||
|
||||
// 14.3.4 Intl.Locale.prototype.minimize ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.minimize
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::minimize)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
VERIFY(locale.has_value());
|
||||
|
@ -81,22 +81,22 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::minimize)
|
|||
}
|
||||
|
||||
// 14.3.5 Intl.Locale.prototype.toString ( ), https://tc39.es/ecma402/#sec-Intl.Locale.prototype.toString
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::to_string)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::to_string)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Return loc.[[Locale]].
|
||||
return js_string(vm, locale_object->locale());
|
||||
}
|
||||
|
||||
// 14.3.6 get Intl.Locale.prototype.baseName, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.baseName
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::base_name)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let locale be loc.[[Locale]].
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
|
@ -118,34 +118,34 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::base_name)
|
|||
// 14.3.9 get Intl.Locale.prototype.collation, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.collation
|
||||
// 14.3.10 get Intl.Locale.prototype.hourCycle, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.hourCycle
|
||||
// 14.3.12 get Intl.Locale.prototype.numberingSystem, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.numberingSystem
|
||||
#define __JS_ENUMERATE(keyword) \
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::keyword) \
|
||||
{ \
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object)); \
|
||||
if (!locale_object->has_##keyword()) \
|
||||
return js_undefined(); \
|
||||
return js_string(vm, locale_object->keyword()); \
|
||||
#define __JS_ENUMERATE(keyword) \
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
|
||||
{ \
|
||||
auto* locale_object = TRY(typed_this_object(global_object)); \
|
||||
if (!locale_object->has_##keyword()) \
|
||||
return js_undefined(); \
|
||||
return js_string(vm, locale_object->keyword()); \
|
||||
}
|
||||
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
|
||||
#undef __JS_ENUMERATE
|
||||
|
||||
// 14.3.11 get Intl.Locale.prototype.numeric, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.numeric
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::numeric)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::numeric)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Return loc.[[Numeric]].
|
||||
return Value(locale_object->numeric());
|
||||
}
|
||||
|
||||
// 14.3.13 get Intl.Locale.prototype.language, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.language
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::language)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::language)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let locale be loc.[[Locale]].
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
|
@ -158,11 +158,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::language)
|
|||
}
|
||||
|
||||
// 14.3.14 get Intl.Locale.prototype.script, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.script
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::script)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let locale be loc.[[Locale]].
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
|
@ -179,11 +179,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::script)
|
|||
}
|
||||
|
||||
// 14.3.15 get Intl.Locale.prototype.region, https://tc39.es/ecma402/#sec-Intl.Locale.prototype.region
|
||||
JS_DEFINE_OLD_NATIVE_FUNCTION(LocalePrototype::region)
|
||||
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
|
||||
{
|
||||
// 1. Let loc be the this value.
|
||||
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
|
||||
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
|
||||
auto* locale_object = TRY(typed_this_object(global_object));
|
||||
|
||||
// 3. Let locale be loc.[[Locale]].
|
||||
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
|
||||
|
|
|
@ -20,20 +20,20 @@ public:
|
|||
virtual ~LocalePrototype() override = default;
|
||||
|
||||
private:
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(maximize);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(minimize);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(to_string);
|
||||
JS_DECLARE_NATIVE_FUNCTION(maximize);
|
||||
JS_DECLARE_NATIVE_FUNCTION(minimize);
|
||||
JS_DECLARE_NATIVE_FUNCTION(to_string);
|
||||
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(base_name);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(calendar);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(case_first);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(collation);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(hour_cycle);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(numbering_system);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(numeric);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(language);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(script);
|
||||
JS_DECLARE_OLD_NATIVE_FUNCTION(region);
|
||||
JS_DECLARE_NATIVE_FUNCTION(base_name);
|
||||
JS_DECLARE_NATIVE_FUNCTION(calendar);
|
||||
JS_DECLARE_NATIVE_FUNCTION(case_first);
|
||||
JS_DECLARE_NATIVE_FUNCTION(collation);
|
||||
JS_DECLARE_NATIVE_FUNCTION(hour_cycle);
|
||||
JS_DECLARE_NATIVE_FUNCTION(numbering_system);
|
||||
JS_DECLARE_NATIVE_FUNCTION(numeric);
|
||||
JS_DECLARE_NATIVE_FUNCTION(language);
|
||||
JS_DECLARE_NATIVE_FUNCTION(script);
|
||||
JS_DECLARE_NATIVE_FUNCTION(region);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue