object.js (1236B)
1 // Copyright (C) 2014 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 es6id: 12.2.5 5 description: > 6 to name, accessor side effects object literal 7 includes: [compareArray.js] 8 ---*/ 9 var counter = 0; 10 var key1 = { 11 toString: function() { 12 assert.sameValue(counter++, 0, "The result of `counter++` is `0`"); 13 return 'b'; 14 } 15 }; 16 var key2 = { 17 toString: function() { 18 assert.sameValue(counter++, 1, "The result of `counter++` is `1`"); 19 return 'd'; 20 } 21 }; 22 var object = { 23 a() { return 'A'; }, 24 [key1]() { return 'B'; }, 25 c() { return 'C'; }, 26 [key2]() { return 'D'; }, 27 }; 28 assert.sameValue(counter, 2, "The value of `counter` is `2`"); 29 assert.sameValue(object.a(), 'A', "`object.a()` returns `'A'`. Defined as `a() { return 'A'; }`"); 30 assert.sameValue(object.b(), 'B', "`object.b()` returns `'B'`. Defined as `[key1]() { return 'B'; }`"); 31 assert.sameValue(object.c(), 'C', "`object.c()` returns `'C'`. Defined as `c() { return 'C'; }`"); 32 assert.sameValue(object.d(), 'D', "`object.d()` returns `'D'`. Defined as `[key2]() { return 'D'; }`"); 33 assert.compareArray( 34 Object.getOwnPropertyNames(object), 35 ['a', 'b', 'c', 'd'] 36 ); 37 38 reportCompare(0, 0);