Temporal.cpp 1.7 KB

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