tor-browser

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

options-padding.js (1459B)


      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 "padding" option must be undefined or an object.
      8 info: |
      9  Iterator.zipKeyed ( iterables [ , options ] )
     10    ...
     11    6. Let paddingOption be undefined.
     12    7. If mode is "longest", then
     13      a. Set paddingOption to ? Get(options, "padding").
     14      b. If paddingOption is not undefined and paddingOption is not an Object, throw a TypeError exception.
     15    ...
     16 features: [joint-iteration]
     17 ---*/
     18 
     19 var validPadding = [
     20  undefined,
     21  {},
     22 ];
     23 
     24 var invalidPadding = [
     25  null,
     26  false,
     27  "",
     28  Symbol(),
     29  123,
     30  123n,
     31 ];
     32 
     33 // Absent "padding" option.
     34 Iterator.zipKeyed({}, {mode: "longest"});
     35 
     36 // All valid padding values are accepted.
     37 for (var padding of validPadding) {
     38  Iterator.zipKeyed({}, {mode: "longest", padding});
     39 }
     40 
     41 // Throws a TypeError for invalid padding options.
     42 for (var padding of invalidPadding) {
     43  assert.throws(TypeError, function() {
     44    Iterator.zipKeyed({}, {mode: "longest", padding});
     45  });
     46 }
     47 
     48 // Invalid padding options are okay when mode is not "longest" because the padding option is not read.
     49 for (var padding of invalidPadding) {
     50  Iterator.zipKeyed({}, {padding});
     51  Iterator.zipKeyed({}, {mode: undefined, padding});
     52  Iterator.zipKeyed({}, {mode: "shortest", padding});
     53  Iterator.zipKeyed({}, {mode: "strict", padding});
     54 }
     55 
     56 reportCompare(0, 0);