tor-browser

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

options-padding.js (1434B)


      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.zip
      6 description: >
      7  The "padding" option must be undefined or an object.
      8 info: |
      9  Iterator.zip ( 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  Object("string"),
     23 ];
     24 
     25 var invalidPadding = [
     26  null,
     27  false,
     28  "",
     29  Symbol(),
     30  123,
     31  123n,
     32 ];
     33 
     34 // Absent "padding" option.
     35 Iterator.zip([], {mode: "longest"});
     36 
     37 // All valid padding values are accepted.
     38 for (var padding of validPadding) {
     39  Iterator.zip([], {mode: "longest", padding});
     40 }
     41 
     42 // Throws a TypeError for invalid padding options.
     43 for (var padding of invalidPadding) {
     44  assert.throws(TypeError, function() {
     45    Iterator.zip([], {mode: "longest", padding});
     46  });
     47 }
     48 
     49 // Invalid padding options are okay when mode is not "longest" because the padding option is not read.
     50 for (var padding of invalidPadding) {
     51  Iterator.zip([], {padding});
     52  Iterator.zip([], {mode: undefined, padding});
     53  Iterator.zip([], {mode: "shortest", padding});
     54  Iterator.zip([], {mode: "strict", padding});
     55 }
     56 
     57 reportCompare(0, 0);