tor-browser

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

constructor-option-read-order.js (1609B)


      1 // Copyright 2023 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-initializenumberformat
      6 description: Checks the order of option read.
      7 features: [Intl.NumberFormat-v3]
      8 includes: [compareArray.js]
      9 ---*/
     10 
     11 let optionKeys = [
     12    // Inside InitializeNumberFormat
     13    "localeMatcher",
     14    "numberingSystem",
     15    // Inside SetNumberFormatUnitOptions
     16        "style",
     17        "currency",
     18        "currencyDisplay",
     19        "currencySign",
     20        "unit",
     21        "unitDisplay",
     22    // End of SetNumberFormatUnitOptions
     23    // Back to InitializeNumberFormat
     24    "notation",
     25    // Inside SetNumberFormatDigitOptions
     26        "minimumIntegerDigits",
     27        "minimumFractionDigits",
     28        "maximumFractionDigits",
     29        "minimumSignificantDigits",
     30        "maximumSignificantDigits",
     31        "roundingIncrement",
     32        "roundingMode",
     33        "roundingPriority",
     34        "trailingZeroDisplay",
     35    // End of SetNumberFormatDigitOptions
     36    // Back to InitializeNumberFormat
     37    "compactDisplay",
     38    "useGrouping",
     39    "signDisplay"
     40 ];
     41 
     42 // Use getters to track the order of reading known properties.
     43 // TODO: Should we use a Proxy to detect *unexpected* property reads?
     44 let reads = new Array();
     45 let options = {};
     46 optionKeys.forEach((key) => {
     47    Object.defineProperty(options, key, {
     48        get() {
     49            reads.push(key);
     50            return undefined;
     51        },
     52    });
     53 });
     54 new Intl.NumberFormat(undefined, options);
     55 assert.compareArray(reads, optionKeys, "Intl.NumberFormat options read order");
     56 
     57 reportCompare(0, 0);