1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 14:17:36 +00:00

LibJS: Port PrototypeObject::typed_this_object() to NonnullGCPtr

This commit is contained in:
Linus Groh 2023-04-13 20:09:41 +02:00 committed by Andreas Kling
parent 15360e50d3
commit a23dd88f61
36 changed files with 491 additions and 491 deletions

View file

@ -40,13 +40,13 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::compare_getter)
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(vm));
auto collator = TRY(typed_this_object(vm));
// 3. If collator.[[BoundCompare]] is undefined, then
if (!collator->bound_compare()) {
// a. Let F be a new built-in function object as defined in 10.3.3.1.
// b. Set F.[[Collator]] to collator.
auto function = CollatorCompareFunction::create(realm, *collator);
auto function = CollatorCompareFunction::create(realm, collator);
// c. Set collator.[[BoundCompare]] to F.
collator->set_bound_compare(function);
@ -63,7 +63,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
// 1. Let collator be the this value.
// 2. Perform ? RequireInternalSlot(collator, [[InitializedCollator]]).
auto* collator = TRY(typed_this_object(vm));
auto collator = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -48,13 +48,13 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format)
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set dtf to ? UnwrapDateTimeFormat(dtf).
// 3. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
auto* date_time_format = TRY(typed_this_object(vm));
auto date_time_format = TRY(typed_this_object(vm));
// 4. If dtf.[[BoundFormat]] is undefined, then
if (!date_time_format->bound_format()) {
// a. Let F be a new built-in function object as defined in DateTime Format Functions (11.1.6).
// b. Set F.[[DateTimeFormat]] to dtf.
auto bound_format = DateTimeFormatFunction::create(realm, *date_time_format);
auto bound_format = DateTimeFormatFunction::create(realm, date_time_format);
// c. Set dtf.[[BoundFormat]] to F.
date_time_format->set_bound_format(bound_format);
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
// 1. Let dtf be the this value.
// 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
auto* date_time_format = TRY(typed_this_object(vm));
auto date_time_format = TRY(typed_this_object(vm));
double date_value;
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
}
// 5. Return ? FormatDateTimeToParts(dtf, x).
return TRY(format_date_time_to_parts(vm, *date_time_format, date_value));
return TRY(format_date_time_to_parts(vm, date_time_format, date_value));
}
// 11.3.5 Intl.DateTimeFormat.prototype.formatRange ( startDate, endDate ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.formatRange
@ -100,7 +100,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range)
// 1. Let dtf be this value.
// 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
auto* date_time_format = TRY(typed_this_object(vm));
auto date_time_format = TRY(typed_this_object(vm));
// 3. If startDate is undefined or endDate is undefined, throw a TypeError exception.
if (start_date.is_undefined())
@ -115,7 +115,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range)
auto end_date_number = TRY(end_date.to_number(vm)).as_double();
// 6. Return ? FormatDateTimeRange(dtf, x, y).
auto formatted = TRY(format_date_time_range(vm, *date_time_format, start_date_number, end_date_number));
auto formatted = TRY(format_date_time_range(vm, date_time_format, start_date_number, end_date_number));
return PrimitiveString::create(vm, move(formatted));
}
@ -127,7 +127,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
// 1. Let dtf be this value.
// 2. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
auto* date_time_format = TRY(typed_this_object(vm));
auto date_time_format = TRY(typed_this_object(vm));
// 3. If startDate is undefined or endDate is undefined, throw a TypeError exception.
if (start_date.is_undefined())
@ -142,7 +142,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_range_to_parts)
auto end_date_number = TRY(end_date.to_number(vm)).as_double();
// 6. Return ? FormatDateTimeRangeToParts(dtf, x, y).
return TRY(format_date_time_range_to_parts(vm, *date_time_format, start_date_number, end_date_number));
return TRY(format_date_time_range_to_parts(vm, date_time_format, start_date_number, end_date_number));
}
// 11.3.7 Intl.DateTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype.resolvedoptions
@ -154,7 +154,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
// 2. If the implementation supports the normative optional constructor mode of 4.3 Note 1, then
// a. Set dtf to ? UnwrapDateTimeFormat(dtf).
// 3. Perform ? RequireInternalSlot(dtf, [[InitializedDateTimeFormat]]).
auto* date_time_format = TRY(typed_this_object(vm));
auto date_time_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());
@ -194,7 +194,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
}
if (!date_time_format->has_date_style() && !date_time_format->has_time_style()) {
MUST(for_each_calendar_field(vm, *date_time_format, [&](auto& option, auto const& property, auto const&) -> ThrowCompletionOr<void> {
MUST(for_each_calendar_field(vm, date_time_format, [&](auto& option, auto const& property, auto const&) -> ThrowCompletionOr<void> {
using ValueType = typename RemoveReference<decltype(option)>::ValueType;
if (!option.has_value())

View file

@ -42,7 +42,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of)
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY(typed_this_object(vm));
auto display_names = TRY(typed_this_object(vm));
// 3. Let code be ? ToString(code).
code = PrimitiveString::create(vm, TRY(code.to_string(vm)));
@ -130,7 +130,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
// 1. Let displayNames be this value.
// 2. Perform ? RequireInternalSlot(displayNames, [[InitializedDisplayNames]]).
auto* display_names = TRY(typed_this_object(vm));
auto display_names = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -40,13 +40,13 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
{
// 1. Let df be this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(vm));
auto duration_format = TRY(typed_this_object(vm));
// 3. Let record be ? ToDurationRecord(duration).
auto record = TRY(to_duration_record(vm, vm.argument(0)));
// 4. Let parts be PartitionDurationFormatPattern(df, record).
auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, *duration_format, record));
auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, duration_format, record));
// 5. Let result be a new empty String.
ThrowableStringBuilder result(vm);
@ -68,13 +68,13 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
// 1. Let df be this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(vm));
auto duration_format = TRY(typed_this_object(vm));
// 3. Let record be ? ToDurationRecord(duration).
auto record = TRY(to_duration_record(vm, vm.argument(0)));
// 4. Let parts be PartitionDurationFormatPattern(df, record).
auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, *duration_format, record));
auto parts = MUST_OR_THROW_OOM(partition_duration_format_pattern(vm, duration_format, record));
// 5. Let result be ! ArrayCreate(0).
auto result = MUST(Array::create(realm, 0));
@ -110,7 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
// 1. Let df be the this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(vm));
auto duration_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -42,13 +42,13 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = TRY(typed_this_object(vm));
auto list_format = TRY(typed_this_object(vm));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(vm, list));
// 4. Return ! FormatList(lf, stringList).
auto formatted = MUST_OR_THROW_OOM(format_list(vm, *list_format, string_list));
auto formatted = MUST_OR_THROW_OOM(format_list(vm, list_format, string_list));
return PrimitiveString::create(vm, move(formatted));
}
@ -59,13 +59,13 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::format_to_parts)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = TRY(typed_this_object(vm));
auto list_format = TRY(typed_this_object(vm));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(vm, list));
// 4. Return ! FormatListToParts(lf, stringList).
return MUST_OR_THROW_OOM(format_list_to_parts(vm, *list_format, string_list));
return MUST_OR_THROW_OOM(format_list_to_parts(vm, list_format, string_list));
}
// 13.3.5 Intl.ListFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype.resolvedoptions
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
// 1. Let lf be the this value.
// 2. Perform ? RequireInternalSlot(lf, [[InitializedListFormat]]).
auto* list_format = TRY(typed_this_object(vm));
auto list_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -61,7 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::maximize)
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
VERIFY(locale.has_value());
@ -81,7 +81,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::minimize)
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
VERIFY(locale.has_value());
@ -99,7 +99,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::to_string)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Return loc.[[Locale]].
return PrimitiveString::create(vm, locale_object->locale());
@ -110,7 +110,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
@ -135,7 +135,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::base_name)
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto* locale_object = TRY(typed_this_object(vm)); \
auto locale_object = TRY(typed_this_object(vm)); \
if (!locale_object->has_##keyword()) \
return js_undefined(); \
return PrimitiveString::create(vm, locale_object->keyword()); \
@ -148,7 +148,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::numeric)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Return loc.[[Numeric]].
return Value(locale_object->numeric());
@ -159,7 +159,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::language)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
@ -176,7 +176,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::script)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
@ -197,7 +197,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
@ -223,11 +223,11 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::region)
// 1.4.17 get Intl.Locale.prototype.collations, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.collations
// 1.4.18 get Intl.Locale.prototype.hourCycles, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.hourCycles
// 1.4.19 get Intl.Locale.prototype.numberingSystems, https://tc39.es/proposal-intl-locale-info/#sec-Intl.Locale.prototype.numberingSystems
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto* locale_object = TRY(typed_this_object(vm)); \
return MUST_OR_THROW_OOM(keyword##_of_locale(vm, *locale_object)); \
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto locale_object = TRY(typed_this_object(vm)); \
return MUST_OR_THROW_OOM(keyword##_of_locale(vm, locale_object)); \
}
JS_ENUMERATE_LOCALE_INFO_PROPERTIES
#undef __JS_ENUMERATE
@ -237,7 +237,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::time_zones)
{
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = TRY_OR_THROW_OOM(vm, ::Locale::parse_unicode_locale_id(locale_object->locale()));
@ -257,13 +257,13 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto info = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
auto direction = MUST_OR_THROW_OOM(character_direction_of_locale(vm, *locale_object));
auto direction = MUST_OR_THROW_OOM(character_direction_of_locale(vm, locale_object));
// 5. Perform ! CreateDataPropertyOrThrow(info, "direction", dir).
MUST(info->create_data_property_or_throw(vm.names.direction, MUST_OR_THROW_OOM(PrimitiveString::create(vm, direction))));
@ -279,13 +279,13 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
// 1. Let loc be the this value.
// 2. Perform ? RequireInternalSlot(loc, [[InitializedLocale]]).
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
auto locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto info = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Let wi be ! WeekInfoOfLocale(loc).
auto week_info = MUST_OR_THROW_OOM(week_info_of_locale(vm, *locale_object));
auto week_info = MUST_OR_THROW_OOM(week_info_of_locale(vm, locale_object));
// 5. Let we be ! CreateArrayFromList( wi.[[Weekend]] ).
auto weekend = Array::create_from<u8>(realm, week_info.weekend, [](auto day) { return Value(day); });

View file

@ -48,13 +48,13 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format)
// 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 = TRY(typed_this_object(vm));
auto number_format = TRY(typed_this_object(vm));
// 4. If nf.[[BoundFormat]] is undefined, then
if (!number_format->bound_format()) {
// a. Let F be a new built-in function object as defined in Number Format Functions (15.1.4).
// b. Set F.[[NumberFormat]] to nf.
auto bound_format = NumberFormatFunction::create(realm, *number_format);
auto bound_format = NumberFormatFunction::create(realm, number_format);
// c. Set nf.[[BoundFormat]] to F.
number_format->set_bound_format(bound_format);
@ -71,13 +71,13 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_to_parts)
// 1. Let nf be the this value.
// 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
auto* number_format = TRY(typed_this_object(vm));
auto number_format = TRY(typed_this_object(vm));
// 3. Let x be ? ToIntlMathematicalValue(value).
auto mathematical_value = TRY(to_intl_mathematical_value(vm, value));
// 4. Return ? FormatNumericToParts(nf, x).
return TRY(format_numeric_to_parts(vm, *number_format, move(mathematical_value)));
return TRY(format_numeric_to_parts(vm, number_format, move(mathematical_value)));
}
// 15.3.5 Intl.NumberFormat.prototype.formatRange ( start, end ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.formatrange
@ -88,7 +88,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range)
// 1. Let nf be the this value.
// 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
auto* number_format = TRY(typed_this_object(vm));
auto number_format = TRY(typed_this_object(vm));
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
@ -103,7 +103,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range)
auto y = TRY(to_intl_mathematical_value(vm, end));
// 6. Return ? FormatNumericRange(nf, x, y).
auto formatted = TRY(format_numeric_range(vm, *number_format, move(x), move(y)));
auto formatted = TRY(format_numeric_range(vm, number_format, move(x), move(y)));
return PrimitiveString::create(vm, move(formatted));
}
@ -115,7 +115,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
// 1. Let nf be the this value.
// 2. Perform ? RequireInternalSlot(nf, [[InitializedNumberFormat]]).
auto* number_format = TRY(typed_this_object(vm));
auto number_format = TRY(typed_this_object(vm));
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
@ -130,7 +130,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::format_range_to_parts)
auto y = TRY(to_intl_mathematical_value(vm, end));
// 6. Return ? FormatNumericRangeToParts(nf, x, y).
return TRY(format_numeric_range_to_parts(vm, *number_format, move(x), move(y)));
return TRY(format_numeric_range_to_parts(vm, number_format, move(x), move(y)));
}
// 15.3.7 Intl.NumberFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.numberformat.prototype.resolvedoptions
@ -142,7 +142,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 = TRY(typed_this_object(vm));
auto number_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -40,13 +40,13 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select)
{
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
auto* plural_rules = TRY(typed_this_object(vm));
auto plural_rules = TRY(typed_this_object(vm));
// 3. Let n be ? ToNumber(value).
auto number = TRY(vm.argument(0).to_number(vm));
// 4. Return ! ResolvePlural(pr, n).[[PluralCategory]].
auto plurality = MUST_OR_THROW_OOM(resolve_plural(vm, *plural_rules, number));
auto plurality = MUST_OR_THROW_OOM(resolve_plural(vm, plural_rules, number));
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality.plural_category)));
}
@ -58,7 +58,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
auto* plural_rules = TRY(typed_this_object(vm));
auto plural_rules = TRY(typed_this_object(vm));
// 3. If start is undefined or end is undefined, throw a TypeError exception.
if (start.is_undefined())
@ -73,7 +73,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::select_range)
auto y = TRY(end.to_number(vm));
// 6. Return ? ResolvePluralRange(pr, x, y).
auto plurality = TRY(resolve_plural_range(vm, *plural_rules, x, y));
auto plurality = TRY(resolve_plural_range(vm, plural_rules, x, y));
return MUST_OR_THROW_OOM(PrimitiveString::create(vm, ::Locale::plural_category_to_string(plurality)));
}
@ -84,7 +84,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
// 1. Let pr be the this value.
// 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
auto* plural_rules = TRY(typed_this_object(vm));
auto plural_rules = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format)
{
// 1. Let relativeTimeFormat be the this value.
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
auto* relative_time_format = TRY(typed_this_object(vm));
auto relative_time_format = TRY(typed_this_object(vm));
// 3. Let value be ? ToNumber(value).
auto value = TRY(vm.argument(0).to_number(vm));
@ -47,7 +47,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format)
auto unit = TRY(vm.argument(1).to_string(vm));
// 5. Return ? FormatRelativeTime(relativeTimeFormat, value, unit).
auto formatted = TRY(format_relative_time(vm, *relative_time_format, value.as_double(), unit.bytes_as_string_view()));
auto formatted = TRY(format_relative_time(vm, relative_time_format, value.as_double(), unit.bytes_as_string_view()));
return PrimitiveString::create(vm, move(formatted));
}
@ -56,7 +56,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
{
// 1. Let relativeTimeFormat be the this value.
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
auto* relative_time_format = TRY(typed_this_object(vm));
auto relative_time_format = TRY(typed_this_object(vm));
// 3. Let value be ? ToNumber(value).
auto value = TRY(vm.argument(0).to_number(vm));
@ -65,7 +65,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::format_to_parts)
auto unit = TRY(vm.argument(1).to_string(vm));
// 5. Return ? FormatRelativeTimeToParts(relativeTimeFormat, value, unit).
return TRY(format_relative_time_to_parts(vm, *relative_time_format, value.as_double(), unit.bytes_as_string_view()));
return TRY(format_relative_time_to_parts(vm, relative_time_format, value.as_double(), unit.bytes_as_string_view()));
}
// 17.3.5 Intl.RelativeTimeFormat.prototype.resolvedOptions ( ), https://tc39.es/ecma402/#sec-intl.relativetimeformat.prototype.resolvedoptions
@ -75,7 +75,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
// 1. Let relativeTimeFormat be the this value.
// 2. Perform ? RequireInternalSlot(relativeTimeFormat, [[InitializedRelativeTimeFormat]]).
auto* relative_time_format = TRY(typed_this_object(vm));
auto relative_time_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());

View file

@ -38,7 +38,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentIteratorPrototype::next)
{
// 1. Let iterator be the this value.
// 2. Perform ? RequireInternalSlot(iterator, [[IteratingSegmenter]]).
auto* iterator = TRY(typed_this_object(vm));
auto iterator = TRY(typed_this_object(vm));
// 3. Let segmenter be iterator.[[IteratingSegmenter]].
auto const& segmenter = iterator->iterating_segmenter();

View file

@ -40,7 +40,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(vm));
auto segmenter = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto options = Object::create(realm, realm.intrinsics().object_prototype());
@ -64,13 +64,13 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(vm));
auto segmenter = TRY(typed_this_object(vm));
// 3. Let string be ? ToString(string).
auto string = TRY(vm.argument(0).to_utf16_string(vm));
// 4. Return ! CreateSegmentsObject(segmenter, string).
return Segments::create(realm, *segmenter, move(string));
return Segments::create(realm, segmenter, move(string));
}
}

View file

@ -35,7 +35,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::containing)
{
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
auto* segments = TRY(typed_this_object(vm));
auto segments = TRY(typed_this_object(vm));
// 3. Let segmenter be segments.[[SegmentsSegmenter]].
auto const& segmenter = segments->segments_segmenter();
@ -70,7 +70,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
// 1. Let segments be the this value.
// 2. Perform ? RequireInternalSlot(segments, [[SegmentsSegmenter]]).
auto* segments = TRY(typed_this_object(vm));
auto segments = TRY(typed_this_object(vm));
// 3. Let segmenter be segments.[[SegmentsSegmenter]].
auto& segmenter = segments->segments_segmenter();
@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmentsPrototype::symbol_iterator)
auto string = segments->segments_string();
// 5. Return ! CreateSegmentIterator(segmenter, string).
return SegmentIterator::create(realm, segmenter, string, *segments);
return SegmentIterator::create(realm, segmenter, string, segments);
}
}