tor-browser

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

order-of-operations.js (7791B)


      1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally
      2 // Copyright (C) 2022 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.duration.compare
      7 description: Properties on objects passed to compare() are accessed in the correct order
      8 includes: [compareArray.js, temporalHelpers.js]
      9 features: [Temporal]
     10 ---*/
     11 
     12 const expected = [
     13  // ToTemporalDuration on first argument
     14  "get one.days",
     15  "get one.days.valueOf",
     16  "call one.days.valueOf",
     17  "get one.hours",
     18  "get one.hours.valueOf",
     19  "call one.hours.valueOf",
     20  "get one.microseconds",
     21  "get one.microseconds.valueOf",
     22  "call one.microseconds.valueOf",
     23  "get one.milliseconds",
     24  "get one.milliseconds.valueOf",
     25  "call one.milliseconds.valueOf",
     26  "get one.minutes",
     27  "get one.minutes.valueOf",
     28  "call one.minutes.valueOf",
     29  "get one.months",
     30  "get one.months.valueOf",
     31  "call one.months.valueOf",
     32  "get one.nanoseconds",
     33  "get one.nanoseconds.valueOf",
     34  "call one.nanoseconds.valueOf",
     35  "get one.seconds",
     36  "get one.seconds.valueOf",
     37  "call one.seconds.valueOf",
     38  "get one.weeks",
     39  "get one.weeks.valueOf",
     40  "call one.weeks.valueOf",
     41  "get one.years",
     42  "get one.years.valueOf",
     43  "call one.years.valueOf",
     44  // ToTemporalDuration on second argument
     45  "get two.days",
     46  "get two.days.valueOf",
     47  "call two.days.valueOf",
     48  "get two.hours",
     49  "get two.hours.valueOf",
     50  "call two.hours.valueOf",
     51  "get two.microseconds",
     52  "get two.microseconds.valueOf",
     53  "call two.microseconds.valueOf",
     54  "get two.milliseconds",
     55  "get two.milliseconds.valueOf",
     56  "call two.milliseconds.valueOf",
     57  "get two.minutes",
     58  "get two.minutes.valueOf",
     59  "call two.minutes.valueOf",
     60  "get two.months",
     61  "get two.months.valueOf",
     62  "call two.months.valueOf",
     63  "get two.nanoseconds",
     64  "get two.nanoseconds.valueOf",
     65  "call two.nanoseconds.valueOf",
     66  "get two.seconds",
     67  "get two.seconds.valueOf",
     68  "call two.seconds.valueOf",
     69  "get two.weeks",
     70  "get two.weeks.valueOf",
     71  "call two.weeks.valueOf",
     72  "get two.years",
     73  "get two.years.valueOf",
     74  "call two.years.valueOf",
     75  // ToRelativeTemporalObject
     76  "get options.relativeTo",
     77 ];
     78 const actual = [];
     79 
     80 // basic order of observable operations with no relativeTo
     81 Temporal.Duration.compare(
     82  createDurationPropertyBagObserver("one", 0, 0, 0, 7),
     83  createDurationPropertyBagObserver("two", 0, 0, 0, 6),
     84  createOptionsObserver(undefined)
     85 );
     86 assert.compareArray(actual, expected, "order of operations");
     87 actual.splice(0); // clear
     88 
     89 const baseExpectedOpsWithRelativeTo = expected.concat([
     90  // ToRelativeTemporalObject
     91  "get options.relativeTo.calendar",
     92  "get options.relativeTo.day",
     93  "get options.relativeTo.day.valueOf",
     94  "call options.relativeTo.day.valueOf",
     95  "get options.relativeTo.hour",
     96 ]);
     97 
     98 const expectedOpsForPlainRelativeTo = baseExpectedOpsWithRelativeTo.concat([
     99  // ToRelativeTemporalObject, continued
    100  "get options.relativeTo.microsecond",
    101  "get options.relativeTo.millisecond",
    102  "get options.relativeTo.minute",
    103  "get options.relativeTo.month",
    104  "get options.relativeTo.month.valueOf",
    105  "call options.relativeTo.month.valueOf",
    106  "get options.relativeTo.monthCode",
    107  "get options.relativeTo.monthCode.toString",
    108  "call options.relativeTo.monthCode.toString",
    109  "get options.relativeTo.nanosecond",
    110  "get options.relativeTo.offset",
    111  "get options.relativeTo.second",
    112  "get options.relativeTo.timeZone",
    113  "get options.relativeTo.year",
    114  "get options.relativeTo.year.valueOf",
    115  "call options.relativeTo.year.valueOf",
    116 ]);
    117 
    118 const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
    119  year: 2001,
    120  month: 5,
    121  monthCode: "M05",
    122  day: 2,
    123  calendar: "iso8601",
    124 }, "options.relativeTo", ["calendar"]);
    125 
    126 function createOptionsObserver(relativeTo = undefined) {
    127  return TemporalHelpers.propertyBagObserver(actual, { relativeTo }, "options");
    128 }
    129 
    130 function createDurationPropertyBagObserver(name, y = 0, mon = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0) {
    131  return TemporalHelpers.propertyBagObserver(actual, {
    132    years: y,
    133    months: mon,
    134    weeks: w,
    135    days: d,
    136    hours: h,
    137    minutes: min,
    138    seconds: s,
    139    milliseconds: ms,
    140    microseconds: µs,
    141    nanoseconds: ns,
    142  }, name);
    143 }
    144 
    145 // order of observable operations with plain relativeTo and without calendar units
    146 Temporal.Duration.compare(
    147  createDurationPropertyBagObserver("one", 0, 0, 0, 7),
    148  createDurationPropertyBagObserver("two", 0, 0, 0, 6),
    149  createOptionsObserver(plainRelativeTo)
    150 );
    151 assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo and no calendar units");
    152 actual.splice(0); // clear
    153 
    154 const expectedOpsForZonedRelativeTo = baseExpectedOpsWithRelativeTo.concat([
    155  // ToRelativeTemporalObject, continued
    156  "get options.relativeTo.hour.valueOf",
    157  "call options.relativeTo.hour.valueOf",
    158  "get options.relativeTo.microsecond",
    159  "get options.relativeTo.microsecond.valueOf",
    160  "call options.relativeTo.microsecond.valueOf",
    161  "get options.relativeTo.millisecond",
    162  "get options.relativeTo.millisecond.valueOf",
    163  "call options.relativeTo.millisecond.valueOf",
    164  "get options.relativeTo.minute",
    165  "get options.relativeTo.minute.valueOf",
    166  "call options.relativeTo.minute.valueOf",
    167  "get options.relativeTo.month",
    168  "get options.relativeTo.month.valueOf",
    169  "call options.relativeTo.month.valueOf",
    170  "get options.relativeTo.monthCode",
    171  "get options.relativeTo.monthCode.toString",
    172  "call options.relativeTo.monthCode.toString",
    173  "get options.relativeTo.nanosecond",
    174  "get options.relativeTo.nanosecond.valueOf",
    175  "call options.relativeTo.nanosecond.valueOf",
    176  "get options.relativeTo.offset",
    177  "get options.relativeTo.offset.toString",
    178  "call options.relativeTo.offset.toString",
    179  "get options.relativeTo.second",
    180  "get options.relativeTo.second.valueOf",
    181  "call options.relativeTo.second.valueOf",
    182  "get options.relativeTo.timeZone",
    183  "get options.relativeTo.year",
    184  "get options.relativeTo.year.valueOf",
    185  "call options.relativeTo.year.valueOf",
    186 ]);
    187 
    188 const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, {
    189  year: 2001,
    190  month: 5,
    191  monthCode: "M05",
    192  day: 2,
    193  hour: 6,
    194  minute: 54,
    195  second: 32,
    196  millisecond: 987,
    197  microsecond: 654,
    198  nanosecond: 321,
    199  offset: "+00:00",
    200  calendar: "iso8601",
    201  timeZone: "UTC",
    202 }, "options.relativeTo", ["calendar", "timeZone"]);
    203 
    204 // order of observable operations with zoned relativeTo and without calendar units except days
    205 Temporal.Duration.compare(
    206  createDurationPropertyBagObserver("one", 0, 0, 0, 7),
    207  createDurationPropertyBagObserver("two", 0, 0, 0, 6),
    208  createOptionsObserver(zonedRelativeTo)
    209 );
    210 assert.compareArray(
    211  actual,
    212  expectedOpsForZonedRelativeTo,
    213  "order of operations with ZonedDateTime relativeTo and no calendar units except days"
    214 );
    215 actual.splice(0); // clear
    216 
    217 // order of observable operations with zoned relativeTo and with only time units
    218 Temporal.Duration.compare(
    219  createDurationPropertyBagObserver("one", 0, 0, 0, 0, 7),
    220  createDurationPropertyBagObserver("two", 0, 0, 0, 0, 6),
    221  createOptionsObserver(zonedRelativeTo)
    222 );
    223 assert.compareArray(
    224  actual,
    225  expectedOpsForZonedRelativeTo,
    226  "order of operations with ZonedDateTime relativeTo and only time units"
    227 );
    228 actual.splice(0); // clear
    229 
    230 // order of observable operations with zoned relativeTo and calendar units
    231 Temporal.Duration.compare(
    232  createDurationPropertyBagObserver("one", 1, 1, 1),
    233  createDurationPropertyBagObserver("two", 1, 1, 1, 1),
    234  createOptionsObserver(zonedRelativeTo)
    235 );
    236 assert.compareArray(
    237  actual,
    238  expectedOpsForZonedRelativeTo,
    239  "order of operations with ZonedDateTime relativeTo and calendar units"
    240 );
    241 actual.splice(0); // clear
    242 
    243 reportCompare(0, 0);