Chromium Code Reviews| 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 // See Runtime_GetOptimizationStatus in runtime-test.cc | |
| 8 const kInterpreted = 8; | |
| 9 const kNo = 2; | |
| 10 | |
| 11 function Baseline() { | |
| 12 let array = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | |
| 13 | |
| 14 let it = array[Symbol.iterator](); | |
| 15 assertEquals(0, it.next().value); | |
| 16 assertEquals(1, it.next().value); | |
| 17 assertEquals(2, it.next().value); | |
| 18 %ArrayBufferNeuter(array.buffer); | |
| 19 it.next(); | |
| 20 }; | |
| 21 %NeverOptimizeFunction(Baseline); | |
| 22 | |
| 23 assertThrows(Baseline, TypeError, | |
| 24 "Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer"); | |
| 25 | |
| 26 let state = kNo; | |
| 27 function Turbo(count = 10000) { | |
| 28 let array = Array(10000); | |
| 29 for (let i = 0; i < 10000; ++i) { | |
| 30 array[i] = 254; | |
| 31 } | |
| 32 array[5000] = 255; | |
| 33 array = new Uint8Array(array); | |
| 34 | |
| 35 let sum = 0; | |
| 36 let it = array[Symbol.iterator](); | |
| 37 for (let i = 0; i < count; ++i) { | |
| 38 let result = it.next(); | |
| 39 if (result.value === 255) { | |
| 40 state = %GetOptimizationStatus(Turbo); | |
| 41 %ArrayBufferNeuter(array.buffer); | |
| 42 } | |
| 43 sum += result.value; | |
| 44 } | |
| 45 return sum; | |
| 46 } | |
| 47 | |
| 48 Turbo(10); | |
| 49 Turbo(10); | |
| 50 %OptimizeFunctionOnNextCall(Turbo); | |
| 51 | |
| 52 assertThrows(Turbo, TypeError, | |
| 53 "Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer"); | |
| 54 assertTrue(state !== kInterpreted && state !== kNo, | |
|
Benedikt Meurer
2017/01/03 18:09:39
This is very brittle. I'd rather have a high-level
caitp
2017/01/03 18:18:40
Fair enough
| |
| 55 "Turbo should be optimized using TurboFan backend, but was " + state); | |
| OLD | NEW |