Temporal.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/PlainMonthDayConstructor.h>
  10. #include <LibJS/Runtime/Temporal/Temporal.h>
  11. namespace JS::Temporal {
  12. GC_DEFINE_ALLOCATOR(Temporal);
  13. // 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
  14. Temporal::Temporal(Realm& realm)
  15. : Object(ConstructWithPrototypeTag::Tag, realm.intrinsics().object_prototype())
  16. {
  17. }
  18. void Temporal::initialize(Realm& realm)
  19. {
  20. Base::initialize(realm);
  21. auto& vm = this->vm();
  22. // 1.1.1 Temporal [ %Symbol.toStringTag% ], https://tc39.es/proposal-temporal/#sec-temporal-%symbol.tostringtag%
  23. define_direct_property(vm.well_known_symbol_to_string_tag(), PrimitiveString::create(vm, "Temporal"_string), Attribute::Configurable);
  24. u8 attr = Attribute::Writable | Attribute::Configurable;
  25. define_intrinsic_accessor(vm.names.Duration, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_duration_constructor(); });
  26. define_intrinsic_accessor(vm.names.PlainMonthDay, attr, [](auto& realm) -> Value { return realm.intrinsics().temporal_plain_month_day_constructor(); });
  27. }
  28. }