-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loader: allow importing wasm modules #18972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Flags: --experimental-modules | ||
|
||
import { crashOnUnhandledRejection } from '../common'; | ||
import assert from 'assert'; | ||
|
||
crashOnUnhandledRejection(); | ||
|
||
async function expectsRejection(fn, settings) { | ||
// Retain async context. | ||
const storedError = new Error('Thrown from:'); | ||
try { | ||
await fn(); | ||
} catch (err) { | ||
try { | ||
assert(err instanceof settings.type, | ||
`${err.name} is not instance of ${settings.type.name}`); | ||
assert.strictEqual(err.name, settings.type.name); | ||
} catch (validationError) { | ||
console.error(validationError); | ||
console.error('Original error:'); | ||
console.error(err); | ||
throw storedError; | ||
} | ||
return; | ||
} | ||
assert.fail('Missing expected exception'); | ||
} | ||
|
||
expectsRejection(() => | ||
import('../fixtures/es-modules/invalid.wasm'), { | ||
type: WebAssembly.CompileError, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Flags: --experimental-modules --harmony-dynamic-import | ||
|
||
import { crashOnUnhandledRejection } from '../common'; | ||
import assert from 'assert'; | ||
|
||
crashOnUnhandledRejection(); | ||
|
||
import { add } from '../fixtures/es-modules/add.wasm'; | ||
|
||
assert.strictEqual(add(2, 3), 5); | ||
|
||
import('../fixtures/es-modules/add.wasm').then((ns) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing that this dynamic Perhaps add another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not checking dynamic instantiation (we know that works), i'm checking the namespace and default exports |
||
assert.strictEqual(ns.add(2, 3), 5); | ||
assert.strictEqual(ns.default(2), 12); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const add = (a, b) => a + b; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
;; source of add.wasm | ||
|
||
(module | ||
(import "./add.mjs" "add" (func $add_i32 (param i32 i32) (result i32))) | ||
|
||
(func $add (param $p0 i32) (param $p1 i32) (result i32) | ||
get_local $p0 | ||
get_local $p1 | ||
call $add_i32) | ||
|
||
(func $add_10 (param $p0 i32) (result i32) | ||
get_local $p0 | ||
i32.const 10 | ||
i32.add) | ||
|
||
(export "add" (func $add)) | ||
(export "default" (func $add_10))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the error thrown in case of a bad or non-existent
wasm
file good enough? Does it include, at least, the path to the problematic module? I would definitely also add a test to verify that an exception is thrown for a bad or non-existent module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-existant
-> DefaultResolve won't resolve the file and MODULE_NOT_FOUNDbad
-> WebAssembly.compile rejects and goes up the chaini'll add another tests for errors