computed-property-evaluation-order.js (847B)
1 // Copyright (C) 2016 Michael Ficarra. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-object-initializer-runtime-semantics-propertydefinitionevaluation 5 description: > 6 Evaluation of PropertyDefinitionList occurs in order, and each 7 PropertyDefinition's PropertyName is evaluated before its 8 AssignmentExpression. 9 ---*/ 10 11 var counter = 0; 12 var o = { 13 [++counter]: ++counter, 14 [++counter]: ++counter, 15 [++counter]: ++counter, 16 } 17 18 var keys = Object.getOwnPropertyNames(o); 19 20 assert.sameValue(keys.length, 3, '3 PropertyDefinitions should result in 3 properties'); 21 assert.sameValue(keys[0], '1'); 22 assert.sameValue(o[keys[0]], 2); 23 assert.sameValue(keys[1], '3'); 24 assert.sameValue(o[keys[1]], 4); 25 assert.sameValue(keys[2], '5'); 26 assert.sameValue(o[keys[2]], 6); 27 28 reportCompare(0, 0);