Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainYearMonth/from/argument-object.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) 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.plainyearmonth.from
7 description: An object argument
8 includes: [temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 2019, monthCode: "M11" }),
13 2019, 11, "M11", "Only monthCode");
14 TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 2019, month: 11 }),
15 2019, 11, "M11", "Only month");
16 assert.throws(RangeError,
17 () => Temporal.PlainYearMonth.from({ year: 2019, month: 11, monthCode: "M12" }),
18 "Mismatch between month and monthCode");
19
20 const monthDayItem = { year: 2019, month: 11, get day() { throw new Test262Error("should not read the day property") } };
21 TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthDayItem),
22 2019, 11, "M11", "month with day");
23
24 const monthCodeDayItem = { year: 2019, monthCode: "M11", get day() { throw new Test262Error("should not read the day property") } };
25 TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from(monthCodeDayItem),
26 2019, 11, "M11", "monthCode with day");
27
28 assert.throws(TypeError,
29 () => Temporal.PlainYearMonth.from({}),
30 "No properties");
31 assert.throws(TypeError,
32 () => Temporal.PlainYearMonth.from({ year: 2019 }),
33 "Only year");
34 assert.throws(TypeError,
35 () => Temporal.PlainYearMonth.from({ year: 2019, months: 6 }),
36 "Year and plural 'months'");
37 assert.throws(TypeError,
38 () => Temporal.PlainYearMonth.from({ month: 6 }),
39 "Only month");
40 assert.throws(TypeError,
41 () => Temporal.PlainYearMonth.from({ monthCode: "M06" }),
42 "Only monthCode");
43 assert.throws(TypeError,
44 () => Temporal.PlainYearMonth.from({ year: undefined, month: 6 }),
45 "year explicit undefined");
46
47 TemporalHelpers.assertPlainYearMonth(Temporal.PlainYearMonth.from({ year: 1976, month: 11, months: 12 }),
48 1976, 11, "M11", "Plural property ignored");
49
50 reportCompare(0, 0);