| 1 |
// |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2022 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.zoneddatetime.from |
| 7 |
description: Properties on objects passed to from() are accessed in the correct order |
| 8 |
includes: [compareArray.js, temporalHelpers.js] |
| 9 |
features: [Temporal] |
| 10 |
---*/ |
| 11 |
|
| 12 |
const expectedOptionsReading = [ |
| 13 |
// GetTemporalDisambiguationOption |
| 14 |
"get options.disambiguation", |
| 15 |
"get options.disambiguation.toString", |
| 16 |
"call options.disambiguation.toString", |
| 17 |
// GetTemporalOffsetOption |
| 18 |
"get options.offset", |
| 19 |
"get options.offset.toString", |
| 20 |
"call options.offset.toString", |
| 21 |
// GetTemporalOverflowOption |
| 22 |
"get options.overflow", |
| 23 |
"get options.overflow.toString", |
| 24 |
"call options.overflow.toString", |
| 25 |
]; |
| 26 |
|
| 27 |
const expected = [ |
| 28 |
// ToTemporalCalendar |
| 29 |
"get item.calendar", |
| 30 |
// PrepareTemporalFields |
| 31 |
"get item.day", |
| 32 |
"get item.day.valueOf", |
| 33 |
"call item.day.valueOf", |
| 34 |
"get item.hour", |
| 35 |
"get item.hour.valueOf", |
| 36 |
"call item.hour.valueOf", |
| 37 |
"get item.microsecond", |
| 38 |
"get item.microsecond.valueOf", |
| 39 |
"call item.microsecond.valueOf", |
| 40 |
"get item.millisecond", |
| 41 |
"get item.millisecond.valueOf", |
| 42 |
"call item.millisecond.valueOf", |
| 43 |
"get item.minute", |
| 44 |
"get item.minute.valueOf", |
| 45 |
"call item.minute.valueOf", |
| 46 |
"get item.month", |
| 47 |
"get item.month.valueOf", |
| 48 |
"call item.month.valueOf", |
| 49 |
"get item.monthCode", |
| 50 |
"get item.monthCode.toString", |
| 51 |
"call item.monthCode.toString", |
| 52 |
"get item.nanosecond", |
| 53 |
"get item.nanosecond.valueOf", |
| 54 |
"call item.nanosecond.valueOf", |
| 55 |
"get item.offset", |
| 56 |
"get item.offset.toString", |
| 57 |
"call item.offset.toString", |
| 58 |
"get item.second", |
| 59 |
"get item.second.valueOf", |
| 60 |
"call item.second.valueOf", |
| 61 |
"get item.timeZone", |
| 62 |
"get item.year", |
| 63 |
"get item.year.valueOf", |
| 64 |
"call item.year.valueOf", |
| 65 |
].concat(expectedOptionsReading); |
| 66 |
const actual = []; |
| 67 |
|
| 68 |
const from = TemporalHelpers.propertyBagObserver(actual, { |
| 69 |
year: 2001, |
| 70 |
month: 5, |
| 71 |
monthCode: "M05", |
| 72 |
day: 2, |
| 73 |
hour: 6, |
| 74 |
minute: 54, |
| 75 |
second: 32, |
| 76 |
millisecond: 987, |
| 77 |
microsecond: 654, |
| 78 |
nanosecond: 321, |
| 79 |
offset: "+00:00", |
| 80 |
calendar: "iso8601", |
| 81 |
timeZone: "UTC", |
| 82 |
}, "item", ["calendar", "timeZone"]); |
| 83 |
|
| 84 |
function createOptionsObserver({ overflow = "constrain", disambiguation = "compatible", offset = "reject" } = {}) { |
| 85 |
return TemporalHelpers.propertyBagObserver(actual, { |
| 86 |
overflow, |
| 87 |
disambiguation, |
| 88 |
offset, |
| 89 |
extra: "property", |
| 90 |
}, "options"); |
| 91 |
} |
| 92 |
|
| 93 |
const options = createOptionsObserver(); |
| 94 |
Temporal.ZonedDateTime.from(from, options); |
| 95 |
assert.compareArray(actual, expected, "order of operations"); |
| 96 |
|
| 97 |
actual.splice(0); // clear for next test |
| 98 |
|
| 99 |
Temporal.ZonedDateTime.from(new Temporal.ZonedDateTime(0n, "UTC"), options); |
| 100 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when cloning a ZonedDateTime instance"); |
| 101 |
|
| 102 |
actual.splice(0); |
| 103 |
|
| 104 |
Temporal.ZonedDateTime.from("2001-05-02T06:54:32.987654321+00:00[UTC]", options); |
| 105 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string"); |
| 106 |
|
| 107 |
reportCompare(0, 0); |