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

LibJS: Replace GlobalObject with VM in PrototypeObject AOs [Part 3/19]

This commit is contained in:
Linus Groh 2022-08-20 22:42:08 +01:00
parent 694f66b5ca
commit f6c4a0f5d0
44 changed files with 392 additions and 394 deletions

View file

@ -38,7 +38,7 @@ 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(global_object));
auto* collator = TRY(typed_this_object(vm));
// 3. If collator.[[BoundCompare]] is undefined, then
if (!collator->bound_compare()) {
@ -61,7 +61,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(global_object));
auto* collator = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -46,7 +46,7 @@ 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(global_object));
auto* date_time_format = TRY(typed_this_object(vm));
// 4. If dtf.[[BoundFormat]] is undefined, then
if (!date_time_format->bound_format()) {
@ -69,7 +69,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(global_object));
auto* date_time_format = TRY(typed_this_object(vm));
double date_value;
@ -96,7 +96,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(global_object));
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())
@ -123,7 +123,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(global_object));
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())
@ -150,7 +150,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(global_object));
auto* date_time_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -40,7 +40,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(global_object));
auto* display_names = TRY(typed_this_object(vm));
// 3. Let code be ? ToString(code).
auto code_string = TRY(code.to_string(global_object));
@ -128,7 +128,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(global_object));
auto* display_names = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -36,7 +36,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format)
{
// 1. Let df be this value.
// 2. Perform ? RequireInternalSlot(df, [[InitializedDurationFormat]]).
auto* duration_format = TRY(typed_this_object(global_object));
auto* duration_format = TRY(typed_this_object(vm));
// 3. Let record be ? ToDurationRecord(duration).
auto record = TRY(to_duration_record(vm, vm.argument(0)));
@ -68,7 +68,7 @@ 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(global_object));
auto* duration_format = TRY(typed_this_object(vm));
// 3. Let record be ? ToDurationRecord(duration).
auto record = TRY(to_duration_record(vm, vm.argument(0)));
@ -114,7 +114,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(global_object));
auto* duration_format = TRY(typed_this_object(vm));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -40,7 +40,7 @@ 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(global_object));
auto* list_format = TRY(typed_this_object(vm));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(vm, list));
@ -57,7 +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 = TRY(typed_this_object(global_object));
auto* list_format = TRY(typed_this_object(vm));
// 3. Let stringList be ? StringListFromIterable(list).
auto string_list = TRY(string_list_from_iterable(vm, list));
@ -73,7 +73,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(global_object));
auto* list_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -59,7 +59,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
VERIFY(locale.has_value());
@ -79,7 +79,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
VERIFY(locale.has_value());
@ -97,7 +97,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Return loc.[[Locale]].
return js_string(vm, locale_object->locale());
@ -108,7 +108,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -130,13 +130,13 @@ JS_DEFINE_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_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()); \
#define __JS_ENUMERATE(keyword) \
JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::keyword) \
{ \
auto* locale_object = TRY(typed_this_object(vm)); \
if (!locale_object->has_##keyword()) \
return js_undefined(); \
return js_string(vm, locale_object->keyword()); \
}
JS_ENUMERATE_LOCALE_KEYWORD_PROPERTIES
#undef __JS_ENUMERATE
@ -146,7 +146,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Return loc.[[Numeric]].
return Value(locale_object->numeric());
@ -157,7 +157,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -174,7 +174,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -195,7 +195,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -221,11 +221,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(global_object)); \
return 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 keyword##_of_locale(vm, *locale_object); \
}
JS_ENUMERATE_LOCALE_INFO_PROPERTIES
#undef __JS_ENUMERATE
@ -235,7 +235,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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let locale be loc.[[Locale]].
auto locale = Unicode::parse_unicode_locale_id(locale_object->locale());
@ -255,7 +255,7 @@ 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(global_object));
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, global_object.object_prototype());
@ -277,7 +277,7 @@ 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(global_object));
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, global_object.object_prototype());

View file

@ -46,7 +46,7 @@ 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(global_object));
auto* number_format = TRY(typed_this_object(vm));
// 4. If nf.[[BoundFormat]] is undefined, then
if (!number_format->bound_format()) {
@ -70,7 +70,7 @@ 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(global_object));
auto* number_format = TRY(typed_this_object(vm));
// 3. Let x be ? ToIntlMathematicalValue(value).
auto mathematical_value = TRY(to_intl_mathematical_value(vm, value));
@ -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(global_object));
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())
@ -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(global_object));
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())
@ -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(global_object));
auto* number_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -38,7 +38,7 @@ 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(global_object));
auto* plural_rules = TRY(typed_this_object(vm));
// 3. Let n be ? ToNumber(value).
auto number = TRY(vm.argument(0).to_number(global_object));
@ -56,7 +56,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(global_object));
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())
@ -83,7 +83,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(global_object));
auto* plural_rules = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -36,7 +36,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(global_object));
auto* relative_time_format = TRY(typed_this_object(vm));
// 3. Let value be ? ToNumber(value).
auto value = TRY(vm.argument(0).to_number(global_object));
@ -54,7 +54,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(global_object));
auto* relative_time_format = TRY(typed_this_object(vm));
// 3. Let value be ? ToNumber(value).
auto value = TRY(vm.argument(0).to_number(global_object));
@ -73,7 +73,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(global_object));
auto* relative_time_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());

View file

@ -36,7 +36,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(global_object));
auto* iterator = TRY(typed_this_object(vm));
// 3. Let segmenter be iterator.[[IteratingSegmenter]].
auto const& segmenter = iterator->iterating_segmenter();

View file

@ -38,7 +38,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(global_object));
auto* segmenter = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, global_object.object_prototype());
@ -62,7 +62,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::segment)
// 1. Let segmenter be the this value.
// 2. Perform ? RequireInternalSlot(segmenter, [[InitializedSegmenter]]).
auto* segmenter = TRY(typed_this_object(global_object));
auto* segmenter = TRY(typed_this_object(vm));
// 3. Let string be ? ToString(string).
auto string = TRY(vm.argument(0).to_utf16_string(global_object));

View file

@ -33,7 +33,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(global_object));
auto* segments = TRY(typed_this_object(vm));
// 3. Let segmenter be segments.[[SegmentsSegmenter]].
auto const& segmenter = segments->segments_segmenter();
@ -68,7 +68,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(global_object));
auto* segments = TRY(typed_this_object(vm));
// 3. Let segmenter be segments.[[SegmentsSegmenter]].
auto& segmenter = segments->segments_segmenter();