v8/test/mjsunit/compiler/dataview-detached.js
Camillo Bruni e3e8ea5d65 [flags] Rename --opt to --turbofan
To be consistent with the all the other tiers and avoid confusion, we
rename --opt to ---turbofan, and --always-opt to --always-turbofan.

Change-Id: Ie23dc8282b3fb4cf2fbf73b6c3d5264de5d09718
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610431
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80336}
2022-05-03 12:10:30 +00:00

409 lines
11 KiB
JavaScript

// Copyright 2018 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 --turbofan --noalways-turbofan --no-stress-flush-code
// Invalidate the detaching protector.
%ArrayBufferDetach(new ArrayBuffer(1));
// Check DataView.prototype.getInt8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt8(0);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint8(0);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getInt16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt16(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint16(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getInt32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getInt32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getUint32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getUint32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getFloat32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv) {
return dv.getFloat32(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.getFloat64() optimization.
(function() {
const ab = new ArrayBuffer(8);
const dv = new DataView(ab);
function foo(dv) {
return dv.getFloat64(0, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(0, foo(dv));
assertEquals(0, foo(dv));
%OptimizeFunctionOnNextCall(foo);
assertEquals(0, foo(dv));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt8(0, x);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt8(0));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt8(0));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint8() optimization.
(function() {
const ab = new ArrayBuffer(1);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint8(0, x);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint8(0));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint8(0));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt16(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt16(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt16(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint16() optimization.
(function() {
const ab = new ArrayBuffer(2);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint16(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint16(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint16(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setInt32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setInt32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getInt32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getInt32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setUint32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setUint32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getUint32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getUint32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setFloat32() optimization.
(function() {
const ab = new ArrayBuffer(4);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setFloat32(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getFloat32(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getFloat32(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();
// Check DataView.prototype.setFloat64() optimization.
(function() {
const ab = new ArrayBuffer(8);
const dv = new DataView(ab);
function foo(dv, x) {
return dv.setFloat64(0, x, true);
}
%PrepareFunctionForOptimization(foo);
assertEquals(undefined, foo(dv, 1));
assertEquals(1, dv.getFloat64(0, true));
assertEquals(undefined, foo(dv, 2));
assertEquals(2, dv.getFloat64(0, true));
%OptimizeFunctionOnNextCall(foo);
assertEquals(undefined, foo(dv, 3));
assertOptimized(foo);
%ArrayBufferDetach(ab);
assertThrows(() => foo(dv, 4), TypeError);
assertUnoptimized(foo);
%PrepareFunctionForOptimization(foo);
%OptimizeFunctionOnNextCall(foo);
assertThrows(() => foo(dv, 5), TypeError);
assertOptimized(foo);
})();