tor-browser

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

results-object-from-array.js (1389B)


      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  Calling Iterator.zipKeyed with an array object.
      8 info: |
      9  Iterator.zipKeyed ( iterables [ , options ] )
     10    ...
     11    15. Let finishResults be a new Abstract Closure with parameters (results) that captures keys and iterCount and performs the following steps when called:
     12      a. Let obj be OrdinaryObjectCreate(null).
     13      b. For each integer i such that 0 ≤ i < iterCount, in ascending order, do
     14        i. Perform ! CreateDataPropertyOrThrow(obj, keys[i], results[i]).
     15      c. Return obj.
     16    ...
     17 features: [joint-iteration]
     18 ---*/
     19 
     20 var iterables = [
     21  [1, 2, 3],
     22  [4, 5, 6],
     23 ];
     24 
     25 var it = Iterator.zipKeyed(iterables);
     26 
     27 for (var i = 0; i < iterables[0].length; ++i) {
     28  var results = it.next().value;
     29 
     30  assert.sameValue(
     31    Object.getPrototypeOf(results),
     32    null,
     33    "results prototype is null"
     34  );
     35 
     36  assert.sameValue(
     37    Reflect.ownKeys(results).length,
     38    iterables.length,
     39    "results has correct number of properties"
     40  );
     41 
     42  for (var j = 0; j < iterables.length; ++j) {
     43    assert.sameValue(
     44      results[j],
     45      iterables[j][i],
     46      "results property value has the correct value"
     47    );
     48  }
     49 }
     50 
     51 assert.sameValue(it.next().done, true, "iterator is exhausted");
     52 
     53 reportCompare(0, 0);