1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:27:35 +00:00

LibJS: Convert Intl.DisplayNames functions to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-22 22:48:25 +01:00
parent 68df9e4dfb
commit 15eadcf023
4 changed files with 15 additions and 15 deletions

View file

@ -31,7 +31,7 @@ void DisplayNamesConstructor::initialize(GlobalObject& global_object)
define_direct_property(vm.names.prototype, global_object.intl_display_names_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_old_native_function(vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
define_native_function(vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);
}
@ -112,7 +112,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
}
// 12.3.2 Intl.DisplayNames.supportedLocalesOf ( locales [ , options ] ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.supportedLocalesOf
JS_DEFINE_OLD_NATIVE_FUNCTION(DisplayNamesConstructor::supported_locales_of)
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesConstructor::supported_locales_of)
{
auto locales = vm.argument(0);
auto options = vm.argument(1);
@ -121,10 +121,10 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DisplayNamesConstructor::supported_locales_of)
// No-op, availability of each requested locale is checked via Unicode::is_locale_available()
// 2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY_OR_DISCARD(canonicalize_locale_list(global_object, locales));
auto requested_locales = TRY(canonicalize_locale_list(global_object, locales));
// 3. Return ? SupportedLocales(availableLocales, requestedLocales, options).
return TRY_OR_DISCARD(supported_locales(global_object, requested_locales, options));
return TRY(supported_locales(global_object, requested_locales, options));
}
}

View file

@ -24,7 +24,7 @@ public:
private:
virtual bool has_constructor() const override { return true; }
JS_DECLARE_OLD_NATIVE_FUNCTION(supported_locales_of);
JS_DECLARE_NATIVE_FUNCTION(supported_locales_of);
};
}

View file

@ -28,25 +28,25 @@ void DisplayNamesPrototype::initialize(GlobalObject& global_object)
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl.DisplayNames"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_old_native_function(vm.names.of, of, 1, attr);
define_old_native_function(vm.names.resolvedOptions, resolved_options, 0, attr);
define_native_function(vm.names.of, of, 1, attr);
define_native_function(vm.names.resolvedOptions, resolved_options, 0, attr);
}
// 12.4.3 Intl.DisplayNames.prototype.of ( code ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.of
JS_DEFINE_OLD_NATIVE_FUNCTION(DisplayNamesPrototype::of)
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
{
auto code = vm.argument(0);
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY_OR_DISCARD(typed_this_object(global_object));
auto* display_names = TRY(typed_this_object(global_object));
// 3. Let code be ? ToString(code).
auto code_string = TRY_OR_DISCARD(code.to_string(global_object));
auto code_string = TRY(code.to_string(global_object));
code = js_string(vm, move(code_string));
// 4. Let code be ? CanonicalCodeForDisplayNames(displayNames.[[Type]], code).
code = TRY_OR_DISCARD(canonical_code_for_display_names(global_object, display_names->type(), code.as_string().string()));
code = TRY(canonical_code_for_display_names(global_object, display_names->type(), code.as_string().string()));
// 5. Let fields be displayNames.[[Fields]].
// 6. If fields has a field [[<code>]], return fields.[[<code>]].
@ -81,11 +81,11 @@ JS_DEFINE_OLD_NATIVE_FUNCTION(DisplayNamesPrototype::of)
}
// 12.4.4 Intl.DisplayNames.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype.resolvedOptions
JS_DEFINE_OLD_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
{
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY_OR_DISCARD(typed_this_object(global_object));
auto* display_names = TRY(typed_this_object(global_object));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(global_object, global_object.object_prototype());

View file

@ -20,8 +20,8 @@ public:
virtual ~DisplayNamesPrototype() override = default;
private:
JS_DECLARE_OLD_NATIVE_FUNCTION(of);
JS_DECLARE_OLD_NATIVE_FUNCTION(resolved_options);
JS_DECLARE_NATIVE_FUNCTION(of);
JS_DECLARE_NATIVE_FUNCTION(resolved_options);
};
}