Temporal.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2021, Linus Groh <linusg@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Runtime/GlobalObject.h>
  7. #include <LibJS/Runtime/Temporal/CalendarConstructor.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/PlainTimeConstructor.h>
  14. #include <LibJS/Runtime/Temporal/Temporal.h>
  15. #include <LibJS/Runtime/Temporal/TimeZoneConstructor.h>
  16. #include <LibJS/Runtime/Temporal/ZonedDateTimeConstructor.h>
  17. namespace JS::Temporal {
  18. // 1 The Temporal Object, https://tc39.es/proposal-temporal/#sec-temporal-objects
  19. Temporal::Temporal(GlobalObject& global_object)
  20. : Object(*global_object.object_prototype())
  21. {
  22. }
  23. void Temporal::initialize(GlobalObject& global_object)
  24. {
  25. Object::initialize(global_object);
  26. auto& vm = this->vm();
  27. // 1.1.1 Temporal [ @@toStringTag ], https://tc39.es/proposal-temporal/#sec-temporal-@@tostringtag
  28. define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "Temporal"), Attribute::Configurable);
  29. u8 attr = Attribute::Writable | Attribute::Configurable;
  30. define_direct_property(vm.names.Now, heap().allocate<Now>(global_object, global_object), attr);
  31. define_direct_property(vm.names.Calendar, global_object.temporal_calendar_constructor(), attr);
  32. define_direct_property(vm.names.Duration, global_object.temporal_duration_constructor(), attr);
  33. define_direct_property(vm.names.Instant, global_object.temporal_instant_constructor(), attr);
  34. define_direct_property(vm.names.PlainDate, global_object.temporal_plain_date_constructor(), attr);
  35. define_direct_property(vm.names.PlainDateTime, global_object.temporal_plain_date_time_constructor(), attr);
  36. define_direct_property(vm.names.PlainTime, global_object.temporal_plain_time_constructor(), attr);
  37. define_direct_property(vm.names.TimeZone, global_object.temporal_time_zone_constructor(), attr);
  38. define_direct_property(vm.names.ZonedDateTime, global_object.temporal_zoned_date_time_constructor(), attr);
  39. }
  40. }