2016-06-28 16:46:34 +00:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
2016-10-20 07:38:55 +00:00
|
|
|
// Flags: --expose-wasm --stress-compaction
|
2016-06-28 16:46:34 +00:00
|
|
|
|
|
|
|
load("test/mjsunit/wasm/wasm-constants.js");
|
|
|
|
load("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
|
|
|
|
var kPageSize = 0x10000;
|
2016-11-08 09:55:05 +00:00
|
|
|
var kV8MaxPages = 16384;
|
2016-06-28 16:46:34 +00:00
|
|
|
|
|
|
|
function genGrowMemoryBuilder() {
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction("grow_memory", kSig_i_i)
|
2016-10-26 16:56:05 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGrowMemory, kMemoryZero])
|
2016-06-28 16:46:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction("load", kSig_i_i)
|
|
|
|
.addBody([kExprGetLocal, 0, kExprI32LoadMem, 0, 0])
|
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction("store", kSig_i_ii)
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem, 0, 0,
|
|
|
|
kExprGetLocal, 1])
|
2016-06-28 16:46:34 +00:00
|
|
|
.exportFunc();
|
2016-09-12 07:32:42 +00:00
|
|
|
builder.addFunction("load16", kSig_i_i)
|
|
|
|
.addBody([kExprGetLocal, 0, kExprI32LoadMem16U, 0, 0])
|
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction("store16", kSig_i_ii)
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem16, 0, 0,
|
|
|
|
kExprGetLocal, 1])
|
2016-09-12 07:32:42 +00:00
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction("load8", kSig_i_i)
|
|
|
|
.addBody([kExprGetLocal, 0, kExprI32LoadMem8U, 0, 0])
|
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction("store8", kSig_i_ii)
|
2016-09-27 20:46:10 +00:00
|
|
|
.addBody([kExprGetLocal, 0, kExprGetLocal, 1, kExprI32StoreMem8, 0, 0,
|
|
|
|
kExprGetLocal, 1])
|
2016-09-12 07:32:42 +00:00
|
|
|
.exportFunc();
|
2016-06-28 16:46:34 +00:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
2016-10-14 23:54:38 +00:00
|
|
|
// TODO(gdeepti): Generate tests programatically for all the sizes instead of
|
|
|
|
// current implementation.
|
2016-09-12 07:32:42 +00:00
|
|
|
function testGrowMemoryReadWrite32() {
|
2016-06-28 16:46:34 +00:00
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-06-28 16:46:34 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load(offset); }
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
2016-09-12 07:32:42 +00:00
|
|
|
for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
|
2016-06-28 16:46:34 +00:00
|
|
|
poke(20);
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(20, peek());
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
for (offset = kPageSize - 3; offset < kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(1, growMem(3));
|
2016-06-28 16:46:34 +00:00
|
|
|
|
2016-09-12 07:32:42 +00:00
|
|
|
for (offset = kPageSize; offset <= 4*kPageSize -4; offset+=4) {
|
2016-06-28 16:46:34 +00:00
|
|
|
poke(20);
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(20, peek());
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
for (offset = 4*kPageSize - 3; offset < 4*kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(4, growMem(15));
|
2016-06-28 16:46:34 +00:00
|
|
|
|
2016-09-12 07:32:42 +00:00
|
|
|
for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset+=4) {
|
2016-06-28 16:46:34 +00:00
|
|
|
poke(20);
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(20, peek());
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
2016-09-12 07:32:42 +00:00
|
|
|
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 4; offset+=4) {
|
2016-06-28 16:46:34 +00:00
|
|
|
poke(20);
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(20, peek());
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
for (offset = 19*kPageSize - 3; offset < 19*kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 07:32:42 +00:00
|
|
|
testGrowMemoryReadWrite32();
|
|
|
|
|
|
|
|
function testGrowMemoryReadWrite16() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-12 07:32:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load16(offset); }
|
|
|
|
function poke(value) { return module.exports.store16(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 2); offset+=2) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = kPageSize - 1; offset < kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, growMem(3));
|
|
|
|
|
|
|
|
for (offset = kPageSize; offset <= 4*kPageSize -2; offset+=2) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 4*kPageSize - 1; offset < 4*kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(4, growMem(15));
|
|
|
|
|
|
|
|
for (offset = 4*kPageSize - 2; offset <= 4*kPageSize + 4; offset+=2) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 2; offset+=2) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 19*kPageSize - 1; offset < 19*kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryReadWrite16();
|
|
|
|
|
|
|
|
function testGrowMemoryReadWrite8() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-12 07:32:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load8(offset); }
|
|
|
|
function poke(value) { return module.exports.store8(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
for(offset = 0; offset <= kPageSize - 1; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = kPageSize; offset < kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, growMem(3));
|
|
|
|
|
|
|
|
for (offset = kPageSize; offset <= 4*kPageSize -1; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 4*kPageSize; offset < 4*kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(4, growMem(15));
|
|
|
|
|
|
|
|
for (offset = 4*kPageSize; offset <= 4*kPageSize + 4; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 19*kPageSize - 10; offset <= 19*kPageSize - 1; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
for (offset = 19*kPageSize; offset < 19*kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryReadWrite8();
|
2016-06-28 16:46:34 +00:00
|
|
|
|
|
|
|
function testGrowMemoryZeroInitialSize() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load(offset); }
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(0, growMem(1));
|
2016-06-28 16:46:34 +00:00
|
|
|
|
|
|
|
for(offset = 0; offset <= kPageSize - 4; offset++) {
|
|
|
|
poke(20);
|
2016-08-04 20:37:39 +00:00
|
|
|
assertEquals(20, peek());
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 23:54:38 +00:00
|
|
|
for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {
|
2016-10-14 21:01:23 +00:00
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
2016-10-14 23:54:38 +00:00
|
|
|
|
|
|
|
offset = 3*kPageSize;
|
|
|
|
for (var i = 1; i < 4; i++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
assertEquals(i, growMem(1));
|
|
|
|
}
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
2016-10-14 21:01:23 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 22:42:47 +00:00
|
|
|
testGrowMemoryZeroInitialSize();
|
2016-10-14 21:01:23 +00:00
|
|
|
|
2016-10-14 23:54:38 +00:00
|
|
|
function testGrowMemoryZeroInitialSize32() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load(offset); }
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(0, growMem(1));
|
|
|
|
|
|
|
|
for(offset = 0; offset <= kPageSize - 4; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(offset = kPageSize - 3; offset <= kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryZeroInitialSize32();
|
|
|
|
|
|
|
|
function testGrowMemoryZeroInitialSize16() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load16(offset); }
|
|
|
|
function poke(value) { return module.exports.store16(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(0, growMem(1));
|
|
|
|
|
|
|
|
for(offset = 0; offset <= kPageSize - 2; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(offset = kPageSize - 1; offset <= kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryZeroInitialSize16();
|
|
|
|
|
|
|
|
function testGrowMemoryZeroInitialSize8() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset;
|
|
|
|
function peek() { return module.exports.load8(offset); }
|
|
|
|
function poke(value) { return module.exports.store8(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(0, growMem(1));
|
|
|
|
|
|
|
|
for(offset = 0; offset <= kPageSize - 1; offset++) {
|
|
|
|
poke(20);
|
|
|
|
assertEquals(20, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
for(offset = kPageSize; offset <= kPageSize + 5; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, peek);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryZeroInitialSize8();
|
|
|
|
|
2016-06-28 16:46:34 +00:00
|
|
|
function testGrowMemoryTrapMaxPagesZeroInitialMemory() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var maxPages = 16385;
|
2016-08-04 20:37:39 +00:00
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
assertEquals(-1, growMem(maxPages));
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryTrapMaxPagesZeroInitialMemory();
|
|
|
|
|
|
|
|
function testGrowMemoryTrapMaxPages() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
builder.addMemory(1, 1, false);
|
|
|
|
var module = builder.instantiate();
|
|
|
|
var maxPages = 16384;
|
2016-08-04 20:37:39 +00:00
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
assertEquals(-1, growMem(maxPages));
|
2016-06-28 16:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryTrapMaxPages();
|
2016-08-30 16:59:57 +00:00
|
|
|
|
|
|
|
function testGrowMemoryTrapsWithNonSmiInput() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
// The parameter of grow_memory is unsigned. Therefore -1 stands for
|
|
|
|
// UINT32_MIN, which cannot be represented as SMI.
|
|
|
|
assertEquals(-1, growMem(-1));
|
|
|
|
};
|
|
|
|
|
|
|
|
testGrowMemoryTrapsWithNonSmiInput();
|
2016-09-02 01:38:10 +00:00
|
|
|
|
|
|
|
function testGrowMemoryCurrentMemory() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-02 01:38:10 +00:00
|
|
|
builder.addFunction("memory_size", kSig_i_v)
|
2016-10-26 16:56:05 +00:00
|
|
|
.addBody([kExprMemorySize, kMemoryZero])
|
2016-09-02 01:38:10 +00:00
|
|
|
.exportFunc();
|
|
|
|
var module = builder.instantiate();
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
function MemSize() { return module.exports.memory_size(); }
|
2016-09-27 20:46:10 +00:00
|
|
|
assertEquals(1, MemSize());
|
2016-09-02 01:38:10 +00:00
|
|
|
assertEquals(1, growMem(1));
|
2016-09-27 20:46:10 +00:00
|
|
|
assertEquals(2, MemSize());
|
2016-09-02 01:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryCurrentMemory();
|
2016-09-12 07:32:42 +00:00
|
|
|
|
|
|
|
function testGrowMemoryPreservesDataMemOp32() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-12 07:32:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset, val;
|
|
|
|
function peek() { return module.exports.load(offset); }
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
|
|
|
|
poke(100000 - offset);
|
|
|
|
assertEquals(100000 - offset, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, growMem(3));
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 4); offset+=4) {
|
|
|
|
assertEquals(100000 - offset, peek());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryPreservesDataMemOp32();
|
|
|
|
|
|
|
|
function testGrowMemoryPreservesDataMemOp16() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-12 07:32:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset, val;
|
|
|
|
function peek() { return module.exports.load16(offset); }
|
|
|
|
function poke(value) { return module.exports.store16(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 2); offset+=2) {
|
|
|
|
poke(65535 - offset);
|
|
|
|
assertEquals(65535 - offset, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, growMem(3));
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 2); offset+=2) {
|
|
|
|
assertEquals(65535 - offset, peek());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryPreservesDataMemOp16();
|
|
|
|
|
|
|
|
function testGrowMemoryPreservesDataMemOp8() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-12 07:32:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset, val = 0;
|
|
|
|
function peek() { return module.exports.load8(offset); }
|
|
|
|
function poke(value) { return module.exports.store8(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 1); offset++, val++) {
|
|
|
|
poke(val);
|
|
|
|
assertEquals(val, peek());
|
|
|
|
if (val == 255) val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(1, growMem(3));
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
|
|
|
|
for(offset = 0; offset <= (kPageSize - 1); offset++, val++) {
|
|
|
|
assertEquals(val, peek());
|
|
|
|
if (val == 255) val = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryPreservesDataMemOp8();
|
2016-09-28 20:55:42 +00:00
|
|
|
|
|
|
|
function testGrowMemoryOutOfBoundsOffset() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
2016-11-08 09:55:05 +00:00
|
|
|
builder.addMemory(1, kV8MaxPages, false);
|
2016-09-28 20:55:42 +00:00
|
|
|
var module = builder.instantiate();
|
|
|
|
var offset, val;
|
|
|
|
function peek() { return module.exports.load(offset); }
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
|
|
|
|
offset = 3*kPageSize + 4;
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(1, growMem(1));
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(2, growMem(1));
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
|
|
|
|
assertEquals(3, growMem(1));
|
|
|
|
|
|
|
|
for (offset = 3*kPageSize; offset <= 4*kPageSize - 4; offset++) {
|
|
|
|
poke(0xaced);
|
|
|
|
assertEquals(0xaced, peek());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (offset = 4*kPageSize - 3; offset <= 4*kPageSize + 4; offset++) {
|
|
|
|
assertTraps(kTrapMemOutOfBounds, poke);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryOutOfBoundsOffset();
|
2016-10-20 07:38:55 +00:00
|
|
|
|
|
|
|
function testGrowMemoryOutOfBoundsOffset2() {
|
|
|
|
var builder = new WasmModuleBuilder();
|
|
|
|
builder.addMemory(16, 128, false);
|
|
|
|
builder.addFunction("main", kSig_v_v)
|
|
|
|
.addBody([
|
|
|
|
kExprI32Const, 20,
|
|
|
|
kExprI32Const, 29,
|
2016-10-26 16:56:05 +00:00
|
|
|
kExprGrowMemory, kMemoryZero,
|
2016-10-20 07:38:55 +00:00
|
|
|
kExprI32StoreMem, 0, 0xFF, 0xFF, 0xFF, 0x3a
|
|
|
|
])
|
|
|
|
.exportAs("main");
|
|
|
|
var module = builder.instantiate();
|
|
|
|
assertTraps(kTrapMemOutOfBounds, module.exports.main);
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryOutOfBoundsOffset2();
|
2016-11-08 09:55:05 +00:00
|
|
|
|
|
|
|
function testGrowMemoryDeclaredMaxTraps() {
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
builder.addMemory(1, 16, false);
|
|
|
|
var module = builder.instantiate();
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
assertEquals(1, growMem(5));
|
|
|
|
assertEquals(6, growMem(5));
|
|
|
|
assertEquals(-1, growMem(6));
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryDeclaredMaxTraps();
|
|
|
|
|
|
|
|
function testGrowMemoryDeclaredSpecMaxTraps() {
|
|
|
|
// The spec maximum is higher than the internal V8 maximum. This test only
|
|
|
|
// checks that grow_memory does not grow past the internally defined maximum
|
|
|
|
// to reflect the currentl implementation.
|
|
|
|
var builder = genGrowMemoryBuilder();
|
|
|
|
var kSpecMaxPages = 65535;
|
|
|
|
builder.addMemory(1, kSpecMaxPages, false);
|
|
|
|
var module = builder.instantiate();
|
|
|
|
function poke(value) { return module.exports.store(offset, value); }
|
|
|
|
function growMem(pages) { return module.exports.grow_memory(pages); }
|
|
|
|
assertEquals(1, growMem(20));
|
|
|
|
assertEquals(-1, growMem(kV8MaxPages - 20));
|
|
|
|
}
|
|
|
|
|
|
|
|
testGrowMemoryDeclaredSpecMaxTraps();
|