OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --allow-natives-syntax |
| 6 |
| 7 function Baseline() { |
| 8 let array = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); |
| 9 |
| 10 let it = array[Symbol.iterator](); |
| 11 assertEquals(0, it.next().value); |
| 12 assertEquals(1, it.next().value); |
| 13 assertEquals(2, it.next().value); |
| 14 %ArrayBufferNeuter(array.buffer); |
| 15 it.next(); |
| 16 }; |
| 17 %NeverOptimizeFunction(Baseline); |
| 18 |
| 19 assertThrows(Baseline, TypeError, |
| 20 "Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer"); |
| 21 |
| 22 function Turbo(count = 10000) { |
| 23 let array = Array(10000); |
| 24 for (let i = 0; i < 10000; ++i) { |
| 25 array[i] = 254; |
| 26 } |
| 27 array[5000] = 255; |
| 28 array = new Uint8Array(array); |
| 29 |
| 30 let sum = 0; |
| 31 let it = array[Symbol.iterator](); |
| 32 for (let i = 0; i < count; ++i) { |
| 33 let result = it.next(); |
| 34 if (result.value === 255) { |
| 35 %ArrayBufferNeuter(array.buffer); |
| 36 } |
| 37 sum += result.value; |
| 38 } |
| 39 return sum; |
| 40 } |
| 41 |
| 42 Turbo(10); |
| 43 Turbo(10); |
| 44 %OptimizeFunctionOnNextCall(Turbo); |
| 45 |
| 46 assertThrows(Turbo, TypeError, |
| 47 "Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer"); |
OLD | NEW |