tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

infinity-throws-rangeerror.js (1626B)


      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 any value in a property bag for either argument is Infinity or -Infinity
      7 esid: sec-temporal.zoneddatetime.compare
      8 includes: [compareArray.js, temporalHelpers.js]
      9 features: [Temporal]
     10 ---*/
     11 
     12 const other = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "gregory");
     13 const base = { era: "ad", month: 5, day: 2, hour: 15, timeZone: "UTC", calendar: "gregory" };
     14 
     15 [Infinity, -Infinity].forEach((inf) => {
     16  assert.throws(RangeError, () => Temporal.ZonedDateTime.compare({ ...base, eraYear: inf }, other), `eraYear property cannot be ${inf}`);
     17 
     18  assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(other, { ...base, eraYear: inf }), `eraYear property cannot be ${inf}`);
     19 
     20  const calls1 = [];
     21  const obj1 = TemporalHelpers.toPrimitiveObserver(calls1, inf, "eraYear");
     22  assert.throws(RangeError, () => Temporal.ZonedDateTime.compare({ ...base, eraYear: obj1 }, other));
     23  assert.compareArray(calls1, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value");
     24 
     25  const calls2 = [];
     26  const obj2 = TemporalHelpers.toPrimitiveObserver(calls2, inf, "eraYear");
     27  assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(other, { ...base, eraYear: obj2 }));
     28  assert.compareArray(calls2, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value");
     29 });
     30 
     31 reportCompare(0, 0);