2019-06-21 13:02:01 +00:00
|
|
|
// Copyright 2019 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.
|
|
|
|
|
2020-06-09 15:54:14 +00:00
|
|
|
// Flags: --experimental-wasm-bulk-memory --experimental-wasm-reftypes
|
2019-06-21 13:02:01 +00:00
|
|
|
|
|
|
|
load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
|
|
|
let kTableSize = 5;
|
|
|
|
|
|
|
|
let table = new WebAssembly.Table(
|
2020-06-09 15:54:14 +00:00
|
|
|
{element: 'externref', initial: kTableSize, maximum: kTableSize});
|
2019-06-21 13:02:01 +00:00
|
|
|
|
|
|
|
let builder = new WasmModuleBuilder();
|
2020-06-09 15:54:14 +00:00
|
|
|
builder.addImportedTable('m', 'table', kTableSize, kTableSize, kWasmExternRef);
|
2019-06-21 13:02:01 +00:00
|
|
|
builder.addTable(kWasmAnyFunc, 1000);
|
|
|
|
|
|
|
|
builder.addFunction('copy', kSig_v_iii)
|
|
|
|
.addBody([
|
2019-10-08 12:38:48 +00:00
|
|
|
kExprLocalGet, 0, kExprLocalGet, 1, kExprLocalGet, 2, kNumericPrefix,
|
2019-06-21 13:02:01 +00:00
|
|
|
kExprTableCopy, kTableZero, kTableZero
|
|
|
|
])
|
|
|
|
.exportFunc();
|
|
|
|
|
|
|
|
const instance = builder.instantiate({m: {table: table}});
|
|
|
|
|
|
|
|
function resetTable() {
|
|
|
|
table.set(0, 1000);
|
|
|
|
table.set(1, 1001);
|
|
|
|
table.set(2, 1002);
|
|
|
|
table.set(3, 1003);
|
|
|
|
table.set(4, 1004);
|
|
|
|
}
|
|
|
|
|
|
|
|
function assertTable(values) {
|
|
|
|
for (let i = 0; i < kTableSize; ++i) {
|
|
|
|
assertEquals(table.get(i), values[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetTable();
|
|
|
|
instance.exports.copy(0, 1, 1);
|
|
|
|
assertTable([1001, 1001, 1002, 1003, 1004]);
|
|
|
|
|
|
|
|
resetTable();
|
|
|
|
instance.exports.copy(0, 1, 2);
|
|
|
|
assertTable([1001, 1002, 1002, 1003, 1004]);
|
|
|
|
|
|
|
|
resetTable();
|
|
|
|
instance.exports.copy(3, 0, 2);
|
|
|
|
assertTable([1000, 1001, 1002, 1000, 1001]);
|
|
|
|
|
2019-07-18 07:33:28 +00:00
|
|
|
// Non-overlapping, src < dst. Because of src < dst, we copy backwards.
|
|
|
|
// Therefore the first access already traps, and the table is not changed.
|
2019-06-21 13:02:01 +00:00
|
|
|
resetTable();
|
|
|
|
assertTraps(kTrapTableOutOfBounds, () => instance.exports.copy(3, 0, 3));
|
2019-07-18 07:33:28 +00:00
|
|
|
assertTable([1000, 1001, 1002, 1003, 1004]);
|
2019-06-21 13:02:01 +00:00
|
|
|
|
|
|
|
// Non-overlapping, dst < src.
|
|
|
|
resetTable();
|
|
|
|
assertTraps(kTrapTableOutOfBounds, () => instance.exports.copy(0, 4, 2));
|
2019-11-20 14:22:39 +00:00
|
|
|
assertTable([1000, 1001, 1002, 1003, 1004]);
|
2019-06-21 13:02:01 +00:00
|
|
|
|
|
|
|
// Overlapping, src < dst. This is required to copy backward, but the first
|
|
|
|
// access will be out-of-bounds, so nothing changes.
|
|
|
|
resetTable();
|
|
|
|
assertTraps(kTrapTableOutOfBounds, () => instance.exports.copy(3, 0, 99));
|
|
|
|
assertTable([1000, 1001, 1002, 1003, 1004]);
|
|
|
|
|
|
|
|
// Overlapping, dst < src.
|
|
|
|
resetTable();
|
|
|
|
assertTraps(kTrapTableOutOfBounds, () => instance.exports.copy(0, 1, 99));
|
2019-11-20 14:22:39 +00:00
|
|
|
assertTable([1000, 1001, 1002, 1003, 1004]);
|