mirror of
https://github.com/tc39/test262.git
synced 2025-05-04 06:50:32 +02:00
* [javascriptcore-test262-automation] changes from git@github.com:WebKit/webkit.git at sha 949e26452cfa153a7f4afe593da97e2fe9e1b706 on Tue Jul 03 2018 14:35:15 GMT-0400 (Eastern Daylight Time)
55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
import Builder from '../Builder.js';
|
|
import * as assert from '../assert.js';
|
|
|
|
let mems = [];
|
|
function makeMem(initial) {
|
|
const desc = {initial};
|
|
mems.push([desc, new WebAssembly.Memory(desc)]);
|
|
}
|
|
for (let i = 0; i < 100; ++i) {
|
|
makeMem(1);
|
|
}
|
|
|
|
// This loop should not OOM! This tests a bug where we
|
|
// would call mmap with zero bytes if we ran out of
|
|
// fast memories but created a slow memory with zero
|
|
// initial page count.
|
|
for (let i = 0; i < 100; ++i) {
|
|
makeMem(0);
|
|
}
|
|
|
|
function testMems() {
|
|
for (const [memDesc, mem] of mems) {
|
|
const builder = (new Builder())
|
|
.Type().End()
|
|
.Import()
|
|
.Memory("imp", "memory", memDesc)
|
|
.End()
|
|
.Function().End()
|
|
.Export()
|
|
.Function("foo")
|
|
.End()
|
|
.Code()
|
|
.Function("foo", { params: [], ret: "i32" })
|
|
.I32Const(0)
|
|
.I32Load8U(0, 0)
|
|
.Return()
|
|
.End()
|
|
.End();
|
|
const bin = builder.WebAssembly().get();
|
|
const module = new WebAssembly.Module(bin);
|
|
const instance = new WebAssembly.Instance(module, {imp: {memory: mem}});
|
|
if (mem.buffer.byteLength > 0)
|
|
assert.eq(instance.exports.foo(), 0);
|
|
else
|
|
assert.throws(() => instance.exports.foo(), WebAssembly.RuntimeError, "Out of bounds memory access");
|
|
}
|
|
}
|
|
|
|
testMems();
|
|
|
|
for (const [_, mem] of mems)
|
|
mem.grow(1);
|
|
|
|
testMems();
|