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

LibJS+LibWeb: Replace GlobalObject with Realm in initialize() functions

This is a continuation of the previous commit.

Calling initialize() is the first thing that's done after allocating a
cell on the JS heap - and in the common case of allocating an object,
that's where properties are assigned and intrinsics occasionally
accessed.
Since those are supposed to live on the realm eventually, this is
another step into that direction.
This commit is contained in:
Linus Groh 2022-08-16 00:20:49 +01:00
parent ecd163bdf1
commit 5dd5896588
304 changed files with 608 additions and 603 deletions

View file

@ -16,14 +16,14 @@ CalendarConstructor::CalendarConstructor(Realm& realm)
{
}
void CalendarConstructor::initialize(GlobalObject& global_object)
void CalendarConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_calendar_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_calendar_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class CalendarConstructor final : public NativeFunction {
public:
explicit CalendarConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~CalendarConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -25,9 +25,9 @@ CalendarPrototype::CalendarPrototype(Realm& realm)
{
}
void CalendarPrototype::initialize(GlobalObject& global_object)
void CalendarPrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class CalendarPrototype final : public PrototypeObject<CalendarPrototype, Calend
public:
explicit CalendarPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~CalendarPrototype() override = default;
private:

View file

@ -19,14 +19,14 @@ DurationConstructor::DurationConstructor(Realm& realm)
{
}
void DurationConstructor::initialize(GlobalObject& global_object)
void DurationConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_duration_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_duration_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class DurationConstructor final : public NativeFunction {
public:
explicit DurationConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~DurationConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -20,9 +20,9 @@ DurationPrototype::DurationPrototype(Realm& realm)
{
}
void DurationPrototype::initialize(GlobalObject& global_object)
void DurationPrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class DurationPrototype final : public PrototypeObject<DurationPrototype, Durati
public:
explicit DurationPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~DurationPrototype() override = default;
private:

View file

@ -18,14 +18,14 @@ InstantConstructor::InstantConstructor(Realm& realm)
{
}
void InstantConstructor::initialize(GlobalObject& global_object)
void InstantConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_instant_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_instant_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class InstantConstructor final : public NativeFunction {
public:
explicit InstantConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~InstantConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -24,9 +24,9 @@ InstantPrototype::InstantPrototype(Realm& realm)
{
}
void InstantPrototype::initialize(GlobalObject& global_object)
void InstantPrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class InstantPrototype final : public PrototypeObject<InstantPrototype, Instant>
public:
explicit InstantPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~InstantPrototype() override = default;
private:

View file

@ -25,9 +25,9 @@ Now::Now(Realm& realm)
{
}
void Now::initialize(GlobalObject& global_object)
void Now::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class Now final : public Object {
public:
explicit Now(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~Now() override = default;
private:

View file

@ -20,14 +20,14 @@ PlainDateConstructor::PlainDateConstructor(Realm& realm)
{
}
void PlainDateConstructor::initialize(GlobalObject& global_object)
void PlainDateConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_plain_date_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class PlainDateConstructor final : public NativeFunction {
public:
explicit PlainDateConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainDateConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -25,9 +25,9 @@ PlainDatePrototype::PlainDatePrototype(Realm& realm)
{
}
void PlainDatePrototype::initialize(GlobalObject& global_object)
void PlainDatePrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class PlainDatePrototype final : public PrototypeObject<PlainDatePrototype, Plai
public:
explicit PlainDatePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainDatePrototype() override = default;
private:

View file

@ -20,14 +20,14 @@ PlainDateTimeConstructor::PlainDateTimeConstructor(Realm& realm)
{
}
void PlainDateTimeConstructor::initialize(GlobalObject& global_object)
void PlainDateTimeConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_plain_date_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_date_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class PlainDateTimeConstructor final : public NativeFunction {
public:
explicit PlainDateTimeConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainDateTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -26,9 +26,9 @@ PlainDateTimePrototype::PlainDateTimePrototype(Realm& realm)
{
}
void PlainDateTimePrototype::initialize(GlobalObject& global_object)
void PlainDateTimePrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class PlainDateTimePrototype final : public PrototypeObject<PlainDateTimePrototy
public:
explicit PlainDateTimePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainDateTimePrototype() override = default;
private:

View file

@ -19,14 +19,14 @@ PlainMonthDayConstructor::PlainMonthDayConstructor(Realm& realm)
{
}
void PlainMonthDayConstructor::initialize(GlobalObject& global_object)
void PlainMonthDayConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_plain_month_day_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_month_day_prototype(), 0);
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);

View file

@ -15,7 +15,7 @@ class PlainMonthDayConstructor final : public NativeFunction {
public:
explicit PlainMonthDayConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainMonthDayConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -20,9 +20,9 @@ PlainMonthDayPrototype::PlainMonthDayPrototype(Realm& realm)
{
}
void PlainMonthDayPrototype::initialize(GlobalObject& global_object)
void PlainMonthDayPrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class PlainMonthDayPrototype final : public PrototypeObject<PlainMonthDayPrototy
public:
explicit PlainMonthDayPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainMonthDayPrototype() override = default;
private:

View file

@ -18,14 +18,14 @@ PlainTimeConstructor::PlainTimeConstructor(Realm& realm)
{
}
void PlainTimeConstructor::initialize(GlobalObject& global_object)
void PlainTimeConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_plain_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class PlainTimeConstructor final : public NativeFunction {
public:
explicit PlainTimeConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -25,9 +25,9 @@ PlainTimePrototype::PlainTimePrototype(Realm& realm)
{
}
void PlainTimePrototype::initialize(GlobalObject& global_object)
void PlainTimePrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class PlainTimePrototype final : public PrototypeObject<PlainTimePrototype, Plai
public:
explicit PlainTimePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainTimePrototype() override = default;
private:

View file

@ -20,14 +20,14 @@ PlainYearMonthConstructor::PlainYearMonthConstructor(Realm& realm)
{
}
void PlainYearMonthConstructor::initialize(GlobalObject& global_object)
void PlainYearMonthConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_plain_year_month_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_plain_year_month_prototype(), 0);
define_direct_property(vm.names.length, Value(2), Attribute::Configurable);

View file

@ -15,7 +15,7 @@ class PlainYearMonthConstructor final : public NativeFunction {
public:
explicit PlainYearMonthConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainYearMonthConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -22,9 +22,9 @@ PlainYearMonthPrototype::PlainYearMonthPrototype(Realm& realm)
{
}
void PlainYearMonthPrototype::initialize(GlobalObject& global_object)
void PlainYearMonthPrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class PlainYearMonthPrototype final : public PrototypeObject<PlainYearMonthProto
public:
explicit PlainYearMonthPrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~PlainYearMonthPrototype() override = default;
private:

View file

@ -26,28 +26,27 @@ Temporal::Temporal(Realm& realm)
{
}
void Temporal::initialize(GlobalObject& global_object)
void Temporal::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();
auto& realm = *global_object.associated_realm();
// 1.1.1 Temporal [ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal-@@tostringtag
define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Temporal"), Attribute::Configurable);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_direct_property(vm.names.Now, heap().allocate<Now>(global_object, realm), attr);
define_direct_property(vm.names.Calendar, global_object.temporal_calendar_constructor(), attr);
define_direct_property(vm.names.Duration, global_object.temporal_duration_constructor(), attr);
define_direct_property(vm.names.Instant, global_object.temporal_instant_constructor(), attr);
define_direct_property(vm.names.PlainDate, global_object.temporal_plain_date_constructor(), attr);
define_direct_property(vm.names.PlainDateTime, global_object.temporal_plain_date_time_constructor(), attr);
define_direct_property(vm.names.PlainMonthDay, global_object.temporal_plain_month_day_constructor(), attr);
define_direct_property(vm.names.PlainTime, global_object.temporal_plain_time_constructor(), attr);
define_direct_property(vm.names.PlainYearMonth, global_object.temporal_plain_year_month_constructor(), attr);
define_direct_property(vm.names.TimeZone, global_object.temporal_time_zone_constructor(), attr);
define_direct_property(vm.names.ZonedDateTime, global_object.temporal_zoned_date_time_constructor(), attr);
define_direct_property(vm.names.Now, heap().allocate<Now>(realm.global_object(), 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);
}
}

View file

@ -15,7 +15,7 @@ class Temporal final : public Object {
public:
explicit Temporal(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~Temporal() override = default;
};

View file

@ -16,14 +16,14 @@ TimeZoneConstructor::TimeZoneConstructor(Realm& realm)
{
}
void TimeZoneConstructor::initialize(GlobalObject& global_object)
void TimeZoneConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_time_zone_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_time_zone_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class TimeZoneConstructor final : public NativeFunction {
public:
explicit TimeZoneConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~TimeZoneConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -22,9 +22,9 @@ TimeZonePrototype::TimeZonePrototype(Realm& realm)
{
}
void TimeZonePrototype::initialize(GlobalObject& global_object)
void TimeZonePrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class TimeZonePrototype final : public PrototypeObject<TimeZonePrototype, TimeZo
public:
explicit TimeZonePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~TimeZonePrototype() override = default;
private:

View file

@ -21,14 +21,14 @@ ZonedDateTimeConstructor::ZonedDateTimeConstructor(Realm& realm)
{
}
void ZonedDateTimeConstructor::initialize(GlobalObject& global_object)
void ZonedDateTimeConstructor::initialize(Realm& realm)
{
NativeFunction::initialize(global_object);
NativeFunction::initialize(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, global_object.temporal_zoned_date_time_prototype(), 0);
define_direct_property(vm.names.prototype, realm.global_object().temporal_zoned_date_time_prototype(), 0);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.from, from, 1, attr);

View file

@ -15,7 +15,7 @@ class ZonedDateTimeConstructor final : public NativeFunction {
public:
explicit ZonedDateTimeConstructor(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~ZonedDateTimeConstructor() override = default;
virtual ThrowCompletionOr<Value> call() override;

View file

@ -25,9 +25,9 @@ ZonedDateTimePrototype::ZonedDateTimePrototype(Realm& realm)
{
}
void ZonedDateTimePrototype::initialize(GlobalObject& global_object)
void ZonedDateTimePrototype::initialize(Realm& realm)
{
Object::initialize(global_object);
Object::initialize(realm);
auto& vm = this->vm();

View file

@ -16,7 +16,7 @@ class ZonedDateTimePrototype final : public PrototypeObject<ZonedDateTimePrototy
public:
explicit ZonedDateTimePrototype(Realm&);
virtual void initialize(GlobalObject&) override;
virtual void initialize(Realm&) override;
virtual ~ZonedDateTimePrototype() override = default;
private: