From 0c038bf12e1e4106306db64dcdb65a4e2071758c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 28 Aug 2025 15:24:18 -0400 Subject: [PATCH] LibJS: Read user options in a Temporal AO sooner This is a normative change in the Temporal proposal. See: https://github.com/tc39/proposal-temporal/commit/9924aa4 --- .../Runtime/Temporal/AbstractOperations.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp index c14a57dd2e8..83545b80747 100644 --- a/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp +++ b/Libraries/LibJS/Runtime/Temporal/AbstractOperations.cpp @@ -1693,34 +1693,34 @@ ThrowCompletionOr get_difference_settings(VM& vm, DurationOp // 2. Let largestUnit be ? GetTemporalUnitValuedOption(options, "largestUnit", UNSET). auto largest_unit = TRY(get_temporal_unit_valued_option(vm, options, vm.names.largestUnit, Unset {})); - // 3. Perform ? ValidateTemporalUnitValue(largestUnit, unitGroup, « AUTO »). + // 3. Let roundingIncrement be ? GetRoundingIncrementOption(options). + auto rounding_increment = TRY(get_rounding_increment_option(vm, options)); + + // 4. Let roundingMode be ? GetRoundingModeOption(options, TRUNC). + auto rounding_mode = TRY(get_rounding_mode_option(vm, options, RoundingMode::Trunc)); + + // 5. Let smallestUnit be ? GetTemporalUnitValuedOption(options, "smallestUnit", UNSET). + auto smallest_unit = TRY(get_temporal_unit_valued_option(vm, options, vm.names.smallestUnit, Unset {})); + + // 6. Perform ? ValidateTemporalUnitValue(largestUnit, unitGroup, « AUTO »). TRY(validate_temporal_unit_value(vm, vm.names.largestUnit, largest_unit, unit_group, { { Auto {} } })); - // 4. If largestUnit is UNSET, then + // 7. If largestUnit is UNSET, then if (largest_unit.has()) { // a. Set largestUnit to AUTO. largest_unit = Auto {}; } - // 5. If disallowedUnits contains largestUnit, throw a RangeError exception. + // 8. If disallowedUnits contains largestUnit, throw a RangeError exception. if (auto* unit = largest_unit.get_pointer(); unit && disallowed_units.contains_slow(*unit)) return vm.throw_completion(ErrorType::OptionIsNotValidValue, temporal_unit_to_string(*unit), vm.names.largestUnit); - // 6. Let roundingIncrement be ? GetRoundingIncrementOption(options). - auto rounding_increment = TRY(get_rounding_increment_option(vm, options)); - - // 7. Let roundingMode be ? GetRoundingModeOption(options, TRUNC). - auto rounding_mode = TRY(get_rounding_mode_option(vm, options, RoundingMode::Trunc)); - - // 8. If operation is SINCE, then + // 9. If operation is SINCE, then if (operation == DurationOperation::Since) { // a. Set roundingMode to NegateRoundingMode(roundingMode). rounding_mode = negate_rounding_mode(rounding_mode); } - // 9. Let smallestUnit be ? GetTemporalUnitValuedOption(options, "smallestUnit", UNSET). - auto smallest_unit = TRY(get_temporal_unit_valued_option(vm, options, vm.names.smallestUnit, Unset {})); - // 10. Perform ? ValidateTemporalUnitValue(smallestUnit, unitGroup). TRY(validate_temporal_unit_value(vm, vm.names.smallestUnit, smallest_unit, unit_group));