acquire-properties-from-array.js (1690B)
1 // Copyright (C) 2011 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 es6id: 13.1 5 description: > 6 for-in to acquire properties from array 7 ---*/ 8 function props(x) { 9 var array = []; 10 for (let p in x) array.push(p); 11 return array; 12 } 13 var subject; 14 15 subject = props([]); 16 assert.sameValue(subject.length, 0, "[]: length"); 17 assert.sameValue(subject[0], undefined, "[]: first property"); 18 assert.sameValue(subject[1], undefined, "[]: second property"); 19 assert.sameValue(subject[2], undefined, "[]: third property"); 20 assert.sameValue(subject[3], undefined, "[]: fourth property"); 21 22 subject = props([1]); 23 assert.sameValue(subject.length, 1, "[1]: length"); 24 assert.sameValue(subject[0], "0", "[1]: first property"); 25 assert.sameValue(subject[1], undefined, "[1]: second property"); 26 assert.sameValue(subject[2], undefined, "[1]: third property"); 27 assert.sameValue(subject[3], undefined, "[1]: fourth property"); 28 29 subject = props([1, 2]); 30 assert.sameValue(subject.length, 2, "[1, 2]: length"); 31 assert.sameValue(subject[0], "0", "[1, 2]: first property"); 32 assert.sameValue(subject[1], "1", "[1, 2]: second property"); 33 assert.sameValue(subject[2], undefined, "[1, 2]: third property"); 34 assert.sameValue(subject[3], undefined, "[1, 2]: fourth property"); 35 36 subject = props([1, 2, 3]); 37 assert.sameValue(subject.length, 3, "[1, 2, 3]: length"); 38 assert.sameValue(subject[0], "0", "[1, 2, 3]: first property"); 39 assert.sameValue(subject[1], "1", "[1, 2, 3]: second property"); 40 assert.sameValue(subject[2], "2", "[1, 2, 3]: third property"); 41 assert.sameValue(subject[3], undefined, "[1, 2, 3]: fourth property"); 42 43 reportCompare(0, 0);