Temporal.cpp 1.5 KB

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