tor-browser

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

options-mode.js (1878B)


      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  The "mode" option must be undefined or a valid string mode.
      8 info: |
      9  Iterator.zipKeyed ( iterables [ , options ] )
     10    ...
     11    3. Let mode be ? Get(options, "mode").
     12    4. If mode is undefined, set mode to "shortest".
     13    5. If mode is not one of "shortest", "longest", or "strict", throw a TypeError exception.
     14    ...
     15 features: [joint-iteration]
     16 ---*/
     17 
     18 var validModes = [
     19  undefined,
     20  "shortest",
     21  "longest",
     22  "strict",
     23 ];
     24 
     25 var invalidModes = [
     26  null,
     27  false,
     28  "",
     29  "short",
     30  "long",
     31  "loose",
     32  Symbol(),
     33  123,
     34  123n,
     35  {},
     36 ];
     37 
     38 // Absent "mode" option.
     39 Iterator.zipKeyed({}, {});
     40 
     41 // All valid mode values are accepted.
     42 for (var mode of validModes) {
     43  Iterator.zipKeyed({}, {mode});
     44 }
     45 
     46 // Throws a TypeError for invalid mode options.
     47 for (var mode of invalidModes) {
     48  assert.throws(TypeError, function() {
     49    Iterator.zipKeyed({}, {mode});
     50  });
     51 }
     52 
     53 // "padding" option is not retrieved when "mode" option is invalid.
     54 for (var mode of invalidModes) {
     55  var options = {
     56    mode,
     57    get padding() {
     58      throw new Test262Error();
     59    }
     60  };
     61  assert.throws(TypeError, function() {
     62    Iterator.zipKeyed({}, options);
     63  });
     64 }
     65 
     66 // String wrappers are not accepted.
     67 for (var mode of validModes) {
     68  var options = {mode: new String(mode)};
     69  assert.throws(TypeError, function() {
     70    Iterator.zipKeyed({}, options);
     71  });
     72 }
     73 
     74 // Does not call any of `toString`, `valueOf`, `Symbol.toPrimitive`.
     75 var badMode = {
     76  toString() {
     77    throw new Test262Error();
     78  },
     79  valueOf() {
     80    throw new Test262Error();
     81  },
     82  [Symbol.toPrimitive]() {
     83    throw new Test262Error();
     84  },
     85 };
     86 assert.throws(TypeError, function() {
     87  Iterator.zipKeyed({}, {mode: badMode});
     88 });
     89 
     90 reportCompare(0, 0);