Skip to content

Commit

Permalink
Bug 1840374 - Part 29: Sync AddDurationToOrSubtractDurationFromPlainY…
Browse files Browse the repository at this point in the history
…earMonth. r=spidermonkey-reviewers,sfink

Implement the changes from <tc39/proposal-temporal#2484>.

Differential Revision: https://phabricator.services.mozilla.com/D182049

UltraBlame original commit: 2aff072a94c4b7ae26778e7308f853ab008bd8e2
  • Loading branch information
marco-c committed Jul 21, 2023
1 parent 31c1afb commit 20d19d9
Showing 1 changed file with 269 additions and 29 deletions.
298 changes: 269 additions & 29 deletions js/src/builtin/temporal/PlainYearMonth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2966,6 +2966,106 @@ return
false
;
}
Rooted
<
PlainObject
*
>
fieldsCopy
(
cx
CopyOptions
(
cx
fields
)
)
;
if
(
!
fieldsCopy
)
{
return
false
;
}
Value
one
=
Int32Value
(
1
)
;
auto
handleOne
=
Handle
<
Value
>
:
:
fromMarkedLocation
(
&
one
)
;
if
(
!
DefineDataProperty
(
cx
fields
cx
-
>
names
(
)
.
day
handleOne
)
)
{
return
false
;
}
Rooted
<
Wrapped
<
PlainDateObject
*
>
>
intermediateDate
(
cx
CalendarDateFromFields
(
cx
calendar
fields
)
)
;
if
(
!
intermediateDate
)
{
return
false
;
}
int32_t
sign
=
Expand All @@ -2991,7 +3091,69 @@ Rooted
<
Value
>
day
dateAdd
(
cx
)
;
if
(
calendar
.
isObject
(
)
)
{
Rooted
<
JSObject
*
>
calendarObj
(
cx
calendar
.
toObject
(
)
)
;
if
(
!
GetMethod
(
cx
calendarObj
cx
-
>
names
(
)
.
dateAdd
&
dateAdd
)
)
{
return
false
;
}
}
Rooted
<
Wrapped
<
PlainDateObject
*
>
>
date
(
cx
)
Expand All @@ -3003,46 +3165,125 @@ sign
0
)
{
Duration
oneMonthDuration
=
{
0
1
}
;
Rooted
<
Value
Wrapped
<
PlainDateObject
*
>
>
yearMonthValue
nextMonth
(
cx
ObjectValue
CalendarDateAdd
(
*
yearMonth
cx
calendar
intermediateDate
oneMonthDuration
dateAdd
)
)
;
if
(
!
CalendarDaysInMonth
nextMonth
)
{
return
false
;
}
Duration
minusDayDuration
=
{
0
0
0
-
1
}
;
Rooted
<
Wrapped
<
PlainDateObject
*
>
>
endOfMonth
(
cx
CalendarDateAdd
(
cx
calendar
yearMonthValue
&
day
nextMonth
minusDayDuration
dateAdd
)
)
;
if
(
!
endOfMonth
)
{
return
false
;
}
}
else
{
Rooted
<
Value
>
endOfMonthValue
(
cx
ObjectValue
(
*
endOfMonth
)
)
;
Rooted
<
Value
>
day
.
setInt32
(
1
cx
)
;
if
(
!
CalendarDay
(
cx
calendar
endOfMonthValue
&
day
)
)
{
return
false
;
}
if
Expand All @@ -3051,7 +3292,7 @@ if
DefineDataProperty
(
cx
fields
fieldsCopy
cx
-
>
Expand All @@ -3068,23 +3309,13 @@ return
false
;
}
Rooted
<
Wrapped
<
PlainDateObject
*
>
>
date
(
cx
=
CalendarDateFromFields
(
cx
calendar
fields
)
fieldsCopy
)
;
if
Expand All @@ -3097,6 +3328,14 @@ return
false
;
}
}
else
{
date
=
intermediateDate
;
}
Rooted
<
DurationObject
Expand Down Expand Up @@ -3178,6 +3417,7 @@ calendar
date
durationToAdd
options
dateAdd
)
)
;
Expand Down

0 comments on commit 20d19d9

Please sign in to comment.