From 15977ea42f55aac42d3479b1ca4f344dd2cde6fe Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 18 Feb 2024 14:34:58 +1300 Subject: [PATCH] LibJS: Put roundTo argument into a variable Following the pattern we have in other protoypes to avoid a magic number index into the zeroth argument. --- .../LibJS/Runtime/Temporal/DurationPrototype.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp index c3d221497a..28f89ea882 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/DurationPrototype.cpp @@ -326,12 +326,14 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) { auto& realm = *vm.current_realm(); + auto round_to_value = vm.argument(0); + // 1. Let duration be the this value. // 2. Perform ? RequireInternalSlot(duration, [[InitializedTemporalDuration]]). auto duration = TRY(typed_this_object(vm)); // 3. If roundTo is undefined, then - if (vm.argument(0).is_undefined()) { + if (round_to_value.is_undefined()) { // a. Throw a TypeError exception. return vm.throw_completion(ErrorType::TemporalMissingOptionsObject); } @@ -339,7 +341,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) Object* round_to; // 4. If Type(roundTo) is String, then - if (vm.argument(0).is_string()) { + if (round_to_value.is_string()) { // a. Let paramString be roundTo. // b. Set roundTo to OrdinaryObjectCreate(null). @@ -351,7 +353,7 @@ JS_DEFINE_NATIVE_FUNCTION(DurationPrototype::round) // 5. Else, else { // a. Set roundTo to ? GetOptionsObject(roundTo). - round_to = TRY(get_options_object(vm, vm.argument(0))); + round_to = TRY(get_options_object(vm, round_to_value)); } // 6. Let smallestUnitPresent be true.