| 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.plaindate |
| 7 |
description: PlainDate constructor with non-integer arguments. |
| 8 |
includes: [compareArray.js, temporalHelpers.js] |
| 9 |
features: [Temporal] |
| 10 |
---*/ |
| 11 |
|
| 12 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(2020.6, 11.7, 24.1), |
| 13 |
2020, 11, "M11", 24, "positive fractional"); |
| 14 |
|
| 15 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(-2020.6, 11.7, 24.1), |
| 16 |
-2020, 11, "M11", 24, "negative fractional"); |
| 17 |
|
| 18 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(null, 11, 24), |
| 19 |
0, 11, "M11", 24, "null"); |
| 20 |
|
| 21 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(true, 11, 24), |
| 22 |
1, 11, "M11", 24, "boolean"); |
| 23 |
|
| 24 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate("2020.6", "11.7", "24.1"), |
| 25 |
2020, 11, "M11", 24, "fractional strings"); |
| 26 |
|
| 27 |
for (const invalid of [Symbol(), 1n]) { |
| 28 |
assert.throws(TypeError, () => new Temporal.PlainDate(invalid, 11, 24), `year ${typeof invalid}`); |
| 29 |
assert.throws(TypeError, () => new Temporal.PlainDate(2020, invalid, 24), `month ${typeof invalid}`); |
| 30 |
assert.throws(TypeError, () => new Temporal.PlainDate(2020, 11, invalid), `day ${typeof invalid}`); |
| 31 |
} |
| 32 |
|
| 33 |
for (const invalid of [undefined, "invalid"]) { |
| 34 |
assert.throws(RangeError, () => new Temporal.PlainDate(invalid, 11, 24), `year ${typeof invalid}`); |
| 35 |
assert.throws(RangeError, () => new Temporal.PlainDate(2020, invalid, 24), `month ${typeof invalid}`); |
| 36 |
assert.throws(RangeError, () => new Temporal.PlainDate(2020, 11, invalid), `day ${typeof invalid}`); |
| 37 |
} |
| 38 |
const actual = []; |
| 39 |
const args = [ |
| 40 |
TemporalHelpers.toPrimitiveObserver(actual, 2020, "year"), |
| 41 |
TemporalHelpers.toPrimitiveObserver(actual, 11, "month"), |
| 42 |
TemporalHelpers.toPrimitiveObserver(actual, 24, "day"), |
| 43 |
]; |
| 44 |
TemporalHelpers.assertPlainDate(new Temporal.PlainDate(...args), |
| 45 |
2020, 11, "M11", 24, "invalid string"); |
| 46 |
assert.compareArray(actual, [ |
| 47 |
"get year.valueOf", |
| 48 |
"call year.valueOf", |
| 49 |
"get month.valueOf", |
| 50 |
"call month.valueOf", |
| 51 |
"get day.valueOf", |
| 52 |
"call day.valueOf", |
| 53 |
]); |
| 54 |
|
| 55 |
reportCompare(0, 0); |