2017-01-03 20:12:19 +00:00
|
|
|
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
// Flags: --allow-natives-syntax
|
|
|
|
|
|
|
|
function Baseline() {
|
|
|
|
let array = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
|
|
|
|
|
|
|
let it = array[Symbol.iterator]();
|
|
|
|
assertEquals(0, it.next().value);
|
|
|
|
assertEquals(1, it.next().value);
|
|
|
|
assertEquals(2, it.next().value);
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(array.buffer);
|
2017-01-03 20:12:19 +00:00
|
|
|
it.next();
|
|
|
|
};
|
|
|
|
%NeverOptimizeFunction(Baseline);
|
|
|
|
|
|
|
|
assertThrows(Baseline, TypeError,
|
2019-09-11 15:45:30 +00:00
|
|
|
"Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer");
|
2017-01-03 20:12:19 +00:00
|
|
|
|
|
|
|
function Turbo(count = 10000) {
|
|
|
|
let array = Array(10000);
|
|
|
|
for (let i = 0; i < 10000; ++i) {
|
|
|
|
array[i] = 254;
|
|
|
|
}
|
|
|
|
array[5000] = 255;
|
|
|
|
array = new Uint8Array(array);
|
|
|
|
|
|
|
|
let sum = 0;
|
|
|
|
let it = array[Symbol.iterator]();
|
|
|
|
for (let i = 0; i < count; ++i) {
|
|
|
|
let result = it.next();
|
|
|
|
if (result.value === 255) {
|
2018-12-11 10:22:02 +00:00
|
|
|
%ArrayBufferDetach(array.buffer);
|
2017-01-03 20:12:19 +00:00
|
|
|
}
|
|
|
|
sum += result.value;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2019-05-01 16:49:49 +00:00
|
|
|
%PrepareFunctionForOptimization(Turbo);
|
2017-01-03 20:12:19 +00:00
|
|
|
Turbo(10);
|
|
|
|
Turbo(10);
|
|
|
|
%OptimizeFunctionOnNextCall(Turbo);
|
|
|
|
|
|
|
|
assertThrows(Turbo, TypeError,
|
2019-09-11 15:45:30 +00:00
|
|
|
"Cannot perform Array Iterator.prototype.next on a detached ArrayBuffer");
|