forked from WebAssembly/gc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js-api][test] Refine DefaultValue for new reference types
DefaultValue will return undefined for externref as before, but for other nullable reference types will return null. For non-nullable reference types, operations like grow and set should error if the value to set is missing. Also adds WPT tests for the error cases. This requires some updates to wasm-module-builder.js as well. Fixes issue WebAssembly#501
- Loading branch information
Showing
5 changed files
with
76 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// META: global=window,dedicatedworker,jsshell | ||
// META: script=/wasm/jsapi/wasm-module-builder.js | ||
|
||
let exports = {}; | ||
setup(() => { | ||
const builder = new WasmModuleBuilder(); | ||
|
||
builder.addTable(wasmRefType(kWasmAnyRef), 10, 20, [...wasmI32Const(42), ...GCInstr(kExprRefI31)]) | ||
.exportAs("tableAnyNonNullable"); | ||
builder.addTable(wasmRefNullType(kWasmAnyRef), 10, 20) | ||
.exportAs("tableAnyNullable"); | ||
|
||
const buffer = builder.toBuffer(); | ||
const module = new WebAssembly.Module(buffer); | ||
const instance = new WebAssembly.Instance(module, {}); | ||
exports = instance.exports; | ||
}); | ||
|
||
test(() => { | ||
exports.tableAnyNullable.grow(5); | ||
for (let i = 0; i < 5; i++) | ||
assert_equals(exports.tableAnyNullable.get(10 + i), null); | ||
}, "grow (nullable anyref)"); | ||
|
||
test(() => { | ||
assert_throws_js(TypeError, () => { exports.tableAnyNonNullable.grow(5); }); | ||
exports.tableAnyNonNullable.grow(5, "foo"); | ||
for (let i = 0; i < 5; i++) | ||
assert_equals(exports.tableAnyNonNullable.get(10 + i), "foo"); | ||
}, "grow (non-nullable anyref)"); | ||
|
||
test(() => { | ||
for (let i = 0; i < exports.tableAnyNullable.length; i++) { | ||
exports.tableAnyNullable.set(i); | ||
assert_equals(exports.tableAnyNullable.get(i), null); | ||
} | ||
}, "set (nullable anyref)"); | ||
|
||
test(() => { | ||
for (let i = 0; i < exports.tableAnyNonNullable.length; i++) { | ||
assert_throws_js(TypeError, () => { exports.tableAnyNonNullable.set(i); }); | ||
} | ||
}, "set (non-nullable anyref)"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters