From e6858964037488ee05d49f6a1d61089ab28e0440 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 18 Jun 2022 13:33:12 +0100 Subject: [PATCH] LibJS: Check value is an Object before checking for internal slots This is an editorial change in the Temporal spec. See: https://github.com/tc39/proposal-temporal/commit/d96e662 --- .../LibJS/Runtime/Temporal/DurationPrototype.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index a0d1a4b623..11c6393d55 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -425,8 +425,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) // 24. Let balanceResult be ? BalanceDurationRelative(adjustResult.[[Years]], adjustResult.[[Months]], adjustResult.[[Weeks]], adjustResult.[[Days]], largestUnit, relativeTo). auto balance_result = TRY(balance_duration_relative(global_object, adjust_result.years, adjust_result.months, adjust_result.weeks, adjust_result.days, *largest_unit, relative_to)); - // 25. If relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot, then - // TODO: The spec doesn't check the type of relativeTo here and relativeTo can be undefined. + // 25. If Type(relativeTo) is Object and relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot, then if (relative_to.is_object() && is(relative_to.as_object())) { auto& relative_to_zoned_date_time = static_cast(relative_to.as_object()); @@ -483,10 +482,12 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::total) // 9. Let intermediate be undefined. ZonedDateTime* intermediate = nullptr; - // 10. If relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot, then + // 10. If Type(relativeTo) is Object and relativeTo has an [[InitializedTemporalZonedDateTime]] internal slot, then if (relative_to.is_object() && is(relative_to.as_object())) { + auto& relative_to_zoned_date_time = static_cast(relative_to.as_object()); + // a. Set intermediate to ? MoveRelativeZonedDateTime(relativeTo, unbalanceResult.[[Years]], unbalanceResult.[[Months]], unbalanceResult.[[Weeks]], 0). - intermediate = TRY(move_relative_zoned_date_time(global_object, static_cast(relative_to.as_object()), unbalance_result.years, unbalance_result.months, unbalance_result.weeks, 0)); + intermediate = TRY(move_relative_zoned_date_time(global_object, relative_to_zoned_date_time, unbalance_result.years, unbalance_result.months, unbalance_result.weeks, 0)); } // 11. Let balanceResult be ? BalanceDuration(unbalanceResult.[[Days]], duration.[[Hours]], duration.[[Minutes]], duration.[[Seconds]], duration.[[Milliseconds]], duration.[[Microseconds]], duration.[[Nanoseconds]], unit, intermediate).