forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-element.js
More file actions
34 lines (31 loc) · 933 Bytes
/
basic-element.js
File metadata and controls
34 lines (31 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Builder from '../Builder.js';
import * as assert from '../assert.js';
const tableDescription = {initial: 1, element: "funcref"};
const builder = new Builder()
.Type().End()
.Import()
.Table("imp", "table", tableDescription)
.End()
.Function().End()
.Element()
.Element({tableIndex: 0, offset: 0, functionIndices: [0]})
.End()
.Code()
.Function("foo", {params: ["i32"], ret: "i32"})
.GetLocal(0)
.I32Const(42)
.I32Add()
.Return()
.End()
.End();
const bin = builder.WebAssembly().get();
const module = new WebAssembly.Module(bin);
const table = new WebAssembly.Table(tableDescription);
new WebAssembly.Instance(module, {imp: {table}});
const foo = table.get(0);
const objs = [];
for (let i = 0; i < 10000; i++) {
objs.push(new String("foo"));
if (foo(20) !== 20 + 42)
throw new Error("bad!!!");
}