|
@@ -38,6 +38,7 @@ void PlainTimePrototype::initialize(GlobalObject& global_object)
|
|
define_native_accessor(vm.names.nanosecond, nanosecond_getter, {}, Attribute::Configurable);
|
|
define_native_accessor(vm.names.nanosecond, nanosecond_getter, {}, Attribute::Configurable);
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
|
|
+ define_native_function(vm.names.with, with, 1, attr);
|
|
define_native_function(vm.names.equals, equals, 1, attr);
|
|
define_native_function(vm.names.equals, equals, 1, attr);
|
|
define_native_function(vm.names.toPlainDateTime, to_plain_date_time, 1, attr);
|
|
define_native_function(vm.names.toPlainDateTime, to_plain_date_time, 1, attr);
|
|
define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
|
|
define_native_function(vm.names.getISOFields, get_iso_fields, 0, attr);
|
|
@@ -148,6 +149,115 @@ JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::nanosecond_getter)
|
|
return Value(temporal_time->iso_nanosecond());
|
|
return Value(temporal_time->iso_nanosecond());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 4.3.12 Temporal.PlainTime.prototype.with ( temporalTimeLike [ , options ] ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.with
|
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::with)
|
|
|
|
+{
|
|
|
|
+ // 1. Let temporalTime be the this value.
|
|
|
|
+ // 2. Perform ? RequireInternalSlot(temporalTime, [[InitializedTemporalTime]]).
|
|
|
|
+ auto* temporal_time = typed_this(global_object);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ auto temporal_time_like_argument = vm.argument(0);
|
|
|
|
+
|
|
|
|
+ // 3. If Type(temporalTimeLike) is not Object, then
|
|
|
|
+ if (!temporal_time_like_argument.is_object()) {
|
|
|
|
+ // a. Throw a TypeError exception.
|
|
|
|
+ vm.throw_exception<TypeError>(global_object, ErrorType::NotAnObject, temporal_time_like_argument.to_string_without_side_effects());
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ auto& temporal_time_like = temporal_time_like_argument.as_object();
|
|
|
|
+
|
|
|
|
+ // 4. Perform ? RejectTemporalCalendarType(temporalTimeLike).
|
|
|
|
+ reject_temporal_calendar_type(global_object, temporal_time_like);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 5. Let calendarProperty be ? Get(temporalTimeLike, "calendar").
|
|
|
|
+ auto calendar_property = temporal_time_like.get(vm.names.calendar);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 6. If calendarProperty is not undefined, then
|
|
|
|
+ if (!calendar_property.is_undefined()) {
|
|
|
|
+ // a. Throw a TypeError exception.
|
|
|
|
+ vm.throw_exception<TypeError>(global_object, ErrorType::TemporalPlainTimeWithArgumentMustNotHave, "calendar");
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 7. Let timeZoneProperty be ? Get(temporalTimeLike, "timeZone").
|
|
|
|
+ auto time_zone_property = temporal_time_like.get(vm.names.timeZone);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 8. If timeZoneProperty is not undefined, then
|
|
|
|
+ if (!time_zone_property.is_undefined()) {
|
|
|
|
+ // a. Throw a TypeError exception.
|
|
|
|
+ vm.throw_exception<TypeError>(global_object, ErrorType::TemporalPlainTimeWithArgumentMustNotHave, "timeZone");
|
|
|
|
+ return {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 9. Let partialTime be ? ToPartialTime(temporalTimeLike).
|
|
|
|
+ auto partial_time = to_partial_time(global_object, temporal_time_like);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 10. Set options to ? GetOptionsObject(options).
|
|
|
|
+ auto* options = get_options_object(global_object, vm.argument(1));
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 11. Let overflow be ? ToTemporalOverflow(options).
|
|
|
|
+ auto overflow = to_temporal_overflow(global_object, *options);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 12. If partialTime.[[Hour]] is not undefined, then
|
|
|
|
+ // a. Let hour be partialTime.[[Hour]].
|
|
|
|
+ // 13. Else,
|
|
|
|
+ // a. Let hour be temporalTime.[[ISOHour]].
|
|
|
|
+ auto hour = partial_time->hour.value_or(temporal_time->iso_hour());
|
|
|
|
+
|
|
|
|
+ // 14. If partialTime.[[Minute]] is not undefined, then
|
|
|
|
+ // a. Let minute be partialTime.[[Minute]].
|
|
|
|
+ // 15. Else,
|
|
|
|
+ // a. Let minute be temporalTime.[[ISOMinute]].
|
|
|
|
+ auto minute = partial_time->minute.value_or(temporal_time->iso_minute());
|
|
|
|
+
|
|
|
|
+ // 16. If partialTime.[[Second]] is not undefined, then
|
|
|
|
+ // a. Let second be partialTime.[[Second]].
|
|
|
|
+ // 17. Else,
|
|
|
|
+ // a. Let second be temporalTime.[[ISOSecond]].
|
|
|
|
+ auto second = partial_time->second.value_or(temporal_time->iso_second());
|
|
|
|
+
|
|
|
|
+ // 18. If partialTime.[[Millisecond]] is not undefined, then
|
|
|
|
+ // a. Let millisecond be partialTime.[[Millisecond]].
|
|
|
|
+ // 19. Else,
|
|
|
|
+ // a. Let millisecond be temporalTime.[[ISOMillisecond]].
|
|
|
|
+ auto millisecond = partial_time->millisecond.value_or(temporal_time->iso_millisecond());
|
|
|
|
+
|
|
|
|
+ // 20. If partialTime.[[Microsecond]] is not undefined, then
|
|
|
|
+ // a. Let microsecond be partialTime.[[Microsecond]].
|
|
|
|
+ // 21. Else,
|
|
|
|
+ // a. Let microsecond be temporalTime.[[ISOMicrosecond]].
|
|
|
|
+ auto microsecond = partial_time->microsecond.value_or(temporal_time->iso_microsecond());
|
|
|
|
+
|
|
|
|
+ // 22. If partialTime.[[Nanosecond]] is not undefined, then
|
|
|
|
+ // a. Let nanosecond be partialTime.[[Nanosecond]].
|
|
|
|
+ // 23. Else,
|
|
|
|
+ // a. Let nanosecond be temporalTime.[[ISONanosecond]].
|
|
|
|
+ auto nanosecond = partial_time->nanosecond.value_or(temporal_time->iso_nanosecond());
|
|
|
|
+
|
|
|
|
+ // 24. Let result be ? RegulateTime(hour, minute, second, millisecond, microsecond, nanosecond, overflow).
|
|
|
|
+ auto result = regulate_time(global_object, hour, minute, second, millisecond, microsecond, nanosecond, *overflow);
|
|
|
|
+ if (vm.exception())
|
|
|
|
+ return {};
|
|
|
|
+
|
|
|
|
+ // 25. Return ? CreateTemporalTime(result.[[Hour]], result.[[Minute]], result.[[Second]], result.[[Millisecond]], result.[[Microsecond]], result.[[Nanosecond]]).
|
|
|
|
+ return create_temporal_time(global_object, result->hour, result->minute, result->second, result->millisecond, result->microsecond, result->nanosecond);
|
|
|
|
+}
|
|
|
|
+
|
|
// 4.3.16 Temporal.PlainTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.equals
|
|
// 4.3.16 Temporal.PlainTime.prototype.equals ( other ), https://tc39.es/proposal-temporal/#sec-temporal.plaintime.prototype.equals
|
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::equals)
|
|
JS_DEFINE_NATIVE_FUNCTION(PlainTimePrototype::equals)
|
|
{
|
|
{
|