2021-07-06 19:14:47 +01:00
|
|
|
/*
|
2022-08-27 00:54:55 +01:00
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
2021-07-06 19:14:47 +01:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2021-07-14 21:01:12 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/CalendarConstructor.h>
|
2021-07-15 23:20:43 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/DurationConstructor.h>
|
2021-07-07 17:41:37 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/InstantConstructor.h>
|
2021-07-06 19:33:20 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/Now.h>
|
2021-07-19 00:29:26 +03:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainDateConstructor.h>
|
2021-07-22 19:47:07 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainDateTimeConstructor.h>
|
2021-08-14 23:54:24 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainMonthDayConstructor.h>
|
2021-07-28 18:36:52 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainTimeConstructor.h>
|
2021-08-07 22:40:32 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/PlainYearMonthConstructor.h>
|
2021-07-06 19:14:47 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/Temporal.h>
|
2021-07-06 23:53:27 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/TimeZoneConstructor.h>
|
2021-08-01 17:20:11 +01:00
|
|
|
#include <LibJS/Runtime/Temporal/ZonedDateTimeConstructor.h>
|
2021-07-06 19:14:47 +01:00
|
|
|
|
|
|
|
namespace JS::Temporal {
|
|
|
|
|
|
|
|
// 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
|
2022-08-16 00:20:49 +01:00
|
|
|
Temporal::Temporal(Realm& realm)
|
2022-12-14 12:17:58 +01:00
|
|
|
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
|
2021-07-06 19:14:47 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-28 12:33:35 -05:00
|
|
|
ThrowCompletionOr<void> Temporal::initialize(Realm& realm)
|
2021-07-06 19:14:47 +01:00
|
|
|
{
|
2023-01-28 12:33:35 -05:00
|
|
|
MUST_OR_THROW_OOM(Base::initialize(realm));
|
2021-07-06 19:33:20 +01:00
|
|
|
|
|
|
|
auto& vm = this->vm();
|
|
|
|
|
2021-07-27 18:47:23 +01:00
|
|
|
// 1.1.1 Temporal [ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal-@@tostringtag
|
2023-02-09 09:00:14 -05:00
|
|
|
define_direct_property(*vm.well_known_symbol_to_string_tag(), MUST_OR_THROW_OOM(PrimitiveString::create(vm, "Temporal"sv)), Attribute::Configurable);
|
2021-07-27 18:47:23 +01:00
|
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
2023-01-28 13:39:44 -05:00
|
|
|
define_direct_property(vm.names.Now, MUST_OR_THROW_OOM(heap().allocate<Now>(realm, realm)), attr);
|
2022-11-24 09:43:53 -05:00
|
|
|
define_intrinsic_accessor(vm.names.Calendar, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_calendar_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.Duration, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_duration_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.Instant, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_instant_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.PlainDate, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_date_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.PlainDateTime, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_date_time_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.PlainMonthDay, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_month_day_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.PlainTime, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_time_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.PlainYearMonth, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_year_month_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.TimeZone, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_time_zone_constructor(); });
|
|
|
|
define_intrinsic_accessor(vm.names.ZonedDateTime, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_zoned_date_time_constructor(); });
|
2023-01-28 12:33:35 -05:00
|
|
|
|
|
|
|
return {};
|
2021-07-06 19:14:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|