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

LibJS: Move intrinsics to the realm

Intrinsics, i.e. mostly constructor and prototype objects, but also
things like empty and new object shape now live on a new heap-allocated
JS::Intrinsics object, thus completing the long journey of taking all
the magic away from the global object.
This represents the Realm's [[Intrinsics]] slot in the spec and matches
its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of
architecture.

In the majority of cases it should now be possibly to fully allocate a
regular object without the global object existing, and in fact that's
what we do now - the realm is allocated before the global object, and
the intrinsics between both :^)
This commit is contained in:
Linus Groh 2022-08-27 00:54:55 +01:00
parent 84c4b66721
commit 50428ea8d2
217 changed files with 1305 additions and 1039 deletions

View file

@ -17,7 +17,7 @@ CollatorCompareFunction* CollatorCompareFunction::create(Realm& realm, Collator&
}
CollatorCompareFunction::CollatorCompareFunction(Realm& realm, Collator& collator)
: NativeFunction(*realm.global_object().function_prototype())
: NativeFunction(*realm.intrinsics().function_prototype())
, m_collator(collator)
{
}

View file

@ -131,7 +131,7 @@ static ThrowCompletionOr<Collator*> initialize_collator(VM& vm, Collator& collat
// 10.1 The Intl.Collator Constructor, https://tc39.es/ecma402/#sec-the-intl-collator-constructor
CollatorConstructor::CollatorConstructor(Realm& realm)
: NativeFunction(vm().names.Collator.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Collator.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -142,7 +142,7 @@ void CollatorConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 10.2.1 Intl.Collator.prototype, https://tc39.es/ecma402/#sec-intl.collator.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_collator_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_collator_prototype(), 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
@ -171,7 +171,7 @@ ThrowCompletionOr<Object*> CollatorConstructor::construct(FunctionObject& new_ta
// a. Append [[CaseFirst]] as the last element of internalSlotsList.
// 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%Collator.prototype%", internalSlotsList).
auto* collator = TRY(ordinary_create_from_constructor<Collator>(vm, new_target, &GlobalObject::intl_collator_prototype));
auto* collator = TRY(ordinary_create_from_constructor<Collator>(vm, new_target, &Intrinsics::intl_collator_prototype));
// 6. Return ? InitializeCollator(collator, locales, options).
return TRY(initialize_collator(vm, *collator, locales, options));

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 10.3 Properties of the Intl.Collator Prototype Object, https://tc39.es/ecma402/#sec-properties-of-the-intl-collator-prototype-object
CollatorPrototype::CollatorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -64,7 +64,7 @@ JS_DEFINE_NATIVE_FUNCTION(CollatorPrototype::resolved_options)
auto* collator = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 3, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -545,7 +545,7 @@ ThrowCompletionOr<Vector<PatternPartition>> format_date_time_pattern(VM& vm, Dat
auto const& data_locale = date_time_format.data_locale();
auto construct_number_format = [&](auto* options) -> ThrowCompletionOr<NumberFormat*> {
auto* number_format = TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale), options));
auto* number_format = TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale), options));
return static_cast<NumberFormat*>(number_format);
};
@ -861,7 +861,7 @@ ThrowCompletionOr<Array*> format_date_time_to_parts(VM& vm, DateTimeFormat& date
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -1175,7 +1175,7 @@ ThrowCompletionOr<Array*> format_date_time_range_to_parts(VM& vm, DateTimeFormat
// 4. For each Record { [[Type]], [[Value]], [[Source]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -18,7 +18,7 @@ namespace JS::Intl {
// 11.1 The Intl.DateTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor
DateTimeFormatConstructor::DateTimeFormatConstructor(Realm& realm)
: NativeFunction(vm().names.DateTimeFormat.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.DateTimeFormat.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -29,7 +29,7 @@ void DateTimeFormatConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 11.2.1 Intl.DateTimeFormat.prototype, https://tc39.es/ecma402/#sec-intl.datetimeformat.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_date_time_format_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_date_time_format_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
@ -53,7 +53,7 @@ ThrowCompletionOr<Object*> DateTimeFormatConstructor::construct(FunctionObject&
auto options = vm.argument(1);
// 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormat.prototype%", « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »).
auto* date_time_format = TRY(ordinary_create_from_constructor<DateTimeFormat>(vm, new_target, &GlobalObject::intl_date_time_format_prototype));
auto* date_time_format = TRY(ordinary_create_from_constructor<DateTimeFormat>(vm, new_target, &Intrinsics::intl_date_time_format_prototype));
// 3. Perform ? InitializeDateTimeFormat(dateTimeFormat, locales, options).
TRY(initialize_date_time_format(vm, *date_time_format, locales, options));

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 11.5.5 DateTime Format Functions, https://tc39.es/ecma402/#sec-datetime-format-functions
DateTimeFormatFunction* DateTimeFormatFunction::create(Realm& realm, DateTimeFormat& date_time_format)
{
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.global_object().function_prototype());
return realm.heap().allocate<DateTimeFormatFunction>(realm, date_time_format, *realm.intrinsics().function_prototype());
}
DateTimeFormatFunction::DateTimeFormatFunction(DateTimeFormat& date_time_format, Object& prototype)
@ -49,7 +49,7 @@ ThrowCompletionOr<Value> DateTimeFormatFunction::call()
// 3. If date is not provided or is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(JS::call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(JS::call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 11.3 Properties of the Intl.DateTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-datetimeformat-prototype-object
DateTimeFormatPrototype::DateTimeFormatPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -78,7 +78,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::format_to_parts)
// 3. If date is undefined, then
if (date.is_undefined()) {
// a. Let x be ! Call(%Date.now%, undefined).
date_value = MUST(call(vm, realm.global_object().date_constructor_now_function(), js_undefined())).as_double();
date_value = MUST(call(vm, realm.intrinsics().date_constructor_now_function(), js_undefined())).as_double();
}
// 4. Else,
else {
@ -155,7 +155,7 @@ JS_DEFINE_NATIVE_FUNCTION(DateTimeFormatPrototype::resolved_options)
auto* date_time_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 5. For each row of Table 5, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -115,7 +115,7 @@ ThrowCompletionOr<Value> canonical_code_for_display_names(VM& vm, DisplayNames::
return vm.throw_completion<RangeError>(ErrorType::IntlInvalidLanguageTag, code);
// c. Return ! CanonicalizeUnicodeLocaleId(code).
auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id);
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
return js_string(vm, move(canonicalized_tag));
}

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 12.1 The Intl.DisplayNames Constructor, https://tc39.es/ecma402/#sec-intl-displaynames-constructor
DisplayNamesConstructor::DisplayNamesConstructor(Realm& realm)
: NativeFunction(vm().names.DisplayNames.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.DisplayNames.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -28,7 +28,7 @@ void DisplayNamesConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 12.2.1 Intl.DisplayNames.prototype, https://tc39.es/ecma402/#sec-Intl.DisplayNames.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_display_names_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_display_names_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
@ -52,7 +52,7 @@ ThrowCompletionOr<Object*> DisplayNamesConstructor::construct(FunctionObject& ne
auto options_value = vm.argument(1);
// 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNames.prototype%", « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[LanguageDisplay]], [[Fields]] »).
auto* display_names = TRY(ordinary_create_from_constructor<DisplayNames>(vm, new_target, &GlobalObject::intl_display_names_prototype));
auto* display_names = TRY(ordinary_create_from_constructor<DisplayNames>(vm, new_target, &Intrinsics::intl_display_names_prototype));
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value));

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 12.3 Properties of the Intl.DisplayNames Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-displaynames-prototype-object
DisplayNamesPrototype::DisplayNamesPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -131,7 +131,7 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::resolved_options)
auto* display_names = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 8, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -402,7 +402,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// o. Let nf be ? Construct(%NumberFormat%, « durationFormat.[[Locale]], nfOpts »).
auto* number_format = static_cast<Intl::NumberFormat*>(TRY(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
auto* number_format = static_cast<NumberFormat*>(TRY(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, duration_format.locale()), number_format_options)));
// FIXME: durationFormat.[[NumberFormat]] is not a thing, the spec likely means 'nf' in this case
// p. Let num be ! FormatNumeric(durationFormat.[[NumberFormat]], value).
@ -431,7 +431,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
// t. Else,
else {
// i. Let pr be ? Construct(%PluralRules%, « durationFormat.[[Locale]] »).
auto* plural_rules = TRY(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
auto* plural_rules = TRY(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), js_string(vm, duration_format.locale())));
// ii. Let prv be ! ResolvePlural(pr, value).
auto plurality = resolve_plural(static_cast<PluralRules&>(*plural_rules), value);
@ -479,7 +479,7 @@ ThrowCompletionOr<Vector<PatternPartition>> partition_duration_format_pattern(VM
}
// 3. Let lf be ? Construct(%ListFormat%, « durationFormat.[[Locale]] »).
auto* list_format = static_cast<Intl::ListFormat*>(TRY(construct(vm, *realm.global_object().intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
auto* list_format = static_cast<ListFormat*>(TRY(construct(vm, *realm.intrinsics().intl_list_format_constructor(), js_string(vm, duration_format.locale()))));
// FIXME: CreatePartsFromList expects a list of strings and creates a list of Pattern Partition records, but we already created a list of Pattern Partition records
// so we try to hack something together from it that looks mostly right

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 1.2 The Intl.DurationFormat Constructor, https://tc39.es/proposal-intl-duration-format/#sec-intl-durationformat-constructor
DurationFormatConstructor::DurationFormatConstructor(Realm& realm)
: NativeFunction(vm().names.DurationFormat.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.DurationFormat.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -26,7 +26,7 @@ void DurationFormatConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 1.3.1 Intl.DurationFormat.prototype, https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_duration_format_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_duration_format_prototype(), 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
@ -49,7 +49,7 @@ ThrowCompletionOr<Object*> DurationFormatConstructor::construct(FunctionObject&
auto options_value = vm.argument(1);
// 2. Let durationFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%DurationFormatPrototype%", « [[InitializedDurationFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[YearsStyle]], [[YearsDisplay]], [[MonthsStyle]], [[MonthsDisplay]] , [[WeeksStyle]], [[WeeksDisplay]] , [[DaysStyle]], [[DaysDisplay]] , [[HoursStyle]], [[HoursDisplay]] , [[MinutesStyle]], [[MinutesDisplay]] , [[SecondsStyle]], [[SecondsDisplay]] , [[MillisecondsStyle]], [[MillisecondsDisplay]] , [[MicrosecondsStyle]], [[MicrosecondsDisplay]] , [[NanosecondsStyle]], [[NanosecondsDisplay]], [[FractionalDigits]] »).
auto* duration_format = TRY(ordinary_create_from_constructor<DurationFormat>(vm, new_target, &GlobalObject::intl_duration_format_prototype));
auto* duration_format = TRY(ordinary_create_from_constructor<DurationFormat>(vm, new_target, &Intrinsics::intl_duration_format_prototype));
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));

View file

@ -12,7 +12,7 @@ namespace JS::Intl {
// 1.4 Properties of the Intl.DurationFormat Prototype Object, https://tc39.es/proposal-intl-duration-format/#sec-properties-of-intl-durationformat-prototype-object
DurationFormatPrototype::DurationFormatPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -89,7 +89,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::format_to_parts)
auto const& part = formatted[n];
// a. Let obj be ! OrdinaryObjectCreate(%ObjectPrototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(obj, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -117,7 +117,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationFormatPrototype::resolved_options)
auto* duration_format = TRY(typed_this_object(vm));
// 3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 2, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -29,7 +29,7 @@ namespace JS::Intl {
// 8 The Intl Object, https://tc39.es/ecma402/#intl-object
Intl::Intl(Realm& realm)
: Object(*realm.global_object().object_prototype())
: Object(*realm.intrinsics().object_prototype())
{
}
@ -43,16 +43,16 @@ void Intl::initialize(Realm& realm)
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Intl"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.Collator, realm.global_object().intl_collator_constructor(), attr);
define_direct_property(vm.names.DateTimeFormat, realm.global_object().intl_date_time_format_constructor(), attr);
define_direct_property(vm.names.DisplayNames, realm.global_object().intl_display_names_constructor(), attr);
define_direct_property(vm.names.DurationFormat, realm.global_object().intl_duration_format_constructor(), attr);
define_direct_property(vm.names.ListFormat, realm.global_object().intl_list_format_constructor(), attr);
define_direct_property(vm.names.Locale, realm.global_object().intl_locale_constructor(), attr);
define_direct_property(vm.names.NumberFormat, realm.global_object().intl_number_format_constructor(), attr);
define_direct_property(vm.names.PluralRules, realm.global_object().intl_plural_rules_constructor(), attr);
define_direct_property(vm.names.RelativeTimeFormat, realm.global_object().intl_relative_time_format_constructor(), attr);
define_direct_property(vm.names.Segmenter, realm.global_object().intl_segmenter_constructor(), attr);
define_direct_property(vm.names.Collator, realm.intrinsics().intl_collator_constructor(), attr);
define_direct_property(vm.names.DateTimeFormat, realm.intrinsics().intl_date_time_format_constructor(), attr);
define_direct_property(vm.names.DisplayNames, realm.intrinsics().intl_display_names_constructor(), attr);
define_direct_property(vm.names.DurationFormat, realm.intrinsics().intl_duration_format_constructor(), attr);
define_direct_property(vm.names.ListFormat, realm.intrinsics().intl_list_format_constructor(), attr);
define_direct_property(vm.names.Locale, realm.intrinsics().intl_locale_constructor(), attr);
define_direct_property(vm.names.NumberFormat, realm.intrinsics().intl_number_format_constructor(), attr);
define_direct_property(vm.names.PluralRules, realm.intrinsics().intl_plural_rules_constructor(), attr);
define_direct_property(vm.names.RelativeTimeFormat, realm.intrinsics().intl_relative_time_format_constructor(), attr);
define_direct_property(vm.names.Segmenter, realm.intrinsics().intl_segmenter_constructor(), attr);
define_native_function(realm, vm.names.getCanonicalLocales, get_canonical_locales, 1, attr);
define_native_function(realm, vm.names.supportedValuesOf, supported_values_of, 1, attr);

View file

@ -217,7 +217,7 @@ Array* format_list_to_parts(VM& vm, ListFormat const& list_format, Vector<String
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 13.1 The Intl.ListFormat Constructor, https://tc39.es/ecma402/#sec-intl-listformat-constructor
ListFormatConstructor::ListFormatConstructor(Realm& realm)
: NativeFunction(vm().names.ListFormat.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.ListFormat.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -27,7 +27,7 @@ void ListFormatConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 13.2.1 Intl.ListFormat.prototype, https://tc39.es/ecma402/#sec-Intl.ListFormat.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_list_format_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_list_format_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
@ -51,7 +51,7 @@ ThrowCompletionOr<Object*> ListFormatConstructor::construct(FunctionObject& new_
auto options_value = vm.argument(1);
// 2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormat.prototype%", « [[InitializedListFormat]], [[Locale]], [[Type]], [[Style]], [[Templates]] »).
auto* list_format = TRY(ordinary_create_from_constructor<ListFormat>(vm, new_target, &GlobalObject::intl_list_format_prototype));
auto* list_format = TRY(ordinary_create_from_constructor<ListFormat>(vm, new_target, &Intrinsics::intl_list_format_prototype));
// 3. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locale_value));

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 13.3 Properties of the Intl.ListFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-listformat-prototype-object
ListFormatPrototype::ListFormatPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(ListFormatPrototype::resolved_options)
auto* list_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 10, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
Locale* Locale::create(Realm& realm, Unicode::LocaleID const& locale_id)
{
return realm.heap().allocate<Locale>(realm, locale_id, *realm.global_object().intl_locale_prototype());
return realm.heap().allocate<Locale>(realm, locale_id, *realm.intrinsics().intl_locale_prototype());
}
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects

View file

@ -65,7 +65,7 @@ static ThrowCompletionOr<String> apply_options_to_tag(VM& vm, StringView tag, Ob
auto region = TRY(get_string_option(vm, options, vm.names.region, Unicode::is_unicode_region_subtag));
// 10. Set tag to ! CanonicalizeUnicodeLocaleId(tag).
auto canonicalized_tag = Intl::canonicalize_unicode_locale_id(*locale_id);
auto canonicalized_tag = JS::Intl::canonicalize_unicode_locale_id(*locale_id);
// 11. Assert: tag matches the unicode_locale_id production.
locale_id = Unicode::parse_unicode_locale_id(canonicalized_tag);
@ -217,7 +217,7 @@ static LocaleAndKeys apply_unicode_extension_to_tag(StringView tag, LocaleAndKey
// 14.1 The Intl.Locale Constructor, https://tc39.es/ecma402/#sec-intl-locale-constructor
LocaleConstructor::LocaleConstructor(Realm& realm)
: NativeFunction(vm().names.Locale.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Locale.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -228,7 +228,7 @@ void LocaleConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 14.2.1 Intl.Locale.prototype, https://tc39.es/ecma402/#sec-Intl.Locale.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_locale_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_locale_prototype(), 0);
define_direct_property(vm.names.length, Value(1), Attribute::Configurable);
}
@ -257,7 +257,7 @@ ThrowCompletionOr<Object*> LocaleConstructor::construct(FunctionObject& new_targ
// a. Append [[Numeric]] as the last element of internalSlotsList.
// 6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, "%Locale.prototype%", internalSlotsList).
auto* locale = TRY(ordinary_create_from_constructor<Locale>(vm, new_target, &GlobalObject::intl_locale_prototype));
auto* locale = TRY(ordinary_create_from_constructor<Locale>(vm, new_target, &Intrinsics::intl_locale_prototype));
String tag;

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 14.3 Properties of the Intl.Locale Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-locale-prototype-object
LocalePrototype::LocalePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -258,7 +258,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::text_info)
auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, realm.global_object().object_prototype());
auto* info = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Let dir be ! CharacterDirectionOfLocale(loc).
auto direction = character_direction_of_locale(*locale_object);
@ -280,7 +280,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocalePrototype::week_info)
[[maybe_unused]] auto* locale_object = TRY(typed_this_object(vm));
// 3. Let info be ! ObjectCreate(%Object.prototype%).
auto* info = Object::create(realm, realm.global_object().object_prototype());
auto* info = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Let wi be ! WeekInfoOfLocale(loc).
auto week_info = week_info_of_locale(*locale_object);

View file

@ -922,7 +922,7 @@ Array* format_numeric_to_parts(VM& vm, NumberFormat& number_format, Mathematical
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));
@ -1837,7 +1837,7 @@ ThrowCompletionOr<Array*> format_numeric_range_to_parts(VM& vm, NumberFormat& nu
// 4. For each Record { [[Type]], [[Value]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 15.1 The Intl.NumberFormat Constructor, https://tc39.es/ecma402/#sec-intl-numberformat-constructor
NumberFormatConstructor::NumberFormatConstructor(Realm& realm)
: NativeFunction(vm().names.NumberFormat.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.NumberFormat.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -26,7 +26,7 @@ void NumberFormatConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 15.2.1 Intl.NumberFormat.prototype, https://tc39.es/ecma402/#sec-intl.numberformat.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_number_format_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_number_format_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.supportedLocalesOf, supported_locales_of, 1, attr);
@ -50,7 +50,7 @@ ThrowCompletionOr<Object*> NumberFormatConstructor::construct(FunctionObject& ne
auto options = vm.argument(1);
// 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormat.prototype%", « [[InitializedNumberFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[Unit]], [[UnitDisplay]], [[Currency]], [[CurrencyDisplay]], [[CurrencySign]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]], [[Notation]], [[CompactDisplay]], [[UseGrouping]], [[SignDisplay]], [[BoundFormat]] »).
auto* number_format = TRY(ordinary_create_from_constructor<NumberFormat>(vm, new_target, &GlobalObject::intl_number_format_prototype));
auto* number_format = TRY(ordinary_create_from_constructor<NumberFormat>(vm, new_target, &Intrinsics::intl_number_format_prototype));
// 3. Perform ? InitializeNumberFormat(numberFormat, locales, options).
TRY(initialize_number_format(vm, *number_format, locales, options));

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 1.1.4 Number Format Functions, https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/proposed.html#sec-number-format-functions
NumberFormatFunction* NumberFormatFunction::create(Realm& realm, NumberFormat& number_format)
{
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.global_object().function_prototype());
return realm.heap().allocate<NumberFormatFunction>(realm, number_format, *realm.intrinsics().function_prototype());
}
NumberFormatFunction::NumberFormatFunction(NumberFormat& number_format, Object& prototype)

View file

@ -15,7 +15,7 @@ namespace JS::Intl {
// 15.3 Properties of the Intl.NumberFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-numberformat-prototype-object
NumberFormatPrototype::NumberFormatPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -145,7 +145,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberFormatPrototype::resolved_options)
auto* number_format = TRY(typed_this_object(vm));
// 4. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 5. For each row of Table 11, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 16.1 The Intl.PluralRules Constructor, https://tc39.es/ecma402/#sec-intl-pluralrules-constructor
PluralRulesConstructor::PluralRulesConstructor(Realm& realm)
: NativeFunction(vm().names.PluralRules.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PluralRules.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -28,7 +28,7 @@ void PluralRulesConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 16.2.1 Intl.PluralRules.prototype, https://tc39.es/ecma402/#sec-intl.pluralrules.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_plural_rules_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_plural_rules_prototype(), 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
@ -51,7 +51,7 @@ ThrowCompletionOr<Object*> PluralRulesConstructor::construct(FunctionObject& new
auto options = vm.argument(1);
// 2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRules.prototype%", « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »).
auto* plural_rules = TRY(ordinary_create_from_constructor<PluralRules>(vm, new_target, &GlobalObject::intl_plural_rules_prototype));
auto* plural_rules = TRY(ordinary_create_from_constructor<PluralRules>(vm, new_target, &Intrinsics::intl_plural_rules_prototype));
// 3. Return ? InitializePluralRules(pluralRules, locales, options).
return TRY(initialize_plural_rules(vm, *plural_rules, locales, options));

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 16.3 Properties of the Intl.PluralRules Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-pluralrules-prototype-object
PluralRulesPrototype::PluralRulesPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -86,7 +86,7 @@ JS_DEFINE_NATIVE_FUNCTION(PluralRulesPrototype::resolved_options)
auto* plural_rules = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 13, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -257,7 +257,7 @@ ThrowCompletionOr<Array*> format_relative_time_to_parts(VM& vm, RelativeTimeForm
// 4. For each Record { [[Type]], [[Value]], [[Unit]] } part in parts, do
for (auto& part : parts) {
// a. Let O be OrdinaryObjectCreate(%Object.prototype%).
auto* object = Object::create(realm, realm.global_object().object_prototype());
auto* object = Object::create(realm, realm.intrinsics().object_prototype());
// b. Perform ! CreateDataPropertyOrThrow(O, "type", part.[[Type]]).
MUST(object->create_data_property_or_throw(vm.names.type, js_string(vm, part.type)));

View file

@ -20,7 +20,7 @@ namespace JS::Intl {
// 17.1 The Intl.RelativeTimeFormat Constructor, https://tc39.es/ecma402/#sec-intl-relativetimeformat-constructor
RelativeTimeFormatConstructor::RelativeTimeFormatConstructor(Realm& realm)
: NativeFunction(vm().names.RelativeTimeFormat.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.RelativeTimeFormat.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -31,7 +31,7 @@ void RelativeTimeFormatConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 17.2.1 Intl.RelativeTimeFormat.prototype, https://tc39.es/ecma402/#sec-Intl.RelativeTimeFormat.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_relative_time_format_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_relative_time_format_prototype(), 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
@ -54,7 +54,7 @@ ThrowCompletionOr<Object*> RelativeTimeFormatConstructor::construct(FunctionObje
auto options = vm.argument(1);
// 2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%RelativeTimeFormat.prototype%", « [[InitializedRelativeTimeFormat]], [[Locale]], [[DataLocale]], [[Style]], [[Numeric]], [[NumberFormat]], [[NumberingSystem]], [[PluralRules]] »).
auto* relative_time_format = TRY(ordinary_create_from_constructor<RelativeTimeFormat>(vm, new_target, &GlobalObject::intl_relative_time_format_prototype));
auto* relative_time_format = TRY(ordinary_create_from_constructor<RelativeTimeFormat>(vm, new_target, &Intrinsics::intl_relative_time_format_prototype));
// 3. Return ? InitializeRelativeTimeFormat(relativeTimeFormat, locales, options).
return TRY(initialize_relative_time_format(vm, *relative_time_format, locales, options));
@ -138,11 +138,11 @@ ThrowCompletionOr<RelativeTimeFormat*> initialize_relative_time_format(VM& vm, R
relative_time_format.set_numeric(numeric.as_string().string());
// 19. Let relativeTimeFormat.[[NumberFormat]] be ! Construct(%NumberFormat%, « locale »).
auto* number_format = MUST(construct(vm, *realm.global_object().intl_number_format_constructor(), js_string(vm, locale)));
auto* number_format = MUST(construct(vm, *realm.intrinsics().intl_number_format_constructor(), js_string(vm, locale)));
relative_time_format.set_number_format(static_cast<NumberFormat*>(number_format));
// 20. Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
auto* plural_rules = MUST(construct(vm, *realm.global_object().intl_plural_rules_constructor(), js_string(vm, locale)));
auto* plural_rules = MUST(construct(vm, *realm.intrinsics().intl_plural_rules_constructor(), js_string(vm, locale)));
relative_time_format.set_plural_rules(static_cast<PluralRules*>(plural_rules));
// 21. Return relativeTimeFormat.

View file

@ -12,7 +12,7 @@ namespace JS::Intl {
// 17.3 Properties of the Intl.RelativeTimeFormat Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-relativetimeformat-prototype-object
RelativeTimeFormatPrototype::RelativeTimeFormatPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -76,7 +76,7 @@ JS_DEFINE_NATIVE_FUNCTION(RelativeTimeFormatPrototype::resolved_options)
auto* relative_time_format = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 15, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -24,7 +24,7 @@ SegmentIterator* SegmentIterator::create(Realm& realm, Segmenter& segmenter, Utf
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
SegmentIterator::SegmentIterator(Realm& realm, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
: Object(*realm.global_object().intl_segment_iterator_prototype())
: Object(*realm.intrinsics().intl_segment_iterator_prototype())
, m_iterating_segmenter(segmenter)
, m_iterated_string(string)
, m_segments(segments)

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 18.6.2 The %SegmentIteratorPrototype% Object, https://tc39.es/ecma402/#sec-%segmentiteratorprototype%-object
SegmentIteratorPrototype::SegmentIteratorPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().iterator_prototype())
: PrototypeObject(*realm.intrinsics().iterator_prototype())
{
}

View file

@ -62,7 +62,7 @@ Object* create_segment_data_object(VM& vm, Segmenter const& segmenter, Utf16View
VERIFY(start_index < end_index);
// 5. Let result be OrdinaryObjectCreate(%Object.prototype%).
auto* result = Object::create(realm, realm.global_object().object_prototype());
auto* result = Object::create(realm, realm.intrinsics().object_prototype());
// 6. Let segment be the substring of string from startIndex to endIndex.
auto segment = string.substring_view(start_index, end_index - start_index);

View file

@ -16,7 +16,7 @@ namespace JS::Intl {
// 18.1 The Intl.Segmenter Constructor, https://tc39.es/ecma402/#sec-intl-segmenter-constructor
SegmenterConstructor::SegmenterConstructor(Realm& realm)
: NativeFunction(vm().names.Segmenter.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Segmenter.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -27,7 +27,7 @@ void SegmenterConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 18.2.1 Intl.Segmenter.prototype, https://tc39.es/ecma402/#sec-intl.segmenter.prototype
define_direct_property(vm.names.prototype, realm.global_object().intl_segmenter_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().intl_segmenter_prototype(), 0);
define_direct_property(vm.names.length, Value(0), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
@ -51,7 +51,7 @@ ThrowCompletionOr<Object*> SegmenterConstructor::construct(FunctionObject& new_t
// 2. Let internalSlotsList be « [[InitializedSegmenter]], [[Locale]], [[SegmenterGranularity]] ».
// 3. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%Segmenter.prototype%", internalSlotsList).
auto* segmenter = TRY(ordinary_create_from_constructor<Segmenter>(vm, new_target, &GlobalObject::intl_segmenter_prototype));
auto* segmenter = TRY(ordinary_create_from_constructor<Segmenter>(vm, new_target, &Intrinsics::intl_segmenter_prototype));
// 4. Let requestedLocales be ? CanonicalizeLocaleList(locales).
auto requested_locales = TRY(canonicalize_locale_list(vm, locales));

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 18.3 Properties of the Intl.Segmenter Prototype Object, https://tc39.es/ecma402/#sec-properties-of-intl-segmenter-prototype-object
SegmenterPrototype::SegmenterPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -41,7 +41,7 @@ JS_DEFINE_NATIVE_FUNCTION(SegmenterPrototype::resolved_options)
auto* segmenter = TRY(typed_this_object(vm));
// 3. Let options be OrdinaryObjectCreate(%Object.prototype%).
auto* options = Object::create(realm, realm.global_object().object_prototype());
auto* options = Object::create(realm, realm.intrinsics().object_prototype());
// 4. For each row of Table 16, except the header row, in table order, do
// a. Let p be the Property value of the current row.

View file

@ -23,7 +23,7 @@ Segments* Segments::create(Realm& realm, Segmenter& segmenter, Utf16String strin
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
Segments::Segments(Realm& realm, Segmenter& segmenter, Utf16String string)
: Object(*realm.global_object().intl_segments_prototype())
: Object(*realm.intrinsics().intl_segments_prototype())
, m_segments_segmenter(segmenter)
, m_segments_string(move(string))
{

View file

@ -13,7 +13,7 @@ namespace JS::Intl {
// 18.5.2 The %SegmentsPrototype% Object, https://tc39.es/ecma402/#sec-%segmentsprototype%-object
SegmentsPrototype::SegmentsPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}