| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -782,6 +782,9 @@ static ExitCode ProcessGlobalArgsInternal(std::vector<std::string>* args, | |||
| 782 | 782 | ||
| 783 | 783 | v8_args.emplace_back("--js-source-phase-imports"); | |
| 784 | 784 | ||
| 785 | + // WebAssembly JS Promise Integration | ||
| 786 | + v8_args.emplace_back("--experimental-wasm-jspi"); | ||
| 787 | + | ||
| 785 | 788 | #ifdef __POSIX__ | |
| 786 | 789 | // Block SIGPROF signals when sleeping in epoll_wait/kevent/etc. Avoids the | |
| 787 | 790 | // performance penalty of frequent EINTR wakeups when the profiler is running. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,44 @@ | |||
| 1 | + import '../common/index.mjs'; | ||
| 2 | + import { strictEqual } from 'node:assert'; | ||
| 3 | + import { readSync } from '../common/fixtures.mjs'; | ||
| 4 | + | ||
| 5 | + // Test Wasm JSPI | ||
| 6 | + { | ||
| 7 | + const asyncImport = async (x) => { | ||
| 8 | + await new Promise((resolve) => setTimeout(resolve, 10)); | ||
| 9 | + return x + 42; | ||
| 10 | + }; | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * wasm/jspi.wasm contains: | ||
| 14 | + * | ||
| 15 | + * (module | ||
| 16 | + * (type (;0;) (func (param i32) (result i32))) | ||
| 17 | + * (import "js" "async" (func $async (;0;) (type 0))) | ||
| 18 | + * (export "test" (func $test)) | ||
| 19 | + * (func $test (;1;) (type 0) (param $x i32) (result i32) | ||
| 20 | + * local.get $x | ||
| 21 | + * call $async | ||
| 22 | + * ) | ||
| 23 | + * ) | ||
| 24 | + * | ||
| 25 | + * Which is the JS equivalent to: | ||
| 26 | + * | ||
| 27 | + * import { async_ } from 'js'; | ||
| 28 | + * export function test (val) { | ||
| 29 | + * return async_(val); | ||
| 30 | + * } | ||
| 31 | + * | ||
| 32 | + * JSPI then allows turning this sync style Wasm call into async code | ||
| 33 | + * that suspends on the promise. | ||
| 34 | + */ | ||
| 35 | + | ||
| 36 | + const { instance } = await WebAssembly.instantiate(readSync('wasm/jspi.wasm'), { | ||
| 37 | + js: { | ||
| 38 | + async: new WebAssembly.Suspending(asyncImport), | ||
| 39 | + }, | ||
| 40 | + }); | ||
| 41 | + | ||
| 42 | + const promisingExport = WebAssembly.promising(instance.exports.test); | ||
| 43 | + strictEqual(await promisingExport(10), 52); | ||
| 44 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments