Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainDate/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 any value 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 = { year: 2000, month: 5, day: 2 };
13
14 [Infinity, -Infinity].forEach((inf) => {
15 ["year", "month", "day"].forEach((prop) => {
16 ["constrain", "reject"].forEach((overflow) => {
17 assert.throws(RangeError, () => Temporal.PlainDate.from({ ...base, [prop]: inf }, { overflow }), `${prop} property cannot be ${inf} (overflow ${overflow}`);
18
19 const calls = [];
20 const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop);
21 assert.throws(RangeError, () => Temporal.PlainDate.from({ ...base, [prop]: obj }, { overflow }));
22 assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
23 });
24 });
25 });
26
27 reportCompare(0, 0);