Debian Codegraph @

js/src/tests/test262/intl402/Temporal/PlainYearMonth/from/infinity-throws-rangeerror.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) 2021 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 description: Throws if eraYear in the property bag is Infinity or -Infinity
7 esid: sec-temporal.plainyearmonth.from
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const base = { era: "ad", month: 5, calendar: "gregory" };
13
14 [Infinity, -Infinity].forEach((inf) => {
15 ["constrain", "reject"].forEach((overflow) => {
16 assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ ...base, eraYear: inf }, { overflow }), `eraYear property cannot be ${inf} (overflow ${overflow}`);
17
18 const calls = [];
19 const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, "eraYear");
20 assert.throws(RangeError, () => Temporal.PlainYearMonth.from({ ...base, eraYear: obj }, { overflow }));
21 assert.compareArray(calls, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value");
22 });
23 });
24
25 reportCompare(0, 0);