Skip to content

Commit 901a9b0

Browse files
authored
[js-api] Sync with WPT tests (WebAssembly#306)
This reflects the WPT changes in web-platform-tests/wpt@5623804 web-platform-tests/wpt@e0c0429 and web-platform-tests/wpt#42764 `wasm-module-builder.js` was not fully synced with the WPT repo; the changes reflected were just enough to pass the tests. This also changes `worker` from `dedicatedworker` in `legacy/exceptions/js-api/basic.tentative.any.js`, even though the matching WPT test has not been updated to use it, because all other tests seem to be using `dedicatedworker` now.
1 parent f30dfee commit 901a9b0

12 files changed

+66
-30
lines changed

test/js-api/exception/constructor.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22
// META: script=/wasm/jsapi/assertions.js
33

44
test(() => {

test/js-api/exception/getArg.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22
// META: script=/wasm/jsapi/memory/assertions.js
33

44
test(() => {

test/js-api/exception/is.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22
// META: script=/wasm/jsapi/memory/assertions.js
33

44
test(() => {

test/js-api/exception/toString.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22

33
test(() => {
44
const argument = { parameters: [] };

test/js-api/instanceTestFactory.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const instanceTestFactory = [
237237

238238
builder.addGlobal(kWasmI32, true)
239239
.exportAs("")
240-
.init = 7;
240+
.init = wasmI32Const(7);
241241

242242
const buffer = builder.toBuffer();
243243

@@ -273,10 +273,10 @@ const instanceTestFactory = [
273273

274274
builder.addGlobal(kWasmI32, true)
275275
.exportAs("global")
276-
.init = 7;
276+
.init = wasmI32Const(7);
277277
builder.addGlobal(kWasmF64, true)
278278
.exportAs("global2")
279-
.init = 1.2;
279+
.init = wasmF64Const(1.2);
280280

281281
builder.addMemory(4, 8, true);
282282

test/js-api/module/exports.any.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ test(() => {
109109

110110
builder.addGlobal(kWasmI32, true)
111111
.exportAs("global")
112-
.init = 7;
112+
.init = wasmI32Const(7);
113113
builder.addGlobal(kWasmF64, true)
114114
.exportAs("global2")
115-
.init = 1.2;
115+
.init = wasmF64Const(1.2);
116116

117117
builder.addMemory(0, 256, true);
118118

@@ -167,7 +167,7 @@ test(() => {
167167

168168
builder.addGlobal(kWasmI32, true)
169169
.exportAs("")
170-
.init = 7;
170+
.init = wasmI32Const(7);
171171

172172
const buffer = builder.toBuffer()
173173
const module = new WebAssembly.Module(buffer);

test/js-api/tag/constructor.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22
// META: script=/wasm/jsapi/assertions.js
33

44
test(() => {

test/js-api/tag/toString.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22

33
test(() => {
44
const argument = { parameters: [] };

test/js-api/tag/type.tentative.any.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// META: global=window,dedicatedworker,jsshell
1+
// META: global=window,dedicatedworker,jsshell,shadowrealm
22
// META: script=/wasm/jsapi/assertions.js
33

44
function assert_type(argument) {

test/js-api/wasm-module-builder.js

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,35 @@ let kWasmI64 = 0x7e;
9797
let kWasmF32 = 0x7d;
9898
let kWasmF64 = 0x7c;
9999
let kWasmS128 = 0x7b;
100-
let kWasmAnyRef = 0x6f;
101-
let kWasmAnyFunc = 0x70;
100+
101+
// These are defined as negative integers to distinguish them from positive type
102+
// indices.
103+
let kWasmNullFuncRef = -0x0d;
104+
let kWasmNullExternRef = -0x0e;
105+
let kWasmNullRef = -0x0f;
106+
let kWasmFuncRef = -0x10;
107+
let kWasmAnyFunc = kWasmFuncRef; // Alias named as in the JS API spec
108+
let kWasmExternRef = -0x11;
109+
let kWasmAnyRef = -0x12;
110+
111+
// Use the positive-byte versions inside function bodies.
112+
let kLeb128Mask = 0x7f;
113+
let kFuncRefCode = kWasmFuncRef & kLeb128Mask;
114+
let kAnyFuncCode = kFuncRefCode; // Alias named as in the JS API spec
115+
let kExternRefCode = kWasmExternRef & kLeb128Mask;
116+
let kAnyRefCode = kWasmAnyRef & kLeb128Mask;
117+
let kNullExternRefCode = kWasmNullExternRef & kLeb128Mask;
118+
let kNullFuncRefCode = kWasmNullFuncRef & kLeb128Mask;
119+
let kNullRefCode = kWasmNullRef & kLeb128Mask;
120+
121+
let kWasmRefNull = 0x63;
122+
let kWasmRef = 0x64;
123+
function wasmRefNullType(heap_type, is_shared = false) {
124+
return {opcode: kWasmRefNull, heap_type: heap_type, is_shared: is_shared};
125+
}
126+
function wasmRefType(heap_type, is_shared = false) {
127+
return {opcode: kWasmRef, heap_type: heap_type, is_shared: is_shared};
128+
}
102129

103130
let kExternalFunction = 0;
104131
let kExternalTable = 1;
@@ -146,14 +173,14 @@ let kSig_v_f = makeSig([kWasmF32], []);
146173
let kSig_f_f = makeSig([kWasmF32], [kWasmF32]);
147174
let kSig_f_d = makeSig([kWasmF64], [kWasmF32]);
148175
let kSig_d_d = makeSig([kWasmF64], [kWasmF64]);
149-
let kSig_r_r = makeSig([kWasmAnyRef], [kWasmAnyRef]);
176+
let kSig_r_r = makeSig([kWasmExternRef], [kWasmExternRef]);
150177
let kSig_a_a = makeSig([kWasmAnyFunc], [kWasmAnyFunc]);
151-
let kSig_i_r = makeSig([kWasmAnyRef], [kWasmI32]);
152-
let kSig_v_r = makeSig([kWasmAnyRef], []);
178+
let kSig_i_r = makeSig([kWasmExternRef], [kWasmI32]);
179+
let kSig_v_r = makeSig([kWasmExternRef], []);
153180
let kSig_v_a = makeSig([kWasmAnyFunc], []);
154-
let kSig_v_rr = makeSig([kWasmAnyRef, kWasmAnyRef], []);
181+
let kSig_v_rr = makeSig([kWasmExternRef, kWasmExternRef], []);
155182
let kSig_v_aa = makeSig([kWasmAnyFunc, kWasmAnyFunc], []);
156-
let kSig_r_v = makeSig([], [kWasmAnyRef]);
183+
let kSig_r_v = makeSig([], [kWasmExternRef]);
157184
let kSig_a_v = makeSig([], [kWasmAnyFunc]);
158185
let kSig_a_i = makeSig([kWasmI32], [kWasmAnyFunc]);
159186

@@ -554,6 +581,16 @@ class Binary {
554581
}
555582
}
556583

584+
emit_type(type) {
585+
if ((typeof type) == 'number') {
586+
this.emit_u8(type >= 0 ? type : type & kLeb128Mask);
587+
} else {
588+
this.emit_u8(type.opcode);
589+
if ('depth' in type) this.emit_u8(type.depth);
590+
this.emit_heap_type(type.heap_type);
591+
}
592+
}
593+
557594
emit_header() {
558595
this.emit_bytes([
559596
kWasmH0, kWasmH1, kWasmH2, kWasmH3, kWasmV0, kWasmV1, kWasmV2, kWasmV3
@@ -898,11 +935,11 @@ class WasmModuleBuilder {
898935
section.emit_u8(kWasmFunctionTypeForm);
899936
section.emit_u32v(type.params.length);
900937
for (let param of type.params) {
901-
section.emit_u8(param);
938+
section.emit_type(param);
902939
}
903940
section.emit_u32v(type.results.length);
904941
for (let result of type.results) {
905-
section.emit_u8(result);
942+
section.emit_type(result);
906943
}
907944
}
908945
});
@@ -1161,7 +1198,7 @@ class WasmModuleBuilder {
11611198
local_decls.push({count: l.s128_count, type: kWasmS128});
11621199
}
11631200
if (l.anyref_count > 0) {
1164-
local_decls.push({count: l.anyref_count, type: kWasmAnyRef});
1201+
local_decls.push({count: l.anyref_count, type: kWasmExternRef});
11651202
}
11661203
if (l.anyfunc_count > 0) {
11671204
local_decls.push({count: l.anyfunc_count, type: kWasmAnyFunc});

0 commit comments

Comments
 (0)