Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/Duration/compare/relativeto-propertybag-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 relativeTo property bag is Infinity or -Infinity
7 esid: sec-temporal.duration.compare
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const duration1 = new Temporal.Duration(0, 0, 0, 1);
13 const duration2 = new Temporal.Duration(0, 0, 0, 0, 24);
14 const base = { year: 2000, month: 5, day: 2, hour: 15, minute: 30, second: 45, millisecond: 987, microsecond: 654, nanosecond: 321 };
15
16 [Infinity, -Infinity].forEach((inf) => {
17 ["year", "month", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((prop) => {
18 assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: { ...base, [prop]: inf } }), `${prop} property cannot be ${inf} in relativeTo`);
19
20 const calls = [];
21 const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop);
22 assert.throws(RangeError, () => Temporal.Duration.compare(duration1, duration2, { relativeTo: { ...base, [prop]: obj } }));
23 assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
24 });
25 });
26
27 reportCompare(0, 0);