Temporal.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  3. * Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibJS/Runtime/GlobalObject.h>
  8. #include <LibJS/Runtime/Temporal/DurationConstructor.h>
  9. #include <LibJS/Runtime/Temporal/InstantConstructor.h>
  10. #include <LibJS/Runtime/Temporal/Now.h>
  11. #include <LibJS/Runtime/Temporal/PlainDateConstructor.h>
  12. #include <LibJS/Runtime/Temporal/PlainDateTimeConstructor.h>
  13. #include <LibJS/Runtime/Temporal/PlainMonthDayConstructor.h>
  14. #include <LibJS/Runtime/Temporal/PlainTimeConstructor.h>
  15. #include <LibJS/Runtime/Temporal/PlainYearMonthConstructor.h>
  16. #include <LibJS/Runtime/Temporal/Temporal.h>
  17. namespace JS::Temporal {
  18. GC_DEFINE_ALLOCATOR(Temporal);
  19. // 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
  20. Temporal::Temporal(Realm& realm)
  21. : Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
  22. {
  23. }
  24. void Temporal::initialize(Realm& realm)
  25. {
  26. Base::initialize(realm);
  27. auto& vm = this->vm();
  28. // 1.1.1 Temporal [ %Symbol.toStringTag% ], https://tc39.es/proposal-temporal/#sec-temporal-%symbol.tostringtag%
  29. define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal"_string), Attribute::Configurable);
  30. u8 attr = Attribute::Writable | Attribute::Configurable;
  31. define_direct_property(vm.names.Now, realm.create<Now>(realm), attr);
  32. define_intrinsic_accessor(vm.names.Duration, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_duration_constructor(); });
  33. define_intrinsic_accessor(vm.names.Instant, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_instant_constructor(); });
  34. define_intrinsic_accessor(vm.names.PlainDate, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_date_constructor(); });
  35. define_intrinsic_accessor(vm.names.PlainDateTime, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_date_time_constructor(); });
  36. define_intrinsic_accessor(vm.names.PlainMonthDay, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_month_day_constructor(); });
  37. define_intrinsic_accessor(vm.names.PlainTime, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_time_constructor(); });
  38. define_intrinsic_accessor(vm.names.PlainYearMonth, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_year_month_constructor(); });
  39. }
  40. }