tor-browser

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

argument-string-limits.js (1463B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2024 Igalia, S.L. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-temporal.instant.compare
      7 description: ISO strings at the edges of the representable range
      8 features: [Temporal]
      9 ---*/
     10 
     11 const instance = new Temporal.Instant(0n);
     12 
     13 const validStrings = [
     14  "-271821-04-20T00:00Z",
     15  "-271821-04-19T23:00-01:00",
     16  "-271821-04-19T00:00:00.000000001-23:59:59.999999999",
     17  "+275760-09-13T00:00Z",
     18  "+275760-09-13T01:00+01:00",
     19  "+275760-09-13T23:59:59.999999999+23:59:59.999999999",
     20 ];
     21 
     22 for (const arg of validStrings) {
     23  Temporal.Instant.compare(arg, instance);
     24  Temporal.Instant.compare(instance, arg);
     25 }
     26 
     27 const invalidStrings = [
     28  "-271821-04-19T23:59:59.999999999Z",
     29  "-271821-04-19T23:00-00:59:59.999999999",
     30  "-271821-04-19T00:00:00-23:59:59.999999999",
     31  "+275760-09-13T00:00:00.000000001Z",
     32  "+275760-09-13T01:00+00:59:59.999999999",
     33  "+275760-09-14T00:00+23:59:59.999999999",
     34 ];
     35 
     36 for (const arg of invalidStrings) {
     37  assert.throws(
     38    RangeError,
     39    () => Temporal.Instant.compare(arg, instance),
     40    `"${arg}" is outside the representable range of Instant (first argument)`
     41  );
     42  assert.throws(
     43    RangeError,
     44    () => Temporal.Instant.compare(instance, arg),
     45    `"${arg}" is outside the representable range of Instant (second argument)`
     46  );
     47 }
     48 
     49 reportCompare(0, 0);