Backed out 3 changesets (bug 1892041) for causing failures on async-module-does-not...
[gecko.git] / js / src / tests / test262 / built-ins / Temporal / ZonedDateTime / prototype / round / order-of-operations.js
blob48ca638b39ad7181a770da3b1e0ff56e062396fe
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
5 /*---
6 esid: sec-temporal.zoneddatetime.prototype.round
7 description: Properties on objects passed to round() are accessed in the correct order
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
12 const expected = [
13   "get options.roundingIncrement",
14   "get options.roundingIncrement.valueOf",
15   "call options.roundingIncrement.valueOf",
16   "get options.roundingMode",
17   "get options.roundingMode.toString",
18   "call options.roundingMode.toString",
19   "get options.smallestUnit",
20   "get options.smallestUnit.toString",
21   "call options.smallestUnit.toString",
22   // lookup
23   "get this.timeZone.getOffsetNanosecondsFor",
24   "get this.timeZone.getPossibleInstantsFor",
25   // GetPlainDateTimeFor on receiver's instant
26   "call this.timeZone.getOffsetNanosecondsFor",
27   // GetInstantFor on preceding midnight
28   "call this.timeZone.getPossibleInstantsFor",
29   // AddDaysToZonedDateTime
30   "call this.timeZone.getPossibleInstantsFor",
31   // InterpretISODateTimeOffset
32   "call this.timeZone.getPossibleInstantsFor",
33   "call this.timeZone.getOffsetNanosecondsFor",
35 const actual = [];
37 const options = TemporalHelpers.propertyBagObserver(actual, {
38   smallestUnit: "nanoseconds",
39   roundingMode: "halfExpand",
40   roundingIncrement: 2,
41 }, "options");
43 const nextHourOptions = TemporalHelpers.propertyBagObserver(actual, {
44   smallestUnit: "hour",
45   roundingMode: "ceil",
46   roundingIncrement: 1,
47 }, "options");
49 const calendar = TemporalHelpers.calendarObserver(actual, "this.calendar");
50 const instance = new Temporal.ZonedDateTime(
51   988786472_987_654_321n,  /* 2001-05-02T06:54:32.987654321Z */
52   TemporalHelpers.timeZoneObserver(actual, "this.timeZone"),
53   calendar,
56 const fallBackTimeZone = TemporalHelpers.oneShiftTimeZone(Temporal.Instant.fromEpochSeconds(1800), -3600_000_000_000);
57 const fallBackTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", {
58   getOffsetNanosecondsFor: fallBackTimeZone.getOffsetNanosecondsFor.bind(fallBackTimeZone),
59   getPossibleInstantsFor: fallBackTimeZone.getPossibleInstantsFor.bind(fallBackTimeZone),
60 });
61 const fallBackInstance = new Temporal.ZonedDateTime(0n, fallBackTimeZoneObserver, calendar);
62 const beforeFallBackInstance = new Temporal.ZonedDateTime(-3599_000_000_000n, fallBackTimeZoneObserver, calendar);
64 const springForwardTimeZone = TemporalHelpers.oneShiftTimeZone(Temporal.Instant.fromEpochSeconds(-1800), 3600_000_000_000);
65 const springForwardTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "this.timeZone", {
66   getOffsetNanosecondsFor: springForwardTimeZone.getOffsetNanosecondsFor.bind(springForwardTimeZone),
67   getPossibleInstantsFor: springForwardTimeZone.getPossibleInstantsFor.bind(springForwardTimeZone),
68 });
69 const springForwardInstance = new Temporal.ZonedDateTime(0n, springForwardTimeZoneObserver, calendar);
70 const beforeSpringForwardInstance = new Temporal.ZonedDateTime(-3599_000_000_000n, springForwardTimeZoneObserver, calendar);
71 // clear any observable operations that happen due to time zone or calendar
72 // calls in the constructors
73 actual.splice(0);
75 instance.round(options);
76 assert.compareArray(actual, expected, "order of operations");
77 actual.splice(0); // clear
79 fallBackInstance.round(options);
80 assert.compareArray(actual, expected, "order of operations with preceding midnight at repeated wall-clock time");
81 actual.splice(0); // clear
83 beforeFallBackInstance.round(nextHourOptions);
84 assert.compareArray(actual, expected, "order of operations with rounding result at repeated wall-clock time");
85 actual.splice(0); // clear
87 const expectedSkippedDateTime = [
88   "get options.roundingIncrement",
89   "get options.roundingIncrement.valueOf",
90   "call options.roundingIncrement.valueOf",
91   "get options.roundingMode",
92   "get options.roundingMode.toString",
93   "call options.roundingMode.toString",
94   "get options.smallestUnit",
95   "get options.smallestUnit.toString",
96   "call options.smallestUnit.toString",
97   // lookup
98   "get this.timeZone.getOffsetNanosecondsFor",
99   "get this.timeZone.getPossibleInstantsFor",
100   // GetPlainDateTimeFor on receiver's instant
101   "call this.timeZone.getOffsetNanosecondsFor",
102   // GetInstantFor on preceding midnight
103   "call this.timeZone.getPossibleInstantsFor",
104   // DisambiguatePossibleInstants
105   "call this.timeZone.getOffsetNanosecondsFor",
106   "call this.timeZone.getOffsetNanosecondsFor",
107   "call this.timeZone.getPossibleInstantsFor",
108   // AddZonedDateTime
109   "call this.timeZone.getPossibleInstantsFor",
110   // InterpretISODateTimeOffset
111   "call this.timeZone.getPossibleInstantsFor",
112   "call this.timeZone.getOffsetNanosecondsFor",
115 springForwardInstance.round(options);
116 assert.compareArray(actual, expectedSkippedDateTime, "order of operations with preceding midnight at skipped wall-clock time");
117 actual.splice(0); // clear
119 const expectedSkippedResult = [
120   "get options.roundingIncrement",
121   "get options.roundingIncrement.valueOf",
122   "call options.roundingIncrement.valueOf",
123   "get options.roundingMode",
124   "get options.roundingMode.toString",
125   "call options.roundingMode.toString",
126   "get options.smallestUnit",
127   "get options.smallestUnit.toString",
128   "call options.smallestUnit.toString",
129   // lookup
130   "get this.timeZone.getOffsetNanosecondsFor",
131   "get this.timeZone.getPossibleInstantsFor",
132   // GetPlainDateTimeFor on receiver's instant
133   "call this.timeZone.getOffsetNanosecondsFor",
134   // GetInstantFor on preceding midnight
135   "call this.timeZone.getPossibleInstantsFor",
136   // AddDaysToZonedDateTime
137   "call this.timeZone.getPossibleInstantsFor",
138   // DisambiguatePossibleInstants
139   "call this.timeZone.getOffsetNanosecondsFor",
140   "call this.timeZone.getOffsetNanosecondsFor",
141   "call this.timeZone.getPossibleInstantsFor",
142   // InterpretISODateTimeOffset
143   "call this.timeZone.getPossibleInstantsFor",
144   // DisambiguatePossibleInstants
145   "call this.timeZone.getOffsetNanosecondsFor",
146   "call this.timeZone.getOffsetNanosecondsFor",
147   "call this.timeZone.getPossibleInstantsFor",
150 beforeSpringForwardInstance.round(nextHourOptions);
151 assert.compareArray(
152   actual,
153   expectedSkippedResult,
154   "order of operations with following midnight and rounding result at skipped wall-clock time"
156 actual.splice(0); // clear
158 reportCompare(0, 0);