mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 18:00:16 +00:00
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.
This commit is contained in:
parent
b7f80e7081
commit
15977ea42f
Notes:
sideshowbarker
2024-07-17 10:16:43 +09:00
Author: https://github.com/shannonbooth
Commit: 15977ea42f
Pull-request: https://github.com/SerenityOS/serenity/pull/23238
Reviewed-by: https://github.com/trflynn89
1 changed files with 5 additions and 3 deletions
|
@ -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<TypeError>(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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue