tor-browser

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

iterables-iteration-after-reading-options.js (1442B)


      1 // Copyright (C) 2025 André Bargull. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-iterator.zipkeyed
      6 description: >
      7  Perform [[OwnPropertyKeys]] on the "iterables" argument after reading all properties.
      8 info: |
      9  Iterator.zipKeyed ( iterables [ , options ] )
     10    ...
     11    3. Let mode be ? Get(options, "mode").
     12    ...
     13    7. If mode is "longest", then
     14      a. Set paddingOption to ? Get(options, "padding").
     15    ...
     16    10. Let allKeys be ? iterables.[[OwnPropertyKeys]]().
     17    ...
     18 includes: [proxyTrapsHelper.js, compareArray.js]
     19 features: [joint-iteration]
     20 ---*/
     21 
     22 var log = [];
     23 
     24 var iterables = new Proxy({}, allowProxyTraps({
     25  ownKeys(target) {
     26    log.push("own-keys");
     27    return Reflect.ownKeys(target);
     28  },
     29 }));
     30 
     31 
     32 var options = {
     33  get mode() {
     34    log.push("get mode");
     35    return "longest";
     36  },
     37  get padding() {
     38    log.push("get padding");
     39    return [];
     40  }
     41 };
     42 
     43 Iterator.zipKeyed(iterables, options);
     44 
     45 assert.compareArray(log, [
     46  "get mode",
     47  "get padding",
     48  "own-keys",
     49 ]);
     50 
     51 for (var mode of [undefined, "shortest", "strict"]) {
     52  log.length = 0;
     53 
     54  options = {
     55    get mode() {
     56      log.push("get mode");
     57      return mode;
     58    },
     59    get padding() {
     60      log.push("unexpected get padding");
     61      return [];
     62    }
     63  };
     64 
     65  Iterator.zipKeyed(iterables, options);
     66 
     67  assert.compareArray(log, [
     68    "get mode",
     69    "own-keys",
     70  ]);
     71 }
     72 
     73 reportCompare(0, 0);