Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainTime/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.plaintime.from
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const base = { hour: 15, minute: 30, second: 45, millisecond: 987, microsecond: 654, nanosecond: 321 };
13
14 [Infinity, -Infinity].forEach((inf) => {
15 ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((prop) => {
16 ["constrain", "reject"].forEach((overflow) => {
17 assert.throws(RangeError, () => Temporal.PlainTime.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.PlainTime.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);