forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm: add instantiateStreaming support
This commit adds InstantiateStreaming support to allow for some compatability with Web browser environments. Refs: nodejs#21130
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 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
Binary file not shown.
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,9 @@ | ||
;; $ wat2wasm instantiate_streaming.wat -o instantiate_streaming.wasm | ||
(module | ||
(func $add (import "test" "add") (param i32) (param i32) (result i32)) | ||
(func (export "add") (param i32) (param i32) (result i32) | ||
get_local 0 | ||
get_local 1 | ||
call $add | ||
) | ||
) |
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,23 @@ | ||
'use strict'; | ||
|
||
// This test verifies that instantiateStreaming can be used with node. | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
const fs = require('fs'); | ||
|
||
const promise = fs.promises.readFile( | ||
fixtures.path('instantiate_streaming.wasm')); | ||
|
||
// Using an import object just to verify that this works without anything | ||
// needed to be specifically implemented for it to work. | ||
const importObject = { | ||
test: { | ||
add: (arg1, arg2) => arg1 + arg2 | ||
}, | ||
} | ||
|
||
WebAssembly.instantiateStreaming(promise, importObject).then((results) => { | ||
assert.strictEqual(results.instance.exports.add(2, 3), 5); | ||
}); |