|
@@ -39,6 +39,7 @@ void DurationPrototype::initialize(GlobalObject& global_object)
|
|
|
define_native_accessor(vm.names.blank, blank_getter, {}, Attribute::Configurable);
|
|
|
|
|
|
u8 attr = Attribute::Writable | Attribute::Configurable;
|
|
|
+ define_native_function(vm.names.with, with, 1, attr);
|
|
|
define_native_function(vm.names.valueOf, value_of, 0, attr);
|
|
|
}
|
|
|
|
|
@@ -218,6 +219,84 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::blank_getter)
|
|
|
return Value(false);
|
|
|
}
|
|
|
|
|
|
+// 7.3.15 Temporal.Duration.prototype.with ( temporalDurationLike ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.with
|
|
|
+JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::with)
|
|
|
+{
|
|
|
+ // 1. Let duration be the this value.
|
|
|
+ // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]).
|
|
|
+ auto* duration = typed_this(global_object);
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 3. Let temporalDurationLike be ? ToPartialDuration(temporalDurationLike).
|
|
|
+ auto temporal_duration_like = to_partial_duration(global_object, vm.argument(0));
|
|
|
+ if (vm.exception())
|
|
|
+ return {};
|
|
|
+
|
|
|
+ // 4. If temporalDurationLike.[[Years]] is not undefined, then
|
|
|
+ // a. Let years be temporalDurationLike.[[Years]].
|
|
|
+ // 5. Else,
|
|
|
+ // a. Let years be duration.[[Years]].
|
|
|
+ auto years = temporal_duration_like.years.value_or(duration->years());
|
|
|
+
|
|
|
+ // 6. If temporalDurationLike.[[Months]] is not undefined, then
|
|
|
+ // a. Let months be temporalDurationLike.[[Months]].
|
|
|
+ // 7. Else,
|
|
|
+ // a. Let months be duration.[[Months]].
|
|
|
+ auto months = temporal_duration_like.months.value_or(duration->months());
|
|
|
+
|
|
|
+ // 8. If temporalDurationLike.[[Weeks]] is not undefined, then
|
|
|
+ // a. Let weeks be temporalDurationLike.[[Weeks]].
|
|
|
+ // 9. Else,
|
|
|
+ // a. Let weeks be duration.[[Weeks]].
|
|
|
+ auto weeks = temporal_duration_like.weeks.value_or(duration->weeks());
|
|
|
+
|
|
|
+ // 10. If temporalDurationLike.[[Days]] is not undefined, then
|
|
|
+ // a. Let days be temporalDurationLike.[[Days]].
|
|
|
+ // 11. Else,
|
|
|
+ // a. Let days be duration.[[Days]].
|
|
|
+ auto days = temporal_duration_like.days.value_or(duration->days());
|
|
|
+
|
|
|
+ // 12. If temporalDurationLike.[[Hours]] is not undefined, then
|
|
|
+ // a. Let hours be temporalDurationLike.[[Hours]].
|
|
|
+ // 13. Else,
|
|
|
+ // a. Let hours be duration.[[Hours]].
|
|
|
+ auto hours = temporal_duration_like.hours.value_or(duration->hours());
|
|
|
+
|
|
|
+ // 14. If temporalDurationLike.[[Minutes]] is not undefined, then
|
|
|
+ // a. Let minutes be temporalDurationLike.[[Minutes]].
|
|
|
+ // 15. Else,
|
|
|
+ // a. Let minutes be duration.[[Minutes]].
|
|
|
+ auto minutes = temporal_duration_like.minutes.value_or(duration->minutes());
|
|
|
+
|
|
|
+ // 16. If temporalDurationLike.[[Seconds]] is not undefined, then
|
|
|
+ // a. Let seconds be temporalDurationLike.[[Seconds]].
|
|
|
+ // 17. Else,
|
|
|
+ // a. Let seconds be duration.[[Seconds]].
|
|
|
+ auto seconds = temporal_duration_like.seconds.value_or(duration->seconds());
|
|
|
+
|
|
|
+ // 18. If temporalDurationLike.[[Milliseconds]] is not undefined, then
|
|
|
+ // a. Let milliseconds be temporalDurationLike.[[Milliseconds]].
|
|
|
+ // 19. Else,
|
|
|
+ // a. Let milliseconds be duration.[[Milliseconds]].
|
|
|
+ auto milliseconds = temporal_duration_like.milliseconds.value_or(duration->milliseconds());
|
|
|
+
|
|
|
+ // 20. If temporalDurationLike.[[Microseconds]] is not undefined, then
|
|
|
+ // a. Let microseconds be temporalDurationLike.[[Microseconds]].
|
|
|
+ // 21. Else,
|
|
|
+ // a. Let microseconds be duration.[[Microseconds]].
|
|
|
+ auto microseconds = temporal_duration_like.microseconds.value_or(duration->microseconds());
|
|
|
+
|
|
|
+ // 22. If temporalDurationLike.[[Nanoseconds]] is not undefined, then
|
|
|
+ // a. Let nanoseconds be temporalDurationLike.[[Nanoseconds]].
|
|
|
+ // 23. Else,
|
|
|
+ // a. Let nanoseconds be duration.[[Nanoseconds]].
|
|
|
+ auto nanoseconds = temporal_duration_like.nanoseconds.value_or(duration->nanoseconds());
|
|
|
+
|
|
|
+ // 24. Return ? CreateTemporalDuration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
|
|
|
+ return create_temporal_duration(global_object, years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
|
|
|
+}
|
|
|
+
|
|
|
// 7.3.25 Temporal.Duration.prototype.valueOf ( ), https://tc39.es/proposal-temporal/#sec-temporal.duration.prototype.valueof
|
|
|
JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::value_of)
|
|
|
{
|