Skip to content

Commit acc45fd

Browse files
committed
refactor: switch to wast
1 parent 7184bb4 commit acc45fd

33 files changed

+101
-23
lines changed

lib/WebpackOptionsDefaulter.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
7373
{
7474
test: /\.wasm$/i,
7575
type: "webassembly/experimental"
76-
},
77-
{
78-
test: /\.wast$/i,
79-
loader: "@webassemblyjs/wast-loader",
80-
type: "webassembly/experimental"
8176
}
8277
]);
8378

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"@webassemblyjs/ast": "1.4.3",
99
"@webassemblyjs/wasm-edit": "1.4.3",
1010
"@webassemblyjs/wasm-parser": "1.4.3",
11-
"@webassemblyjs/wast-loader": "^1.5.4",
1211
"acorn": "^5.0.0",
1312
"acorn-dynamic-import": "^3.0.0",
1413
"ajv": "^6.1.0",
@@ -73,6 +72,7 @@
7372
"url-loader": "^0.6.2",
7473
"val-loader": "^1.0.2",
7574
"vm-browserify": "~0.0.0",
75+
"wast-loader": "^1.5.5",
7676
"webpack-dev-middleware": "^1.9.0",
7777
"worker-loader": "^1.1.1",
7878
"xxhashjs": "^0.2.1"

test/TestCases.template.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ const describeCases = config => {
141141
{
142142
test: /\.pug/,
143143
loader: "pug-loader"
144+
},
145+
{
146+
test: /\.wat$/i,
147+
loader: "wast-loader",
148+
type: "webassembly/experimental"
144149
}
145150
]
146151
},

test/cases/wasm/import-wasm-wasm/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it("should allow to run a WebAssembly module with imports", function() {
2-
return import("./wasm.wasm").then(function(wasm) {
2+
return import("./wasm.wat").then(function(wasm) {
33
const result = wasm.addNumber(20);
44
expect(result).toEqual(42);
55
});
-78 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./wasm2.wat" "getNumber" (func $./wasm2.wasm.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./wasm2.wasm.getNumber))))
9+
-42 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(func $getNumber (export "getNumber") (type $t0) (result i32)
4+
(i32.const 22)))
5+

test/cases/wasm/imports-circular/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { addNumber } from "./wasm.wasm";
1+
import { addNumber } from "./wasm.wat";
22

33
export var result = addNumber(22);
44

-74 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./module.getNumber))))
9+

test/cases/wasm/imports/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it("should allow to run a WebAssembly module with imports", function() {
2-
return import("./wasm.wasm?1").then(function(wasm) {
2+
return import("./wasm.wat?1").then(function(wasm) {
33
const result = wasm.addNumber(3);
44
expect(result).toEqual(11);
55
});

test/cases/wasm/imports/wasm.wasm

-74 Bytes
Binary file not shown.

test/cases/wasm/imports/wasm.wat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
5+
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
6+
(i32.add
7+
(get_local $p0)
8+
(call $./module.getNumber))))
9+
-117 Bytes
Binary file not shown.

test/cases/wasm/memory/mem-access.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(module (type $t0 (func (result i32))) (type $t1 (func (param i32))) (import "./memory.wat" "memory" (memory $./memory.wasm.memory 1)) (func $get (export "get") (type $t0) (result i32) (i32.load (i32.const 0))) (func $set (export "set") (type $t1) (param $p i32) (i32.store (i32.const 0) (get_local $p))))

test/cases/wasm/memory/memory.wasm

-47 Bytes
Binary file not shown.

test/cases/wasm/memory/memory.wat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(module
2+
(memory $memory (export "memory") 1)
3+
(data (i32.const 12) "\00\00\00\00"))
4+

test/cases/wasm/memory/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as a1 from "./mem-access.wasm?1";
2-
import * as a2 from "./mem-access.wasm?2";
1+
import * as a1 from "./mem-access.wat?1";
2+
import * as a2 from "./mem-access.wat?2";
33

44
a1.set(42);
55
export const x1 = a1.get();

test/cases/wasm/order/a.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { trackA, results } from "./tracker";
22
import "./b.js";
3-
import "./wasm.wasm";
3+
import "./wasm.wat";
44

55
trackA();
66

test/cases/wasm/order/wasm.wasm

-82 Bytes
Binary file not shown.

test/cases/wasm/simple/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ it("should allow to run a WebAssembly module (indirect)", function() {
66
});
77

88
it("should allow to run a WebAssembly module (direct)", function() {
9-
return import("./wasm.wasm?2").then(function(wasm) {
9+
return import("./wasm.wat?2").then(function(wasm) {
1010
const result = wasm.add(wasm.getNumber(), 2);
1111
expect(result).toEqual(42);
1212
});

test/cases/wasm/simple/module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { add, getNumber } from "./wasm.wasm?1";
1+
import { add, getNumber } from "./wasm.wat?1";
22

33
export function run() {
44
return add(getNumber(), 2);

test/cases/wasm/simple/wasm.wasm

-63 Bytes
Binary file not shown.

test/cases/wasm/simple/wasm.wat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(module
2+
(type $t0 (func (param i32 i32) (result i32)))
3+
(type $t1 (func (result i32)))
4+
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
5+
(i32.add
6+
(get_local $p0)
7+
(get_local $p1)))
8+
(func $getNumber (export "getNumber") (type $t1) (result i32)
9+
(i32.const 40)))
10+

test/cases/wasm/table/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
const UNKNOWN_FUNCTION_TABLE = /invalid index into function table|invalid function/;
33

44
it("should support tables", function() {
5-
return import("./wasm-table.wasm").then(function(wasm) {
5+
return import("./wasm-table.wat").then(function(wasm) {
66
expect(wasm.callByIndex(0)).toEqual(42);
77
expect(wasm.callByIndex(1)).toEqual(13);
88
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
99
});
1010
});
1111

1212
it("should support exported tables", function() {
13-
return import("./wasm-table-export.wasm").then(function(wasm) {
13+
return import("./wasm-table-export.wat").then(function(wasm) {
1414
expect(wasm.table).toBeInstanceOf(WebAssembly.Table);
1515
expect(wasm.table.length).toBe(2);
1616
const e0 = wasm.table.get(0);
@@ -23,7 +23,7 @@ it("should support exported tables", function() {
2323
});
2424

2525
it("should support imported tables", function() {
26-
return import("./wasm-table-imported.wasm").then(function(wasm) {
26+
return import("./wasm-table-imported.wat").then(function(wasm) {
2727
expect(wasm.callByIndex(0)).toEqual(42);
2828
expect(wasm.callByIndex(1)).toEqual(13);
2929
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
-85 Bytes
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(func $f1 (type $t0) (result i32)
4+
(i32.const 42))
5+
(func $f2 (type $t0) (result i32)
6+
(i32.const 13))
7+
(table $table (export "table") 2 anyfunc)
8+
(elem (i32.const 0) $f1 $f2))
9+
-105 Bytes
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (param i32) (result i32)))
4+
(import "./wasm-table-export.wat" "table" (table $./wasm-table-export.wasm.table 2 anyfunc))
5+
(func $callByIndex (export "callByIndex") (type $t1) (param $i i32) (result i32)
6+
(call_indirect (type $t0)
7+
(get_local $i))))
8+

test/cases/wasm/table/wasm-table.wasm

-84 Bytes
Binary file not shown.

test/cases/wasm/table/wasm-table.wat

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(module
2+
(type $t0 (func (result i32)))
3+
(type $t1 (func (result i32)))
4+
(type $t2 (func (param i32) (result i32)))
5+
(func $f0 (type $t0) (result i32)
6+
(i32.const 42))
7+
(func $f1 (type $t0) (result i32)
8+
(i32.const 13))
9+
(func $callByIndex (export "callByIndex") (type $t2) (param $p0 i32) (result i32)
10+
(call_indirect (type $t1)
11+
(get_local $p0)))
12+
(table $T0 2 anyfunc)
13+
(elem (i32.const 0) $f0 $f1))
14+

yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,6 @@
125125
"@webassemblyjs/wasm-parser" "1.4.3"
126126
webassemblyjs "1.4.3"
127127

128-
"@webassemblyjs/wast-loader@^1.5.4":
129-
version "1.5.4"
130-
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-loader/-/wast-loader-1.5.4.tgz#6db66671edc5955cb77cbf90a6c4f627f6335a6a"
131-
dependencies:
132-
wabt "^1.0.0"
133-
134128
"@webassemblyjs/wast-parser@1.4.3":
135129
version "1.4.3"
136130
resolved "https://registry.yarnpkg.com/@webassemblyjs/wast-parser/-/wast-parser-1.4.3.tgz#3250402e2c5ed53dbe2233c9de1fe1f9f0d51745"
@@ -6273,6 +6267,12 @@ walker@~1.0.5:
62736267
dependencies:
62746268
makeerror "1.0.x"
62756269

6270+
wast-loader@^1.5.5:
6271+
version "1.5.5"
6272+
resolved "https://registry.yarnpkg.com/wast-loader/-/wast-loader-1.5.5.tgz#a1d6cdc468b6963a6e479de683dc74755f09b81a"
6273+
dependencies:
6274+
wabt "^1.0.0"
6275+
62766276
watch@~0.18.0:
62776277
version "0.18.0"
62786278
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"

0 commit comments

Comments
 (0)