TimeZoneMethods.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. #include <LibJS/Forward.h>
  9. #include <LibJS/Heap/GCPtr.h>
  10. namespace JS::Temporal {
  11. // 11.5.1 Time Zone Methods Records, https://tc39.es/proposal-temporal/#sec-temporal-time-zone-methods-records
  12. struct TimeZoneMethods {
  13. // The time zone object, or a string indicating a built-in time zone.
  14. Variant<String, NonnullGCPtr<Object>> receiver; // [[Reciever]]
  15. // The time zone's getOffsetNanosecondsFor method. For a built-in time zone this is always %Temporal.TimeZone.prototype.getOffsetNanosecondsFor%.
  16. GCPtr<FunctionObject> get_offset_nanoseconds_for; // [[GetOffsetNanosecondsFor]]
  17. // The time zone's getPossibleInstantsFor method. For a built-in time zone this is always %Temporal.TimeZone.prototype.getPossibleInstantsFor%.
  18. GCPtr<FunctionObject> get_possible_instants_for; // [[GetPossibleInstantsFor]]
  19. };
  20. #define JS_ENUMERATE_TIME_ZONE_METHODS \
  21. __JS_ENUMERATE(GetOffsetNanosecondsFor, getOffsetNanosecondsFor, get_offset_nanoseconds_for) \
  22. __JS_ENUMERATE(GetPossibleInstantsFor, getPossibleInstantsFor, get_possible_instants_for)
  23. enum class TimeZoneMethod {
  24. #define __JS_ENUMERATE(PascalName, camelName, snake_name) \
  25. PascalName,
  26. JS_ENUMERATE_TIME_ZONE_METHODS
  27. #undef __JS_ENUMERATE
  28. };
  29. ThrowCompletionOr<void> time_zone_methods_record_lookup(VM&, TimeZoneMethods&, TimeZoneMethod);
  30. ThrowCompletionOr<TimeZoneMethods> create_time_zone_methods_record(VM&, Variant<String, NonnullGCPtr<Object>> time_zone, ReadonlySpan<TimeZoneMethod>);
  31. bool time_zone_methods_record_has_looked_up(TimeZoneMethods const&, TimeZoneMethod);
  32. bool time_zone_methods_record_is_builtin(TimeZoneMethods const&);
  33. ThrowCompletionOr<Value> time_zone_methods_record_call(VM&, TimeZoneMethods const&, TimeZoneMethod, ReadonlySpan<Value> arguments);
  34. }