mirror of
https://github.com/tc39/test262.git
synced 2025-05-04 15:00:42 +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)
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import * as assert from '../assert.js';
|
|
import Builder from '../Builder.js';
|
|
|
|
async function test() {
|
|
let builder = (new Builder())
|
|
.Type().End()
|
|
.Function().End()
|
|
.Export()
|
|
.Function("foo")
|
|
.End()
|
|
.Code()
|
|
.Function("foo", { params: ["i32"], ret: "i32" }, ["i32"])
|
|
.Block("i32")
|
|
.Loop("i32", b =>
|
|
b.GetLocal(1)
|
|
.GetLocal(0)
|
|
.I32Eqz()
|
|
.BrIf(1)
|
|
|
|
.Call(1)
|
|
.GetLocal(1)
|
|
.I32Add()
|
|
.SetLocal(1)
|
|
.GetLocal(0)
|
|
.I32Const(1)
|
|
.I32Sub()
|
|
.SetLocal(0)
|
|
.Br(0)
|
|
|
|
)
|
|
.End()
|
|
.End()
|
|
.Function("bar", { params: [], ret: "i32" })
|
|
.I32Const(42)
|
|
.Return()
|
|
.End()
|
|
.End()
|
|
|
|
const bin = builder.WebAssembly().get();
|
|
const {instance} = await WebAssembly.instantiate(bin, {});
|
|
|
|
const iters = 100000
|
|
for (let i = 0; i < 100; i++)
|
|
assert.eq(instance.exports.foo(iters), 42 * iters);
|
|
}
|
|
|
|
assert.asyncTest(test());
|