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)
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
import * as assert from '../assert.js';
|
|
import Builder from '../Builder.js';
|
|
|
|
async function test() {
|
|
const loopDepth = 100;
|
|
const numCompilations = 1;
|
|
const numVars = 30;
|
|
const params = [];
|
|
params.length = numVars;
|
|
params.fill("i32");
|
|
|
|
let builder = (new Builder())
|
|
.Type().End()
|
|
.Import()
|
|
.Memory("imp", "memory", { initial: 0 })
|
|
.End()
|
|
.Function().End()
|
|
.Export()
|
|
.Function("foo")
|
|
.End()
|
|
.Code()
|
|
.Function("foo", { params, ret: "i32" });
|
|
|
|
const makeLoop = (builder, depth) => {
|
|
if (depth === 0)
|
|
return builder;
|
|
|
|
builder = builder
|
|
.Loop("i32", (b) => {
|
|
b.GetLocal(0)
|
|
.I32Const(1)
|
|
.I32Sub()
|
|
.TeeLocal(0)
|
|
.GetLocal(0)
|
|
.I32Eqz()
|
|
.BrIf(1);
|
|
|
|
return makeLoop(b, depth - 1).Br(0);
|
|
});
|
|
return builder;
|
|
}
|
|
|
|
builder = makeLoop(builder, loopDepth);
|
|
builder = builder.End().End();
|
|
|
|
const bin = builder.WebAssembly().get();
|
|
const memory = new WebAssembly.Memory({ initial: 0 });
|
|
const importObject = { "imp": { "memory": memory } };
|
|
|
|
// Compile a bunch of instances in parallel.
|
|
let compilations = [];
|
|
for (let i = 0; i < numCompilations; ++i) {
|
|
compilations.push(WebAssembly.instantiate(bin, importObject));
|
|
}
|
|
|
|
let [inst] = await Promise.all(compilations);
|
|
let module = inst.module;
|
|
|
|
// Compile a bunch of instances from modules in parallel.
|
|
compilations = [];
|
|
for (let i = 0; i < numCompilations; ++i) {
|
|
compilations.push(WebAssembly.instantiate(module, importObject));
|
|
}
|
|
|
|
await Promise.all(compilations);
|
|
|
|
// Compile an instance from a module in parallel, have sync compilation steal it.
|
|
compilations = [];
|
|
compilations.push(WebAssembly.instantiate(module, importObject));
|
|
inst = new WebAssembly.Instance(module, importObject);
|
|
|
|
await Promise.all(compilations);
|
|
}
|
|
|
|
assert.asyncTest(test());
|