Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / intl402 / Temporal / PlainYearMonth / compare / infinity-throws-rangeerror.js
blob4ee79a26e601308122b50d5c5e68c0b620ec51dc
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
2 // Copyright (C) 2021 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
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 ---*/
12 const other = new Temporal.PlainYearMonth(2000, 5, "gregory");
13 const base = { era: "ad", month: 5, calendar: "gregory" };
15 [Infinity, -Infinity].forEach((inf) => {
16   assert.throws(RangeError, () => Temporal.PlainYearMonth.compare({ ...base, eraYear: inf }, other), `eraYear property cannot be ${inf}`);
18   assert.throws(RangeError, () => Temporal.PlainYearMonth.compare(other, { ...base, eraYear: inf }), `eraYear property cannot be ${inf}`);
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");
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 });
31 reportCompare(0, 0);