padding-iteration.js (1523B)
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 Perform keys iteration on the "padding" option. 8 info: | 9 Iterator.zipKeyed ( iterables [ , options ] ) 10 ... 11 14. If mode is "longest", then 12 ... 13 b. Else, 14 i. For each element key of keys, do 15 1. Let value be Completion(Get(paddingOption, key)). 16 ... 17 includes: [proxyTrapsHelper.js, compareArray.js] 18 features: [joint-iteration] 19 ---*/ 20 21 function makeKeys(k) { 22 var str = "abcdefgh"; 23 assert(k <= str.length, "more than eight keys are unsupported"); 24 return str.slice(0, k).split(""); 25 } 26 27 function fromKeys(keys, value) { 28 return Object.fromEntries(keys.map(function(k) { 29 return [k, value]; 30 })); 31 } 32 33 for (var n = 0; n <= 5; ++n) { 34 // Create an object with |n| properties. 35 var keys = makeKeys(n); 36 var iterables = fromKeys(keys, []); 37 38 for (var k = 0; k <= n + 2; ++k) { 39 var log = []; 40 41 // Create a padding object with |k| properties. Ensure only [[Get]] is 42 // called. 43 var padding = new Proxy(fromKeys(makeKeys(k), undefined), allowProxyTraps({ 44 get(target, propertyKey, receiver) { 45 log.push(propertyKey); 46 return Reflect.get(target, propertyKey, receiver); 47 }, 48 })); 49 50 Iterator.zipKeyed(iterables, {mode: "longest", padding}); 51 52 // [[Get]] happened for all keys from |keys|. 53 assert.compareArray(log, keys); 54 } 55 } 56 57 reportCompare(0, 0);