Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainDate/compare/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 a property bag for either argument is Infinity or -Infinity
7 esid: sec-temporal.plaindate.compare
8 includes: [compareArray.js, temporalHelpers.js]
9 features: [Temporal]
10 ---*/
11
12 const other = new Temporal.PlainDate(2000, 5, 2);
13 const base = { year: 2000, month: 5, day: 2 };
14
15 [Infinity, -Infinity].forEach((inf) => {
16 ["year", "month", "day"].forEach((prop) => {
17 assert.throws(RangeError, () => Temporal.PlainDate.compare({ ...base, [prop]: inf }, other), `${prop} property cannot be ${inf}`);
18
19 assert.throws(RangeError, () => Temporal.PlainDate.compare(other, { ...base, [prop]: inf }), `${prop} property cannot be ${inf}`);
20
21 const calls1 = [];
22 const obj1 = TemporalHelpers.toPrimitiveObserver(calls1, inf, prop);
23 assert.throws(RangeError, () => Temporal.PlainDate.compare({ ...base, [prop]: obj1 }, other));
24 assert.compareArray(calls1, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
25
26 const calls2 = [];
27 const obj2 = TemporalHelpers.toPrimitiveObserver(calls2, inf, prop);
28 assert.throws(RangeError, () => Temporal.PlainDate.compare(other, { ...base, [prop]: obj2 }));
29 assert.compareArray(calls2, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value");
30 });
31 });
32
33 reportCompare(0, 0);