1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 08:27:46 +00:00

LibJS: Convert PrototypeObject::typed_this_object() to ThrowCompletionOr

This commit is contained in:
Linus Groh 2021-10-18 20:03:21 +01:00
parent 7c29979e30
commit 4b7c1f703e
26 changed files with 282 additions and 831 deletions

View file

@ -39,9 +39,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = typed_this_object(global_object);
if (!display_names)
return {};
auto* display_names = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let code be ? ToString(code).
auto code_string = TRY_OR_DISCARD(code.to_string(global_object));
@ -87,9 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
{
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = typed_this_object(global_object);
if (!display_names)
return {};
auto* display_names = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(global_object, global_object.object_prototype());

View file

@ -40,9 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};
auto* list_format = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY_OR_DISCARD(string_list_from_iterable(global_object, list));
@ -59,9 +57,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};
auto* list_format = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY_OR_DISCARD(string_list_from_iterable(global_object, list));
@ -75,9 +71,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
{
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = typed_this_object(global_object);
if (vm.exception())
return {};
auto* list_format = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(global_object, global_object.object_prototype());

View file

@ -49,9 +49,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
VERIFY(locale.has_value());
@ -69,9 +67,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
VERIFY(locale.has_value());
@ -89,9 +85,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::to_string)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Return loc.[[Locale]].
return js_string(vm, locale_object->locale());
@ -102,9 +96,7 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::base_name)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -126,15 +118,13 @@ JS_DEFINE_NATIVE_GETTER(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_NATIVE_GETTER(LocalePrototype::keyword) \
{ \
auto* locale_object = typed_this_object(global_object); \
if (!locale_object) \
return {}; \
if (!locale_object->has_##keyword()) \
return js_undefined(); \
return js_string(vm, locale_object->keyword()); \
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_GETTER(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()); \
}
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
#undef __JS_ENUMERATE
@ -144,9 +134,7 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::numeric)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Return loc.[[Numeric]].
return Value(locale_object->numeric());
@ -157,9 +145,7 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::language)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -176,9 +162,7 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::script)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -199,9 +183,7 @@ JS_DEFINE_NATIVE_GETTER(LocalePrototype::region)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = typed_this_object(global_object);
if (!locale_object)
return {};
auto* locale_object = TRY_OR_DISCARD(typed_this_object(global_object));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());

View file

@ -37,9 +37,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set nf to ? UnwrapNumberFormat(nf).
// 3. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
auto* number_format = typed_this_object(global_object);
if (vm.exception())
return {};
auto* number_format = TRY_OR_DISCARD(typed_this_object(global_object));
// 4. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(global_object, global_object.object_prototype());