species-redefine-getter.js (722B)
1 // Ensure the HadGetterSetterChange flag is set. 2 Object.defineProperty(Array, "foo", {configurable: true, get: function() {}}); 3 Object.defineProperty(Array, "foo", {configurable: true, get: function() {}}); 4 5 // Initialize ArraySpeciesLookup. 6 let a = [1, 2, 3]; 7 for (let i = 0; i < 5; i++) { 8 assertEq(a.slice().length, 3); 9 } 10 11 // Redefine the Array[Symbol.species] getter without changing its attributes/shape. 12 let count = 0; 13 Object.defineProperty(Array, Symbol.species, 14 {get: function() { count++; }, enumerable: false, configurable: true}); 15 16 // Ensure ArraySpeciesLookup now deoptimizes and calls the getter. 17 for (let i = 0; i < 5; i++) { 18 assertEq(a.slice().length, 3); 19 } 20 assertEq(count, 5);