mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
wasm: enable JSPI
PR-URL: https://github.com/nodejs/node/pull/59941 Backport-PR-URL: https://github.com/nodejs/node/pull/65123 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
b1596c2b65
commit
d937c8c6cd
3 files changed
+47
No files matched your search
@@ -786,6 +786,9 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args,
|
|||||||
v8_args.emplace_back("--js-source-phase-imports");
|
v8_args.emplace_back("--js-source-phase-imports");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WebAssembly JS Promise Integration
|
||||||
|
v8_args.emplace_back("--experimental-wasm-jspi");
|
||||||
|
|
||||||
#ifdef __POSIX__
|
#ifdef __POSIX__
|
||||||
// Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the
|
// Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the
|
||||||
// performance penalty of frequent EINTR wakeups when the profiler is running.
|
// performance penalty of frequent EINTR wakeups when the profiler is running.
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,44 @@
|
|||||||
|
import '../common/index.mjs';
|
||||||
|
import assert from 'node:assert';
|
||||||
|
import * as fixtures from '../common/fixtures.mjs';
|
||||||
|
|
||||||
|
// Test Wasm JSPI
|
||||||
|
{
|
||||||
|
const asyncImport = async (x) => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 10));
|
||||||
|
return x + 42;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wasm/jspi.wasm contains:
|
||||||
|
*
|
||||||
|
* (module
|
||||||
|
* (type (;0;) (func (param i32) (result i32)))
|
||||||
|
* (import "js" "async" (func $async (;0;) (type 0)))
|
||||||
|
* (export "test" (func $test))
|
||||||
|
* (func $test (;1;) (type 0) (param $x i32) (result i32)
|
||||||
|
* local.get $x
|
||||||
|
* call $async
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* Which is the JS equivalent to:
|
||||||
|
*
|
||||||
|
* import { async_ } from 'js';
|
||||||
|
* export function test (val) {
|
||||||
|
* return async_(val);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* JSPI then allows turning this sync style Wasm call into async code
|
||||||
|
* that suspends on the promise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { instance } = await WebAssembly.instantiate(fixtures.readSync('wasm/jspi.wasm'), {
|
||||||
|
js: {
|
||||||
|
async: new WebAssembly.Suspending(asyncImport),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const promisingExport = WebAssembly.promising(instance.exports.test);
|
||||||
|
assert.strictEqual(await promisingExport(10), 52);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user