tor-browser

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

order-of-operations.js (2493B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2020 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.plaintime.from
      7 description: Properties on an object passed to from() are accessed in the correct order
      8 includes: [compareArray.js, temporalHelpers.js]
      9 features: [Temporal]
     10 ---*/
     11 
     12 const expectedOptionsReading = [
     13  // GetTemporalOverflowOption
     14  "get options.overflow",
     15  "get options.overflow.toString",
     16  "call options.overflow.toString",
     17 ];
     18 
     19 const expected = [
     20  // ToTemporalTimeRecord
     21  "get fields.hour",
     22  "get fields.hour.valueOf",
     23  "call fields.hour.valueOf",
     24  "get fields.microsecond",
     25  "get fields.microsecond.valueOf",
     26  "call fields.microsecond.valueOf",
     27  "get fields.millisecond",
     28  "get fields.millisecond.valueOf",
     29  "call fields.millisecond.valueOf",
     30  "get fields.minute",
     31  "get fields.minute.valueOf",
     32  "call fields.minute.valueOf",
     33  "get fields.nanosecond",
     34  "get fields.nanosecond.valueOf",
     35  "call fields.nanosecond.valueOf",
     36  "get fields.second",
     37  "get fields.second.valueOf",
     38  "call fields.second.valueOf",
     39 ].concat(expectedOptionsReading);
     40 const actual = [];
     41 
     42 const fields = TemporalHelpers.propertyBagObserver(actual, {
     43  hour: 1.7,
     44  minute: 1.7,
     45  second: 1.7,
     46  millisecond: 1.7,
     47  microsecond: 1.7,
     48  nanosecond: 1.7,
     49  calendar: "iso8601",
     50 }, "fields");
     51 
     52 const options = TemporalHelpers.propertyBagObserver(actual, {
     53  overflow: "constrain",
     54 }, "options");
     55 
     56 const result = Temporal.PlainTime.from(fields, options);
     57 assert.compareArray(actual, expected, "order of operations");
     58 
     59 actual.splice(0);  // clear for next test
     60 
     61 Temporal.PlainTime.from(new Temporal.PlainTime(12, 34), options);
     62 assert.compareArray(actual, expectedOptionsReading, "order of operations when cloning a PlainTime instance");
     63 
     64 actual.splice(0);
     65 
     66 Temporal.PlainTime.from(new Temporal.PlainDateTime(2000, 5, 2), options);
     67 assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a PlainDateTime instance");
     68 
     69 actual.splice(0);
     70 
     71 Temporal.PlainTime.from(new Temporal.ZonedDateTime(0n, "UTC"), options);
     72 assert.compareArray(actual, expectedOptionsReading, "order of operations when converting a ZonedDateTime instance");
     73 
     74 actual.splice(0);
     75 
     76 Temporal.PlainTime.from("12:34", options);
     77 assert.compareArray(actual, expectedOptionsReading, "order of operations when parsing a string");
     78 
     79 reportCompare(0, 0);