2018-06-29 12:59:50 +00:00
|
|
|
// 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 --opt --no-always-opt
|
|
|
|
|
|
|
|
var buffer = new ArrayBuffer(64);
|
|
|
|
var dataview = new DataView(buffer, 8, 24);
|
|
|
|
|
|
|
|
var values = [-1, 2, -3, 42];
|
|
|
|
|
2018-07-05 15:48:54 +00:00
|
|
|
function readUint8(offset) {
|
|
|
|
return dataview.getUint8(offset);
|
|
|
|
}
|
|
|
|
|
2018-06-29 12:59:50 +00:00
|
|
|
function readInt8Handled(offset) {
|
|
|
|
try {
|
|
|
|
return dataview.getInt8(offset);
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 15:48:54 +00:00
|
|
|
function readUint16(offset, little_endian) {
|
|
|
|
return dataview.getUint16(offset, little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function readInt16Handled(offset, little_endian) {
|
|
|
|
try {
|
|
|
|
return dataview.getInt16(offset, little_endian);
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
2018-06-29 12:59:50 +00:00
|
|
|
}
|
|
|
|
|
2018-07-06 09:02:07 +00:00
|
|
|
function readUint32(offset, little_endian) {
|
|
|
|
return dataview.getUint32(offset, little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function readInt32Handled(offset, little_endian) {
|
|
|
|
try {
|
|
|
|
return dataview.getInt32(offset, little_endian);
|
|
|
|
} catch (e) {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function readFloat32(offset, little_endian) {
|
|
|
|
return dataview.getFloat32(offset, little_endian);
|
|
|
|
}
|
|
|
|
|
|
|
|
function readFloat64(offset, little_endian) {
|
|
|
|
return dataview.getFloat64(offset, little_endian);
|
|
|
|
}
|
|
|
|
|
2018-06-29 12:59:50 +00:00
|
|
|
function warmup(f) {
|
|
|
|
f(0);
|
|
|
|
f(1);
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
f(2);
|
|
|
|
f(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TurboFan valid getInt8.
|
|
|
|
for (var i = 0; i < values.length; i++) {
|
|
|
|
dataview.setInt8(i, values[i]);
|
|
|
|
}
|
|
|
|
warmup(readInt8Handled);
|
|
|
|
assertOptimized(readInt8Handled);
|
|
|
|
assertEquals(values[0], readInt8Handled(0));
|
|
|
|
assertEquals(values[1], readInt8Handled(1));
|
|
|
|
assertEquals(values[2], readInt8Handled(2));
|
|
|
|
assertEquals(values[3], readInt8Handled(3));
|
|
|
|
|
|
|
|
// TurboFan valid getUint8.
|
|
|
|
dataview.setUint32(4, 0xdeadbeef);
|
|
|
|
warmup(readUint8);
|
|
|
|
assertOptimized(readUint8);
|
|
|
|
assertEquals(0xde, readUint8(4));
|
|
|
|
assertEquals(0xad, readUint8(5));
|
|
|
|
assertEquals(0xbe, readUint8(6));
|
|
|
|
assertEquals(0xef, readUint8(7));
|
|
|
|
|
2018-07-05 15:48:54 +00:00
|
|
|
// TurboFan valid getUint16.
|
|
|
|
dataview.setUint16(8, 0xabcd);
|
|
|
|
warmup(readUint16);
|
|
|
|
assertOptimized(readUint16);
|
|
|
|
assertEquals(0xabcd, readUint16(8));
|
|
|
|
assertEquals(0xcdab, readUint16(8, true));
|
|
|
|
|
|
|
|
// TurboFan valid getInt16.
|
2018-07-06 09:02:07 +00:00
|
|
|
let b1 = -0x1234;
|
|
|
|
dataview.setInt16(10, b1);
|
2018-07-05 15:48:54 +00:00
|
|
|
warmup(readInt16Handled);
|
2018-07-06 09:02:07 +00:00
|
|
|
assertOptimized(readInt16Handled);
|
|
|
|
assertEquals(b1, readInt16Handled(10));
|
|
|
|
dataview.setInt16(10, b1, true);
|
|
|
|
assertEquals(b1, readInt16Handled(10, true));
|
|
|
|
|
|
|
|
// TurboFan valid getUint32.
|
|
|
|
dataview.setUint32(12, 0xabcdef12);
|
|
|
|
warmup(readUint32);
|
|
|
|
assertOptimized(readUint32);
|
|
|
|
assertEquals(0xabcdef12, readUint32(12));
|
|
|
|
assertEquals(0x12efcdab, readUint32(12, true));
|
|
|
|
|
|
|
|
// TurboFan valid getInt32.
|
|
|
|
let b2 = -0x12345678;
|
|
|
|
dataview.setInt32(16, b2);
|
|
|
|
warmup(readInt32Handled);
|
|
|
|
assertOptimized(readInt32Handled);
|
|
|
|
assertEquals(b2, readInt32Handled(16));
|
|
|
|
dataview.setInt32(16, b2, true);
|
|
|
|
assertEquals(b2, readInt32Handled(16, true));
|
|
|
|
|
|
|
|
// TurboFan valid getFloat32.
|
|
|
|
let b3 = Math.fround(Math.E); // Round Math.E to float32.
|
|
|
|
dataview.setFloat32(16, b3);
|
|
|
|
warmup(readFloat32);
|
|
|
|
assertOptimized(readFloat32);
|
|
|
|
assertEquals(b3, readFloat32(16));
|
|
|
|
dataview.setFloat32(16, b3, true);
|
|
|
|
assertEquals(b3, readFloat32(16, true));
|
|
|
|
|
|
|
|
// TurboFan valid getFloat64.
|
|
|
|
let b4 = Math.PI;
|
|
|
|
dataview.setFloat64(16, b4);
|
|
|
|
warmup(readFloat64);
|
|
|
|
assertOptimized(readFloat64);
|
|
|
|
assertEquals(b4, readFloat64(16));
|
|
|
|
dataview.setFloat64(16, b4, true);
|
|
|
|
assertEquals(b4, readFloat64(16, true));
|
|
|
|
|
2018-07-24 12:39:16 +00:00
|
|
|
// TurboFan out of bounds reads deopt.
|
2018-06-29 12:59:50 +00:00
|
|
|
assertOptimized(readInt8Handled);
|
2018-07-05 15:48:54 +00:00
|
|
|
assertInstanceof(readInt8Handled(24), RangeError);
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readInt8Handled);
|
2018-07-05 15:48:54 +00:00
|
|
|
assertOptimized(readInt16Handled);
|
|
|
|
assertInstanceof(readInt16Handled(23), RangeError);
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readInt16Handled);
|
2018-07-06 09:02:07 +00:00
|
|
|
assertOptimized(readInt32Handled);
|
|
|
|
assertInstanceof(readInt32Handled(21), RangeError);
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readInt32Handled);
|
2018-07-05 15:48:54 +00:00
|
|
|
|
2018-06-29 12:59:50 +00:00
|
|
|
// Without exception handler.
|
|
|
|
assertOptimized(readUint8);
|
2018-07-06 09:02:07 +00:00
|
|
|
assertThrows(() => readUint8(24));
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readUint8);
|
2018-07-06 09:02:07 +00:00
|
|
|
assertOptimized(readFloat32);
|
|
|
|
assertThrows(() => readFloat32(21));
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readFloat32);
|
2018-07-06 09:02:07 +00:00
|
|
|
assertOptimized(readFloat64);
|
|
|
|
assertThrows(() => readFloat64(17));
|
2018-07-24 12:39:16 +00:00
|
|
|
assertUnoptimized(readFloat64);
|
2018-06-29 12:59:50 +00:00
|
|
|
|
2018-07-24 12:39:16 +00:00
|
|
|
// Negative Smi deopts.
|
|
|
|
(function() {
|
|
|
|
function readInt8Handled(offset) {
|
|
|
|
try { return dataview.getInt8(offset); } catch (e) { return e; }
|
|
|
|
}
|
|
|
|
warmup(readInt8Handled);
|
|
|
|
assertOptimized(readInt8Handled);
|
|
|
|
assertInstanceof(readInt8Handled(-1), RangeError);
|
|
|
|
assertUnoptimized(readInt8Handled);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Non-Smi index deopts.
|
|
|
|
(function() {
|
|
|
|
function readUint8(offset) { return dataview.getUint8(offset); }
|
|
|
|
warmup(readUint8);
|
|
|
|
assertOptimized(readUint8);
|
|
|
|
assertEquals(values[3], readUint8(3.14));
|
|
|
|
assertUnoptimized(readUint8);
|
|
|
|
})();
|
|
|
|
|
|
|
|
// TurboFan neutered buffer deopts.
|
|
|
|
(function() {
|
|
|
|
function readInt8Handled(offset) {
|
|
|
|
try { return dataview.getInt8(offset); } catch (e) { return e; }
|
|
|
|
}
|
|
|
|
warmup(readInt8Handled);
|
|
|
|
assertOptimized(readInt8Handled);
|
2018-08-13 17:13:02 +00:00
|
|
|
%ArrayBufferNeuter(buffer);
|
2018-07-24 12:39:16 +00:00
|
|
|
assertInstanceof(readInt8Handled(0), TypeError);
|
|
|
|
assertUnoptimized(readInt8Handled);
|
|
|
|
})();
|