order-after-define-property.js (1405B)
1 // Copyright (C) 2020 Alexey Shvayka. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-enumerate-object-properties 6 description: > 7 Property names are returned in ascending chronological order of creation 8 that is unaffected by [[DefineOwnProperty]]. 9 info: | 10 EnumerateObjectProperties ( O ) 11 12 EnumerateObjectProperties must obtain the own property keys of the target object 13 by calling its [[OwnPropertyKeys]] internal method. Property attributes of the 14 target object must be obtained by calling its [[GetOwnProperty]] internal method. 15 16 OrdinaryOwnPropertyKeys ( O ) 17 18 [...] 19 3. For each own property key P of O that is a String but is not an array index, 20 in ascending chronological order of property creation, do 21 a. Add P as the last element of keys. 22 [...] 23 5. Return keys. 24 includes: [compareArray.js] 25 ---*/ 26 27 var obj = {}; 28 obj.a = 1; 29 obj.b = 2; 30 Object.defineProperty(obj, "a", {value: 11}); 31 var objKeys = []; 32 for (var objKey in obj) { 33 objKeys.push(objKey); 34 } 35 assert.compareArray(objKeys, ["a", "b"]); 36 37 var arr = []; 38 Object.defineProperty(arr, "a", { 39 get: function() {}, 40 enumerable: true, 41 configurable: true, 42 }) 43 arr.b = 2; 44 Object.defineProperty(arr, "a", { 45 get: function() {}, 46 }); 47 var arrKeys = []; 48 for (var arrKey in arr) { 49 arrKeys.push(arrKey); 50 } 51 assert.compareArray(arrKeys, ["a", "b"]); 52 53 reportCompare(0, 0);