| 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.plaindate.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 |
"get options.overflow", |
| 14 |
"get options.overflow.toString", |
| 15 |
"call options.overflow.toString", |
| 16 |
]; |
| 17 |
|
| 18 |
const expected = [ |
| 19 |
"get fields.calendar", |
| 20 |
"get fields.day", |
| 21 |
"get fields.day.valueOf", |
| 22 |
"call fields.day.valueOf", |
| 23 |
"get fields.month", |
| 24 |
"get fields.month.valueOf", |
| 25 |
"call fields.month.valueOf", |
| 26 |
"get fields.monthCode", |
| 27 |
"get fields.monthCode.toString", |
| 28 |
"call fields.monthCode.toString", |
| 29 |
"get fields.year", |
| 30 |
"get fields.year.valueOf", |
| 31 |
"call fields.year.valueOf", |
| 32 |
].concat(expectedOptionsReading); |
| 33 |
const actual = []; |
| 34 |
|
| 35 |
const fields = TemporalHelpers.propertyBagObserver(actual, { |
| 36 |
year: 1.7, |
| 37 |
month: 1.7, |
| 38 |
monthCode: "M01", |
| 39 |
day: 1.7, |
| 40 |
calendar: "iso8601", |
| 41 |
}, "fields", ["calendar"]); |
| 42 |
|
| 43 |
const options = TemporalHelpers.propertyBagObserver(actual, { |
| 44 |
overflow: "constrain", |
| 45 |
extra: "property", |
| 46 |
}, "options"); |
| 47 |
|
| 48 |
const result = Temporal.PlainDate.from(fields, options); |
| 49 |
assert.compareArray(actual, expected, "order of operations"); |
| 50 |
|
| 51 |
actual.splice(0); // clear for next test |
| 52 |
|
| 53 |
Temporal.PlainDate.from(new Temporal.PlainDate(2000, 5, 2), options); |
| 54 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when cloning a PlainDate instance"); |
| 55 |
|
| 56 |
actual.splice(0); |
| 57 |
|
| 58 |
Temporal.PlainDate.from(new Temporal.PlainDateTime(2000, 5, 2), options); |
| 59 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a PlainDateTime instance"); |
| 60 |
|
| 61 |
actual.splice(0); |
| 62 |
|
| 63 |
Temporal.PlainDate.from(new Temporal.ZonedDateTime(0n, "UTC"), options); |
| 64 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a ZonedDateTime instance"); |
| 65 |
|
| 66 |
actual.splice(0); |
| 67 |
|
| 68 |
Temporal.PlainDate.from("2001-05-02", options); |
| 69 |
assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string"); |
| 70 |
|
| 71 |
reportCompare(0, 0); |