diff --git a/js/src/builtin/temporal/PlainYearMonth.cpp b/js/src/builtin/temporal/PlainYearMonth.cpp index 693ce8e1b98c..be073b3c1027 100644 --- a/js/src/builtin/temporal/PlainYearMonth.cpp +++ b/js/src/builtin/temporal/PlainYearMonth.cpp @@ -3578,6 +3578,19 @@ args } else { +/ +/ +TODO +: +Avoid +creating +an +options +object +if +not +necessary +. options = NewPlainObjectWithProto @@ -3696,6 +3709,121 @@ false Step 8 . +Rooted +< +PlainObject +* +> +fieldsCopy +( +cx +CopyOptions +( +cx +fields +) +) +; +if +( +! +fieldsCopy +) +{ +return +false +; +} +/ +/ +Step +9 +. +Value +one += +Int32Value +( +1 +) +; +auto +handleOne += +Handle +< +Value +> +: +: +fromMarkedLocation +( +& +one +) +; +if +( +! +DefineDataProperty +( +cx +fields +cx +- +> +names +( +) +. +day +handleOne +) +) +{ +return +false +; +} +/ +/ +Step +10 +. +Rooted +< +Wrapped +< +PlainDateObject +* +> +> +intermediateDate +( +cx +CalendarDateFromFields +( +cx +calendar +fields +) +) +; +if +( +! +intermediateDate +) +{ +return +false +; +} +/ +/ +Step +11 +. int32_t sign = @@ -3719,16 +3847,115 @@ days ; / / -Steps -9 +FIXME +: +spec +bug - -10 +calendar +can +be +a +string +. +/ +/ +https +: +/ +/ +github +. +com +/ +tc39 +/ +proposal +- +temporal +/ +issues +/ +2619 +/ +/ +Step +12 . Rooted < Value > -day +dateAdd +( +cx +) +; +if +( +calendar +. +isObject +( +) +) +{ +Rooted +< +JSObject +* +> +calendarObj +( +cx +calendar +. +toObject +( +) +) +; +if +( +! +GetMethod +( +cx +calendarObj +cx +- +> +names +( +) +. +dateAdd +& +dateAdd +) +) +{ +return +false +; +} +} +/ +/ +Steps +13 +- +14 +. +Rooted +< +Wrapped +< +PlainDateObject +* +> +> +date ( cx ) @@ -3742,60 +3969,314 @@ sign { / / +| +intermediateDate +| +is +initialized +to +the +first +day +of +| +yearMonth +| +' +s +/ +/ +month +. +Compute +the +last +day +of +| +yearMonth +| +' +s +month +by +first +adding +one +/ +/ +month +and +then +subtracting +one +day +. +/ +/ +/ +/ +This +is +roughly +equivalent +to +these +calls +: +/ +/ +/ +/ +js +> +var +ym += +new +Temporal +. +PlainYearMonth +( +2023 +1 +) +; +/ +/ +js +> +ym +. +toPlainDate +( +{ +day +: +1 +} +) +. +add +( +{ +months +: +1 +} +) +. +subtract +( +{ +days +: +1 +} +) +. +day +/ +/ +31 +/ +/ +/ +/ +For +many +calendars +this +is +equivalent +to +ym +. +daysInMonth +except +when +/ +/ +some +days +are +skipped +for +example +consider +the +Julian +- +to +- +Gregorian +/ +/ +calendar +transition +. +/ +/ +Step +13 +. +a +. +Duration +oneMonthDuration += +{ +0 +1 +} +; +/ +/ Step -9 +13 +. +b . Rooted < -Value +Wrapped +< +PlainDateObject +* > -yearMonthValue +> +nextMonth ( cx -ObjectValue +CalendarDateAdd ( -* -yearMonth +cx +calendar +intermediateDate +oneMonthDuration +dateAdd ) ) ; if ( ! -CalendarDaysInMonth +nextMonth +) +{ +return +false +; +} +/ +/ +Step +13 +. +c +. +Duration +minusDayDuration += +{ +0 +0 +0 +- +1 +} +; +/ +/ +Step +13 +. +d +. +Rooted +< +Wrapped +< +PlainDateObject +* +> +> +endOfMonth +( +cx +CalendarDateAdd ( cx calendar -yearMonthValue -& -day +nextMonth +minusDayDuration +dateAdd ) ) +; +if +( +! +endOfMonth +) { return false ; } -} -else -{ / / Step -10 +13 . -day +e . -setInt32 +Rooted +< +Value +> +endOfMonthValue ( -1 +cx +ObjectValue +( +* +endOfMonth ) +) +; +Rooted +< +Value +> +day +( +cx +) +; +if +( +! +CalendarDay +( +cx +calendar +endOfMonthValue +& +day +) +) +{ +return +false ; } / / Step -11 +13 +. +f . if ( @@ -3803,7 +4284,7 @@ if DefineDataProperty ( cx -fields +fieldsCopy cx - > @@ -3823,25 +4304,17 @@ false / / Step -12 +13 +. +g . -Rooted -< -Wrapped -< -PlainDateObject -* -> -> date -( -cx += CalendarDateFromFields ( cx calendar -fields -) +fieldsCopy ) ; if @@ -3854,10 +4327,25 @@ return false ; } +} +else +{ / / Step -13 +14 +. +a +. +date += +intermediateDate +; +} +/ +/ +Step +15 . Rooted < @@ -3899,8 +4387,38 @@ false } / / +FIXME +: +spec +issue +- +unnecessary +call +to +GetOptionsObject +/ +/ +https +: +/ +/ +github +. +com +/ +tc39 +/ +proposal +- +temporal +/ +issues +/ +2620 +/ +/ Step -14 +16 . Rooted < @@ -3930,7 +4448,7 @@ false / / Step -15 +17 . Rooted < @@ -3950,6 +4468,7 @@ calendar date durationToAdd options +dateAdd ) ) ; @@ -3966,7 +4485,7 @@ false / / Step -16 +18 . Rooted < @@ -3997,7 +4516,7 @@ false / / Step -17 +19 . auto obj