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 function Turbo() { | |
| 27 let array = Array(5000); | |
| 28 for (let i = 0; i < 5000; ++i) { | |
| 29 array[i] = 254; | |
| 30 } | |
| 31 array[3000] = 255; | |
| 32 array = new Uint8Array(array); | |
| 33 | |
| 34 let sum = 0; | |
| 35 let it = array[Symbol.iterator](); | |
| 36 for (let i = 0; i < 5000; ++i) { | |
| 37 let result = it.next(); | |
| 38 if (result.value === 255) { | |
| 39 let state = %GetOptimizationStatus(Turbo); | |
| 40 assertTrue(state === kInterpreted || state === kNo, | |
| 41 "Turbo should be optimized using TurboFan backend."); | |
|
caitp
2017/01/03 16:26:36
these sorts of assertions are hard to get right :(
| |
| 42 %ArrayBufferNeuter(array.buffer); | |
| 43 } | |
| 44 sum += result.value; | |
| 45 } | |
| 46 return sum; | |
| 47 } | |
| 48 | |
| 49 assertThrows(Turbo, TypeError, | |
| 50 "Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer"); | |
| OLD | NEW |