Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainDateTime/from/order-of-operations.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 2020 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-temporal.plaindatetime.from
7 description: Properties on an object passed to from() are accessed in the correct order
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const expectedOptionsReading = [
13 // GetTemporalOverflowOption
14 "get options.overflow",
15 "get options.overflow.toString",
16 "call options.overflow.toString",
17 ];
18
19 const expected = [
20 // GetTemporalCalendarSlotValueWithISODefault
21 "get fields.calendar",
22 // PrepareTemporalFields
23 "get fields.day",
24 "get fields.day.valueOf",
25 "call fields.day.valueOf",
26 "get fields.hour",
27 "get fields.hour.valueOf",
28 "call fields.hour.valueOf",
29 "get fields.microsecond",
30 "get fields.microsecond.valueOf",
31 "call fields.microsecond.valueOf",
32 "get fields.millisecond",
33 "get fields.millisecond.valueOf",
34 "call fields.millisecond.valueOf",
35 "get fields.minute",
36 "get fields.minute.valueOf",
37 "call fields.minute.valueOf",
38 "get fields.month",
39 "get fields.month.valueOf",
40 "call fields.month.valueOf",
41 "get fields.monthCode",
42 "get fields.monthCode.toString",
43 "call fields.monthCode.toString",
44 "get fields.nanosecond",
45 "get fields.nanosecond.valueOf",
46 "call fields.nanosecond.valueOf",
47 "get fields.second",
48 "get fields.second.valueOf",
49 "call fields.second.valueOf",
50 "get fields.year",
51 "get fields.year.valueOf",
52 "call fields.year.valueOf",
53 ].concat(expectedOptionsReading);
54 const actual = [];
55
56 const fields = TemporalHelpers.propertyBagObserver(actual, {
57 year: 1.7,
58 month: 1.7,
59 monthCode: "M01",
60 day: 1.7,
61 hour: 1.7,
62 minute: 1.7,
63 second: 1.7,
64 millisecond: 1.7,
65 microsecond: 1.7,
66 nanosecond: 1.7,
67 calendar: "iso8601",
68 }, "fields", ["calendar"]);
69
70 const options = TemporalHelpers.propertyBagObserver(actual, {
71 overflow: "constrain",
72 extra: "property",
73 }, "options");
74
75 Temporal.PlainDateTime.from(fields, options);
76 assert.compareArray(actual, expected, "order of operations");
77
78 actual.splice(0); // clear for next test
79
80 Temporal.PlainDateTime.from(new Temporal.PlainDateTime(2000, 5, 2), options);
81 assert.compareArray(actual, expectedOptionsReading, "order of operations when cloning a PlainDateTime instance");
82
83 actual.splice(0);
84
85 Temporal.PlainDateTime.from(new Temporal.PlainDate(2000, 5, 2), options);
86 assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a PlainDate instance");
87
88 actual.splice(0);
89
90 Temporal.PlainDateTime.from(new Temporal.ZonedDateTime(0n, "UTC"), options);
91 assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a ZonedDateTime instance");
92
93 actual.splice(0);
94
95 Temporal.PlainDateTime.from("2001-05-02", options);
96 assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string");
97
98 reportCompare(0, 0);