tor-browser

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

results-object-has-default-attributes.js (2551B)


      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  Returned object has the correct prototype and default property attributes.
      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 includes: [compareArray.js, propertyHelper.js]
     18 features: [joint-iteration]
     19 ---*/
     20 
     21 // Assert |actual| is a plain object equal to |expected| with default property attributes.
     22 function assertPlainObject(actual, expected) {
     23  assert.sameValue(
     24    Object.getPrototypeOf(actual),
     25    null,
     26    "[[Prototype]] of actual is null"
     27  );
     28 
     29  assert(Object.isExtensible(actual), "actual is extensible");
     30 
     31  var actualKeys = Reflect.ownKeys(actual);
     32  var expectedKeys = Reflect.ownKeys(expected);
     33 
     34  // All expected property keys are present.
     35  assert.compareArray(actualKeys, expectedKeys);
     36 
     37  // All expected property values are equal.
     38  for (var key of expectedKeys) {
     39    assert.sameValue(actual[key], expected[key], "with key: " + String(key));
     40  }
     41 
     42  // Ensure all properties have the default property attributes.
     43  for (var key of expectedKeys) {
     44    verifyProperty(actual, key, {
     45      writable: true,
     46      enumerable: true,
     47      configurable: true,
     48    });
     49  }
     50 }
     51 
     52 var iterables = Object.create(null, {
     53  a: {
     54    writable: true,
     55    enumerable: true,
     56    configurable: true,
     57    value: ["A"],
     58  },
     59  b: {
     60    writable: false,
     61    enumerable: true,
     62    configurable: true,
     63    value: ["B"],
     64  },
     65  c: {
     66    writable: true,
     67    enumerable: true,
     68    configurable: false,
     69    value: ["C"],
     70  },
     71  d: {
     72    writable: false,
     73    enumerable: true,
     74    configurable: false,
     75    value: ["D"],
     76  },
     77  e: {
     78    enumerable: true,
     79    configurable: true,
     80    get() {
     81      return ["E"];
     82    }
     83  },
     84  f: {
     85    enumerable: true,
     86    configurable: false,
     87    get() {
     88      return ["F"];
     89    }
     90  },
     91 });
     92 
     93 var it = Iterator.zipKeyed(iterables);
     94 
     95 var results = it.next().value;
     96 
     97 assertPlainObject(results, {
     98  a: "A",
     99  b: "B",
    100  c: "C",
    101  d: "D",
    102  e: "E",
    103  f: "F",
    104 });
    105 
    106 assert.sameValue(it.next().done, true, "iterator is exhausted");
    107 
    108 reportCompare(0, 0);