Debian Codegraph @

js/src/tests/test262/intl402/Temporal/PlainYearMonth/compare/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 any value in a property bag for either argument is Infinity or -Infinity
7 esid: sec-temporal.plainyearmonth.compare
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const other = new Temporal.PlainYearMonth(2000, 5, "gregory");
13 const base = { era: "ad", month: 5, calendar: "gregory" };
14
15 [Infinity, -Infinity].forEach((inf) => {
16 assert.throws(RangeError, () => Temporal.PlainYearMonth.compare({ ...base, eraYear: inf }, other), `eraYear property cannot be ${inf}`);
17
18 assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(other, { ...base, eraYear: inf }), `eraYear property cannot be ${inf}`);
19
20 const calls1 = [];
21 const obj1 = TemporalHelpers.toPrimitiveObserver(calls1, inf, "eraYear");
22 assert.throws(RangeError, () => Temporal.PlainYearMonth.compare({ ...base, eraYear: obj1 }, other));
23 assert.compareArray(calls1, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value");
24
25 const calls2 = [];
26 const obj2 = TemporalHelpers.toPrimitiveObserver(calls2, inf, "eraYear");
27 assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(other, { ...base, eraYear: obj2 }));
28 assert.compareArray(calls2, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value");
29 });
30
31 reportCompare(0, 0);