infinity-throws-rangeerror.js (1101B)
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. 4 5 /*--- 6 description: Throws if eraYear in the property bag is Infinity or -Infinity 7 esid: sec-temporal.plaindate.from 8 includes: [compareArray.js, temporalHelpers.js] 9 features: [Temporal] 10 ---*/ 11 12 const base = { era: "ad", month: 5, day: 2, calendar: "gregory" }; 13 14 [Infinity, -Infinity].forEach((inf) => { 15 ["constrain", "reject"].forEach((overflow) => { 16 assert.throws(RangeError, () => Temporal.PlainDate.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.PlainDate.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);