forked from web-platform-tests/wpt
-
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.
[wasm] Source Phase Imports for ESM Integration (web-platform-tests#4…
…2467) Co-authored-by: Nicolò Ribaudo <[email protected]>
- Loading branch information
1 parent
0588aff
commit 8b18dd1
Showing
4 changed files
with
81 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// META: global=window,dedicatedworker,jsshell,shadowrealm | ||
// META: script=/wasm/jsapi/wasm-module-builder.js | ||
// META: script=/wasm/jsapi/assertions.js | ||
|
||
let emptyModuleBinary; | ||
setup(() => { | ||
emptyModuleBinary = new WasmModuleBuilder().toBuffer(); | ||
}); | ||
|
||
test(() => { | ||
assert_equals(typeof AbstractModuleSource, "undefined"); | ||
const AbstractModuleSource = Object.getPrototypeOf(WebAssembly.Module); | ||
assert_equals(AbstractModuleSource.name, "AbstractModuleSource"); | ||
assert_not_equals(AbstractModuleSource, Function); | ||
}, "AbstractModuleSource intrinsic"); | ||
|
||
test(() => { | ||
const AbstractModuleSourceProto = Object.getPrototypeOf(WebAssembly.Module.prototype); | ||
assert_not_equals(AbstractModuleSourceProto, Object); | ||
const AbstractModuleSource = Object.getPrototypeOf(WebAssembly.Module); | ||
assert_equals(AbstractModuleSource.prototype, AbstractModuleSourceProto); | ||
}, "AbstractModuleSourceProto intrinsic"); | ||
|
||
test(() => { | ||
const builder = new WasmModuleBuilder(); | ||
|
||
builder | ||
.addFunction("fn", kSig_v_v) | ||
.addBody([]) | ||
.exportFunc(); | ||
builder.addMemory(0, 256, true); | ||
|
||
const buffer = builder.toBuffer() | ||
const module = new WebAssembly.Module(buffer); | ||
|
||
const AbstractModuleSource = Object.getPrototypeOf(WebAssembly.Module); | ||
const toStringTag = Object.getOwnPropertyDescriptor(AbstractModuleSource.prototype, Symbol.toStringTag).get; | ||
|
||
assert_equals(toStringTag.call(module), "WebAssembly.Module"); | ||
assert_throws_js(TypeError, () => toStringTag.call({})); | ||
}, "AbstractModuleSourceProto toStringTag brand check"); |
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,3 @@ | ||
import source modSource from "./worker.wasm"; | ||
assert_true(modSource instanceof WebAssembly.Module); | ||
assert_true(await import.source("./worker.wasm") === modSource); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import * as mod from "./worker.wasm" | ||
import * as mod from "./worker.wasm"; | ||
assert_true(await import("./worker.wasm") === mod); |
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,35 @@ | ||
<!doctype html> | ||
<title>Source phase imports</title> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script type=module> | ||
setup({ single_test: true }); | ||
|
||
import source exportedNamesSource from "./resources/exported-names.wasm"; | ||
|
||
assert_true(exportedNamesSource instanceof WebAssembly.Module); | ||
const AbstractModuleSource = Object.getPrototypeOf(WebAssembly.Module); | ||
assert_equals(AbstractModuleSource.name, "AbstractModuleSource"); | ||
assert_true(exportedNamesSource instanceof AbstractModuleSource); | ||
|
||
assert_array_equals(WebAssembly.Module.exports(exportedNamesSource).sort(), | ||
["func", "glob", "mem", "tab"]); | ||
|
||
const wasmImportFromWasmSource = await import.source("./resources/wasm-import-from-wasm.wasm"); | ||
|
||
assert_true(wasmImportFromWasmSource instanceof WebAssembly.Module); | ||
|
||
let logged = false; | ||
const instance = await WebAssembly.instantiate(wasmImportFromWasmSource, { | ||
"./wasm-export-to-wasm.wasm": { | ||
log () { | ||
logged = true; | ||
} | ||
} | ||
}); | ||
instance.exports.logExec(); | ||
assert_true(logged); | ||
|
||
done(); | ||
</script> |