1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 13:57:36 +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

@ -70,11 +70,11 @@ ThrowCompletionOr<Calendar*> create_temporal_calendar(VM& vm, String const& iden
// 2. If newTarget is not provided, set newTarget to %Temporal.Calendar%.
if (!new_target)
new_target = realm.global_object().temporal_calendar_constructor();
new_target = realm.intrinsics().temporal_calendar_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Calendar.prototype%", « [[InitializedTemporalCalendar]], [[Identifier]] »).
// 4. Set object.[[Identifier]] to identifier.
auto* object = TRY(ordinary_create_from_constructor<Calendar>(vm, *new_target, &GlobalObject::temporal_calendar_prototype, identifier));
auto* object = TRY(ordinary_create_from_constructor<Calendar>(vm, *new_target, &Intrinsics::temporal_calendar_prototype, identifier));
// 5. Return object.
return object;
@ -947,7 +947,7 @@ ThrowCompletionOr<Object*> default_merge_calendar_fields(VM& vm, Object const& f
auto& realm = *vm.current_realm();
// 1. Let merged be OrdinaryObjectCreate(%Object.prototype%).
auto* merged = Object::create(realm, realm.global_object().object_prototype());
auto* merged = Object::create(realm, realm.intrinsics().object_prototype());
// 2. Let fieldsKeys be ? EnumerableOwnPropertyNames(fields, key).
auto fields_keys = TRY(fields.enumerable_own_property_names(Object::PropertyKind::Key));

View file

@ -12,7 +12,7 @@ namespace JS::Temporal {
// 12.2 The Temporal.Calendar Constructor, https://tc39.es/proposal-temporal/#sec-temporal-calendar-constructor
CalendarConstructor::CalendarConstructor(Realm& realm)
: NativeFunction(vm().names.Calendar.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Calendar.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -23,7 +23,7 @@ void CalendarConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 12.3.1 Temporal.Calendar.prototype, https://tc39.es/proposal-temporal/#sec-temporal.calendar.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_calendar_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_calendar_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -21,7 +21,7 @@ namespace JS::Temporal {
// 12.4 Properties of the Temporal.Calendar Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-calendar-prototype-object
CalendarPrototype::CalendarPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}

View file

@ -334,7 +334,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, doub
// 2. If newTarget is not present, set newTarget to %Temporal.Duration%.
if (!new_target)
new_target = realm.global_object().temporal_duration_constructor();
new_target = realm.intrinsics().temporal_duration_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Duration.prototype%", « [[InitializedTemporalDuration]], [[Years]], [[Months]], [[Weeks]], [[Days]], [[Hours]], [[Minutes]], [[Seconds]], [[Milliseconds]], [[Microseconds]], [[Nanoseconds]] »).
// 4. Set object.[[Years]] to (𝔽(years)).
@ -347,7 +347,7 @@ ThrowCompletionOr<Duration*> create_temporal_duration(VM& vm, double years, doub
// 11. Set object.[[Milliseconds]] to (𝔽(milliseconds)).
// 12. Set object.[[Microseconds]] to (𝔽(microseconds)).
// 13. Set object.[[Nanoseconds]] to (𝔽(nanoseconds)).
auto* object = TRY(ordinary_create_from_constructor<Duration>(vm, *new_target, &GlobalObject::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
auto* object = TRY(ordinary_create_from_constructor<Duration>(vm, *new_target, &Intrinsics::temporal_duration_prototype, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds));
// 14. Return object.
return object;

View file

@ -15,7 +15,7 @@ namespace JS::Temporal {
// 7.1 The Temporal.Duration Constructor, https://tc39.es/proposal-temporal/#sec-temporal-duration-constructor
DurationConstructor::DurationConstructor(Realm& realm)
: NativeFunction(vm().names.Duration.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Duration.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -26,7 +26,7 @@ void DurationConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 7.2.1 Temporal.Duration.prototype, https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_duration_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_duration_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -16,7 +16,7 @@ namespace JS::Temporal {
// 7.3 Properties of the Temporal.Duration Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-duration-prototype-object
DurationPrototype::DurationPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}

View file

@ -61,11 +61,11 @@ ThrowCompletionOr<Instant*> create_temporal_instant(VM& vm, BigInt const& epoch_
// 3. If newTarget is not present, set newTarget to %Temporal.Instant%.
if (!new_target)
new_target = realm.global_object().temporal_instant_constructor();
new_target = realm.intrinsics().temporal_instant_constructor();
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.Instant.prototype%", « [[InitializedTemporalInstant]], [[Nanoseconds]] »).
// 5. Set object.[[Nanoseconds]] to epochNanoseconds.
auto* object = TRY(ordinary_create_from_constructor<Instant>(vm, *new_target, &GlobalObject::temporal_instant_prototype, epoch_nanoseconds));
auto* object = TRY(ordinary_create_from_constructor<Instant>(vm, *new_target, &Intrinsics::temporal_instant_prototype, epoch_nanoseconds));
// 6. Return object.
return object;

View file

@ -14,7 +14,7 @@ namespace JS::Temporal {
// 8.1 The Temporal.Instant Constructor, https://tc39.es/proposal-temporal/#sec-temporal-instant-constructor
InstantConstructor::InstantConstructor(Realm& realm)
: NativeFunction(vm().names.Instant.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.Instant.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -25,7 +25,7 @@ void InstantConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 8.2.1 Temporal.Instant.prototype, https://tc39.es/proposal-temporal/#sec-temporal.instant.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_instant_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_instant_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -20,7 +20,7 @@ namespace JS::Temporal {
// 8.3 Properties of the Temporal.Instant Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-instant-prototype-object
InstantPrototype::InstantPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}

View file

@ -21,7 +21,7 @@ namespace JS::Temporal {
// 2 The Temporal.Now Object, https://tc39.es/proposal-temporal/#sec-temporal-now-object
Now::Now(Realm& realm)
: Object(*realm.global_object().object_prototype())
: Object(*realm.intrinsics().object_prototype())
{
}

View file

@ -67,14 +67,14 @@ ThrowCompletionOr<PlainDate*> create_temporal_date(VM& vm, i32 iso_year, u8 iso_
// 7. If newTarget is not present, set newTarget to %Temporal.PlainDate%.
if (!new_target)
new_target = realm.global_object().temporal_plain_date_constructor();
new_target = realm.intrinsics().temporal_plain_date_constructor();
// 8. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
// 9. Set object.[[ISOYear]] to isoYear.
// 10. Set object.[[ISOMonth]] to isoMonth.
// 11. Set object.[[ISODay]] to isoDay.
// 12. Set object.[[Calendar]] to calendar.
auto* object = TRY(ordinary_create_from_constructor<PlainDate>(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar));
auto* object = TRY(ordinary_create_from_constructor<PlainDate>(vm, *new_target, &Intrinsics::temporal_plain_date_prototype, iso_year, iso_month, iso_day, calendar));
return object;
}

View file

@ -16,7 +16,7 @@ namespace JS::Temporal {
// 3.1 The Temporal.PlainDate Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindate-constructor
PlainDateConstructor::PlainDateConstructor(Realm& realm)
: NativeFunction(vm().names.PlainDate.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PlainDate.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -27,7 +27,7 @@ void PlainDateConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 3.2.1 Temporal.PlainDate.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaindate.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_date_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -21,7 +21,7 @@ namespace JS::Temporal {
// 3.3 Properties of the Temporal.PlainDate Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindate-prototype-object
PlainDatePrototype::PlainDatePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -326,7 +326,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDatePrototype::get_iso_fields)
auto* temporal_date = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalDate.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_date->calendar())));

View file

@ -249,7 +249,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
// 6. If newTarget is not present, set newTarget to %Temporal.PlainDateTime%.
if (!new_target)
new_target = realm.global_object().temporal_plain_date_time_constructor();
new_target = realm.intrinsics().temporal_plain_date_time_constructor();
// 7. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainDateTime.prototype%", « [[InitializedTemporalDateTime]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
// 8. Set object.[[ISOYear]] to isoYear.
@ -262,7 +262,7 @@ ThrowCompletionOr<PlainDateTime*> create_temporal_date_time(VM& vm, i32 iso_year
// 15. Set object.[[ISOMicrosecond]] to microsecond.
// 16. Set object.[[ISONanosecond]] to nanosecond.
// 17. Set object.[[Calendar]] to calendar.
auto* object = TRY(ordinary_create_from_constructor<PlainDateTime>(vm, *new_target, &GlobalObject::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
auto* object = TRY(ordinary_create_from_constructor<PlainDateTime>(vm, *new_target, &Intrinsics::temporal_plain_date_prototype, iso_year, iso_month, iso_day, hour, minute, second, millisecond, microsecond, nanosecond, calendar));
// 18. Return object.
return object;

View file

@ -16,7 +16,7 @@ namespace JS::Temporal {
// 5.1 The Temporal.PlainDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaindatetime-constructor
PlainDateTimeConstructor::PlainDateTimeConstructor(Realm& realm)
: NativeFunction(vm().names.PlainDateTime.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PlainDateTime.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -27,7 +27,7 @@ void PlainDateTimeConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 5.2.1 Temporal.PlainDateTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaindatetime.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_date_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -22,7 +22,7 @@ namespace JS::Temporal {
// 5.3 Properties of the Temporal.PlainDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaindatetime-prototype-object
PlainDateTimePrototype::PlainDateTimePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -735,7 +735,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainDateTimePrototype::get_iso_fields)
auto* date_time = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", dateTime.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&date_time->calendar())));

View file

@ -159,14 +159,14 @@ ThrowCompletionOr<PlainMonthDay*> create_temporal_month_day(VM& vm, u8 iso_month
// 5. If newTarget is not present, set newTarget to %Temporal.PlainMonthDay%.
if (!new_target)
new_target = realm.global_object().temporal_plain_month_day_constructor();
new_target = realm.intrinsics().temporal_plain_month_day_constructor();
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainMonthDay.prototype%", « [[InitializedTemporalMonthDay]], [[ISOMonth]], [[ISODay]], [[ISOYear]], [[Calendar]] »).
// 7. Set object.[[ISOMonth]] to isoMonth.
// 8. Set object.[[ISODay]] to isoDay.
// 9. Set object.[[Calendar]] to calendar.
// 10. Set object.[[ISOYear]] to referenceISOYear.
auto* object = TRY(ordinary_create_from_constructor<PlainMonthDay>(vm, *new_target, &GlobalObject::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
auto* object = TRY(ordinary_create_from_constructor<PlainMonthDay>(vm, *new_target, &Intrinsics::temporal_plain_month_day_prototype, iso_month, iso_day, reference_iso_year, calendar));
// 11. Return object.
return object;

View file

@ -15,7 +15,7 @@ namespace JS::Temporal {
// 10.1 The Temporal.PlainMonthDay Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainmonthday-constructor
PlainMonthDayConstructor::PlainMonthDayConstructor(Realm& realm)
: NativeFunction(vm().names.PlainMonthDay.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PlainMonthDay.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -26,7 +26,7 @@ void PlainMonthDayConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 10.2.1 Temporal.PlainMonthDay.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plainmonthday.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_month_day_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_month_day_prototype(), 0);
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);

View file

@ -16,7 +16,7 @@ namespace JS::Temporal {
// 10.3 Properties of the Temporal.PlainMonthDay Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainmonthday-prototype-object
PlainMonthDayPrototype::PlainMonthDayPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -260,7 +260,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainMonthDayPrototype::get_iso_fields)
auto* month_day = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", monthDay.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&month_day->calendar())));

View file

@ -320,7 +320,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u
// 3. If newTarget is not present, set newTarget to %Temporal.PlainTime%.
if (!new_target)
new_target = realm.global_object().temporal_plain_time_constructor();
new_target = realm.intrinsics().temporal_plain_time_constructor();
// 4. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainTime.prototype%", « [[InitializedTemporalTime]], [[ISOHour]], [[ISOMinute]], [[ISOSecond]], [[ISOMillisecond]], [[ISOMicrosecond]], [[ISONanosecond]], [[Calendar]] »).
// 5. Set object.[[ISOHour]] to hour.
@ -330,7 +330,7 @@ ThrowCompletionOr<PlainTime*> create_temporal_time(VM& vm, u8 hour, u8 minute, u
// 9. Set object.[[ISOMicrosecond]] to microsecond.
// 10. Set object.[[ISONanosecond]] to nanosecond.
// 11. Set object.[[Calendar]] to ! GetISO8601Calendar().
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(vm, *new_target, &GlobalObject::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm)));
auto* object = TRY(ordinary_create_from_constructor<PlainTime>(vm, *new_target, &Intrinsics::temporal_plain_time_prototype, hour, minute, second, millisecond, microsecond, nanosecond, *get_iso8601_calendar(vm)));
// 12. Return object.
return object;

View file

@ -14,7 +14,7 @@ namespace JS::Temporal {
// 4.1 The Temporal.PlainTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plaintime-constructor
PlainTimeConstructor::PlainTimeConstructor(Realm& realm)
: NativeFunction(vm().names.PlainTime.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PlainTime.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -25,7 +25,7 @@ void PlainTimeConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 4.2.1 Temporal.PlainTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -21,7 +21,7 @@ namespace JS::Temporal {
// 4.3 Properties of the Temporal.PlainTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plaintime-prototype-object
PlainTimePrototype::PlainTimePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -425,7 +425,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::get_iso_fields)
auto* temporal_time = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", temporalTime.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&temporal_time->calendar())));

View file

@ -200,14 +200,14 @@ ThrowCompletionOr<PlainYearMonth*> create_temporal_year_month(VM& vm, i32 iso_ye
// 5. If newTarget is not present, set newTarget to %Temporal.PlainYearMonth%.
if (!new_target)
new_target = realm.global_object().temporal_plain_year_month_constructor();
new_target = realm.intrinsics().temporal_plain_year_month_constructor();
// 6. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.PlainYearMonth.prototype%", « [[InitializedTemporalYearMonth]], [[ISOYear]], [[ISOMonth]], [[ISODay]], [[Calendar]] »).
// 7. Set object.[[ISOYear]] to isoYear.
// 8. Set object.[[ISOMonth]] to isoMonth.
// 9. Set object.[[Calendar]] to calendar.
// 10. Set object.[[ISODay]] to referenceISODay.
auto* object = TRY(ordinary_create_from_constructor<PlainYearMonth>(vm, *new_target, &GlobalObject::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar));
auto* object = TRY(ordinary_create_from_constructor<PlainYearMonth>(vm, *new_target, &Intrinsics::temporal_plain_year_month_prototype, iso_year, iso_month, reference_iso_day, calendar));
// 11. Return object.
return object;

View file

@ -16,7 +16,7 @@ namespace JS::Temporal {
// 9.1 The Temporal.PlainYearMonth Constructor, https://tc39.es/proposal-temporal/#sec-temporal-plainyearmonth-constructor
PlainYearMonthConstructor::PlainYearMonthConstructor(Realm& realm)
: NativeFunction(vm().names.PlainYearMonth.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.PlainYearMonth.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -27,7 +27,7 @@ void PlainYearMonthConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 9.2.1 Temporal.PlainYearMonth.prototype, https://tc39.es/proposal-temporal/#sec-temporal.plainyearmonth.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_year_month_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_plain_year_month_prototype(), 0);
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);

View file

@ -18,7 +18,7 @@ namespace JS::Temporal {
// 9.3 Properties of the Temporal.PlainYearMonth Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-plainyearmonth-prototype-object
PlainYearMonthPrototype::PlainYearMonthPrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -427,7 +427,7 @@ JS_DEFINE_NATIVE_FUNCTION(PlainYearMonthPrototype::get_iso_fields)
auto* year_month = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Perform ! CreateDataPropertyOrThrow(fields, "calendar", yearMonth.[[Calendar]]).
MUST(fields->create_data_property_or_throw(vm.names.calendar, Value(&year_month->calendar())));

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -22,7 +22,7 @@ namespace JS::Temporal {
// 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
Temporal::Temporal(Realm& realm)
: Object(*realm.global_object().object_prototype())
: Object(*realm.intrinsics().object_prototype())
{
}
@ -37,16 +37,16 @@ void Temporal::initialize(Realm& realm)
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.Now, heap().allocate<Now>(realm, realm), attr);
define_direct_property(vm.names.Calendar, realm.global_object().temporal_calendar_constructor(), attr);
define_direct_property(vm.names.Duration, realm.global_object().temporal_duration_constructor(), attr);
define_direct_property(vm.names.Instant, realm.global_object().temporal_instant_constructor(), attr);
define_direct_property(vm.names.PlainDate, realm.global_object().temporal_plain_date_constructor(), attr);
define_direct_property(vm.names.PlainDateTime, realm.global_object().temporal_plain_date_time_constructor(), attr);
define_direct_property(vm.names.PlainMonthDay, realm.global_object().temporal_plain_month_day_constructor(), attr);
define_direct_property(vm.names.PlainTime, realm.global_object().temporal_plain_time_constructor(), attr);
define_direct_property(vm.names.PlainYearMonth, realm.global_object().temporal_plain_year_month_constructor(), attr);
define_direct_property(vm.names.TimeZone, realm.global_object().temporal_time_zone_constructor(), attr);
define_direct_property(vm.names.ZonedDateTime, realm.global_object().temporal_zoned_date_time_constructor(), attr);
define_direct_property(vm.names.Calendar, realm.intrinsics().temporal_calendar_constructor(), attr);
define_direct_property(vm.names.Duration, realm.intrinsics().temporal_duration_constructor(), attr);
define_direct_property(vm.names.Instant, realm.intrinsics().temporal_instant_constructor(), attr);
define_direct_property(vm.names.PlainDate, realm.intrinsics().temporal_plain_date_constructor(), attr);
define_direct_property(vm.names.PlainDateTime, realm.intrinsics().temporal_plain_date_time_constructor(), attr);
define_direct_property(vm.names.PlainMonthDay, realm.intrinsics().temporal_plain_month_day_constructor(), attr);
define_direct_property(vm.names.PlainTime, realm.intrinsics().temporal_plain_time_constructor(), attr);
define_direct_property(vm.names.PlainYearMonth, realm.intrinsics().temporal_plain_year_month_constructor(), attr);
define_direct_property(vm.names.TimeZone, realm.intrinsics().temporal_time_zone_constructor(), attr);
define_direct_property(vm.names.ZonedDateTime, realm.intrinsics().temporal_zoned_date_time_constructor(), attr);
}
}

View file

@ -69,10 +69,10 @@ ThrowCompletionOr<TimeZone*> create_temporal_time_zone(VM& vm, String const& ide
// 1. If newTarget is not present, set newTarget to %Temporal.TimeZone%.
if (!new_target)
new_target = realm.global_object().temporal_time_zone_constructor();
new_target = realm.intrinsics().temporal_time_zone_constructor();
// 2. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.TimeZone.prototype%", « [[InitializedTemporalTimeZone]], [[Identifier]], [[OffsetNanoseconds]] »).
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype));
auto* object = TRY(ordinary_create_from_constructor<TimeZone>(vm, *new_target, &Intrinsics::temporal_time_zone_prototype));
// 3. Let offsetNanosecondsResult be Completion(ParseTimeZoneOffsetString(identifier)).
auto offset_nanoseconds_result = parse_time_zone_offset_string(vm, identifier);

View file

@ -12,7 +12,7 @@ namespace JS::Temporal {
// 11.2 The Temporal.TimeZone Constructor, https://tc39.es/proposal-temporal/#sec-temporal-timezone-constructor
TimeZoneConstructor::TimeZoneConstructor(Realm& realm)
: NativeFunction(vm().names.TimeZone.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.TimeZone.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -23,7 +23,7 @@ void TimeZoneConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 11.3.1 Temporal.TimeZone.prototype, https://tc39.es/proposal-temporal/#sec-temporal.timezone.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_time_zone_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_time_zone_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -18,7 +18,7 @@ namespace JS::Temporal {
// 11.4 Properties of the Temporal.TimeZone Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-timezone-prototype-object
TimeZonePrototype::TimeZonePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}

View file

@ -273,13 +273,13 @@ ThrowCompletionOr<ZonedDateTime*> create_temporal_zoned_date_time(VM& vm, BigInt
// 2. If newTarget is not present, set newTarget to %Temporal.ZonedDateTime%.
if (!new_target)
new_target = realm.global_object().temporal_zoned_date_time_constructor();
new_target = realm.intrinsics().temporal_zoned_date_time_constructor();
// 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, "%Temporal.ZonedDateTime.prototype%", « [[InitializedTemporalZonedDateTime]], [[Nanoseconds]], [[TimeZone]], [[Calendar]] »).
// 4. Set object.[[Nanoseconds]] to epochNanoseconds.
// 5. Set object.[[TimeZone]] to timeZone.
// 6. Set object.[[Calendar]] to calendar.
auto* object = TRY(ordinary_create_from_constructor<ZonedDateTime>(vm, *new_target, &GlobalObject::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar));
auto* object = TRY(ordinary_create_from_constructor<ZonedDateTime>(vm, *new_target, &Intrinsics::temporal_time_zone_prototype, epoch_nanoseconds, time_zone, calendar));
// 7. Return object.
return object;

View file

@ -17,7 +17,7 @@ namespace JS::Temporal {
// 6.1 The Temporal.ZonedDateTime Constructor, https://tc39.es/proposal-temporal/#sec-temporal-zoneddatetime-constructor
ZonedDateTimeConstructor::ZonedDateTimeConstructor(Realm& realm)
: NativeFunction(vm().names.ZonedDateTime.as_string(), *realm.global_object().function_prototype())
: NativeFunction(vm().names.ZonedDateTime.as_string(), *realm.intrinsics().function_prototype())
{
}
@ -28,7 +28,7 @@ void ZonedDateTimeConstructor::initialize(Realm& realm)
auto& vm = this->vm();
// 6.2.1 Temporal.ZonedDateTime.prototype, https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype
define_direct_property(vm.names.prototype, realm.global_object().temporal_zoned_date_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.intrinsics().temporal_zoned_date_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(realm, vm.names.from, from, 1, attr);

View file

@ -21,7 +21,7 @@ namespace JS::Temporal {
// 6.3 Properties of the Temporal.ZonedDateTime Prototype Object, https://tc39.es/proposal-temporal/#sec-properties-of-the-temporal-zoneddatetime-prototype-object
ZonedDateTimePrototype::ZonedDateTimePrototype(Realm& realm)
: PrototypeObject(*realm.global_object().object_prototype())
: PrototypeObject(*realm.intrinsics().object_prototype())
{
}
@ -1291,7 +1291,7 @@ JS_DEFINE_NATIVE_FUNCTION(ZonedDateTimePrototype::get_iso_fields)
auto* zoned_date_time = TRY(typed_this_object(vm));
// 3. Let fields be OrdinaryObjectCreate(%Object.prototype%).
auto* fields = Object::create(realm, realm.global_object().object_prototype());
auto* fields = Object::create(realm, realm.intrinsics().object_prototype());
// 4. Let timeZone be zonedDateTime.[[TimeZone]].
auto& time_zone = zoned_date_time->time_zone();