nuxt-ai-ready 2.5.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/dist/chunks/agent-skills.mjs +35 -12
- package/dist/chunks/prerender.mjs +35 -24
- package/dist/cli.mjs +5 -2
- package/dist/module.d.mts +4 -0
- package/dist/module.json +2 -2
- package/dist/module.mjs +8 -4
- package/dist/runtime/app/index.d.ts +3 -0
- package/dist/runtime/app/index.js +2 -0
- package/dist/runtime/cache-control.d.ts +2 -0
- package/dist/runtime/cache-control.js +11 -0
- package/dist/runtime/llms-txt-utils.js +1 -1
- package/dist/runtime/server/db/context.d.ts +13 -0
- package/dist/runtime/server/db/drizzle/client.d.ts +6 -7
- package/dist/runtime/server/db/drizzle/client.js +13 -2
- package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/bun.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/d1.js +3 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/libsql.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/neon.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.d.ts +2 -2
- package/dist/runtime/server/db/drizzle/providers/postgres.js +2 -2
- package/dist/runtime/server/db/drizzle/queries.d.ts +27 -27
- package/dist/runtime/server/db/drizzle/queries.js +6 -5
- package/dist/runtime/server/db/drizzle/raw.d.ts +2 -6
- package/dist/runtime/server/db/index.d.ts +1 -1
- package/dist/runtime/server/db/index.js +1 -1
- package/dist/runtime/server/db/queries.d.ts +36 -36
- package/dist/runtime/server/db/queries.js +8 -9
- package/dist/runtime/server/db/seed.d.ts +2 -2
- package/dist/runtime/server/db/seed.js +4 -3
- package/dist/runtime/server/db/shared.d.ts +8 -0
- package/dist/runtime/server/db/shared.js +8 -2
- package/dist/runtime/server/index.d.ts +2 -0
- package/dist/runtime/server/index.js +17 -0
- package/dist/runtime/server/mcp/tools/get-page-markdown.js +1 -1
- package/dist/runtime/server/mcp/tools/list-pages.js +1 -1
- package/dist/runtime/server/mcp/tools/search-pages.js +1 -1
- package/dist/runtime/server/middleware/markdown.prerender.js +1 -1
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +16 -0
- package/dist/runtime/server/plugins/html-capture.prerender.js +6 -4
- package/dist/runtime/server/plugins/link-header-nitro3.d.ts +2 -0
- package/dist/runtime/server/plugins/link-header-nitro3.js +20 -0
- package/dist/runtime/server/plugins/link-header.d.ts +6 -0
- package/dist/runtime/server/plugins/link-header.js +7 -11
- package/dist/runtime/server/plugins/markdown-negotiation.js +8 -1
- package/dist/runtime/server/plugins/sitemap-seeder.js +3 -3
- package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-artifact.js +10 -10
- package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
- package/dist/runtime/server/routes/agent-skills-index.js +7 -6
- package/dist/runtime/server/routes/ai-catalog.d.ts +2 -1
- package/dist/runtime/server/routes/ai-catalog.js +7 -8
- package/dist/runtime/server/routes/api-catalog.d.ts +3 -1
- package/dist/runtime/server/routes/api-catalog.js +12 -12
- package/dist/runtime/server/routes/llms-full.txt.get.js +1 -1
- package/dist/runtime/server/routes/mcp-server-card.d.ts +1 -1
- package/dist/runtime/server/routes/mcp-server-card.js +7 -8
- package/dist/runtime/server/utils/checkStale.d.ts +2 -2
- package/dist/runtime/server/utils/cloudflare-prerendered.d.ts +3 -0
- package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -0
- package/dist/runtime/server/utils/cloudflare.d.ts +5 -5
- package/dist/runtime/server/utils/cloudflare.js +31 -7
- package/dist/runtime/server/utils/content-negotiation.d.ts +5 -3
- package/dist/runtime/server/utils/content-negotiation.js +8 -7
- package/dist/runtime/server/utils/context.d.ts +3 -3
- package/dist/runtime/server/utils/context.js +1 -1
- package/dist/runtime/server/utils/discovery-response.d.ts +2 -0
- package/dist/runtime/server/utils/link-header.d.ts +5 -3
- package/dist/runtime/server/utils/link-header.js +26 -2
- package/dist/runtime/server/utils/markdown-request.d.ts +4 -3
- package/dist/runtime/server/utils/markdown-request.js +15 -13
- package/dist/runtime/server/utils/negotiation-decision.d.ts +4 -0
- package/dist/runtime/server/utils/negotiation-decision.js +6 -5
- package/dist/runtime/server/utils/negotiation-response.js +47 -22
- package/dist/runtime/server/utils/prerender-html.d.ts +2 -1
- package/dist/runtime/server/utils/prerender-html.js +3 -1
- package/dist/runtime/types.d.ts +15 -7
- package/dist/shared/nuxt-ai-ready.B3hAuOLQ.mjs +29 -0
- package/dist/shared/{nuxt-ai-ready.CLSWou20.mjs → nuxt-ai-ready.C34F0LJo.mjs} +560 -219
- package/package.json +85 -20
- package/skills/nuxt-ai-ready/SKILL.md +26 -12
- package/skills/nuxt-ai-ready/references/runtime-indexing.md +7 -6
- package/dist/runtime/server/db/drizzle/providers/sqlite.d.ts +0 -8
- package/dist/runtime/server/db/drizzle/providers/sqlite.js +0 -15
- package/node_modules/@mdream/js/LICENSE.md +0 -9
- package/node_modules/@mdream/js/README.md +0 -792
- package/node_modules/@mdream/js/bin/mdream.mjs +0 -2
- package/node_modules/@mdream/js/dist/_chunks/const.mjs +0 -134
- package/node_modules/@mdream/js/dist/_chunks/index.d.mts +0 -9
- package/node_modules/@mdream/js/dist/_chunks/markdown-processor.mjs +0 -1968
- package/node_modules/@mdream/js/dist/_chunks/minimal.d.mts +0 -6
- package/node_modules/@mdream/js/dist/_chunks/parse.mjs +0 -2756
- package/node_modules/@mdream/js/dist/_chunks/plugins.mjs +0 -725
- package/node_modules/@mdream/js/dist/_chunks/resolve-plugins.mjs +0 -44
- package/node_modules/@mdream/js/dist/_chunks/stream.mjs +0 -37
- package/node_modules/@mdream/js/dist/_chunks/types.d.mts +0 -473
- package/node_modules/@mdream/js/dist/cli.d.mts +0 -1
- package/node_modules/@mdream/js/dist/cli.mjs +0 -32
- package/node_modules/@mdream/js/dist/core.d.mts +0 -15
- package/node_modules/@mdream/js/dist/core.mjs +0 -28
- package/node_modules/@mdream/js/dist/index.d.mts +0 -4
- package/node_modules/@mdream/js/dist/index.mjs +0 -58
- package/node_modules/@mdream/js/dist/llms-txt.d.mts +0 -86
- package/node_modules/@mdream/js/dist/llms-txt.mjs +0 -308
- package/node_modules/@mdream/js/dist/negotiate.d.mts +0 -35
- package/node_modules/@mdream/js/dist/negotiate.mjs +0 -121
- package/node_modules/@mdream/js/dist/parse.d.mts +0 -90
- package/node_modules/@mdream/js/dist/parse.mjs +0 -2
- package/node_modules/@mdream/js/dist/plugins.d.mts +0 -85
- package/node_modules/@mdream/js/dist/plugins.mjs +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.d.mts +0 -2
- package/node_modules/@mdream/js/dist/preset/minimal.mjs +0 -33
- package/node_modules/@mdream/js/dist/splitter.d.mts +0 -18
- package/node_modules/@mdream/js/dist/splitter.mjs +0 -194
- package/node_modules/@mdream/js/package.json +0 -103
- package/node_modules/cac/LICENSE +0 -21
- package/node_modules/cac/README.md +0 -492
- package/node_modules/cac/dist/index.d.ts +0 -196
- package/node_modules/cac/dist/index.js +0 -638
- package/node_modules/cac/package.json +0 -72
- package/node_modules/mdream/LICENSE.md +0 -9
- package/node_modules/mdream/README.md +0 -1091
- package/node_modules/mdream/bin/mdream.mjs +0 -46
- package/node_modules/mdream/dist/browser.d.mts +0 -105
- package/node_modules/mdream/dist/browser.mjs +0 -262
- package/node_modules/mdream/dist/edge.d.mts +0 -100
- package/node_modules/mdream/dist/edge.mjs +0 -250
- package/node_modules/mdream/dist/iife.js +0 -605
- package/node_modules/mdream/dist/index.d.mts +0 -89
- package/node_modules/mdream/dist/index.mjs +0 -184
- package/node_modules/mdream/dist/wasm.d.mts +0 -100
- package/node_modules/mdream/dist/wasm.mjs +0 -140
- package/node_modules/mdream/dist/worker.d.mts +0 -101
- package/node_modules/mdream/dist/worker.mjs +0 -217
- package/node_modules/mdream/napi/index.d.mts +0 -127
- package/node_modules/mdream/napi/index.d.ts +0 -127
- package/node_modules/mdream/napi/index.mjs +0 -725
- package/node_modules/mdream/napi/rust.android-arm-eabi.node +0 -0
- package/node_modules/mdream/napi/rust.android-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-arm64.node +0 -0
- package/node_modules/mdream/napi/rust.darwin-x64.node +0 -0
- package/node_modules/mdream/napi/rust.freebsd-x64.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm-gnueabihf.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-arm64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-gnu.node +0 -0
- package/node_modules/mdream/napi/rust.linux-x64-musl.node +0 -0
- package/node_modules/mdream/napi/rust.wasi.cjs +0 -2144
- package/node_modules/mdream/napi/rust.wasm32-wasi.wasm +0 -0
- package/node_modules/mdream/napi/rust.win32-arm64-msvc.node +0 -0
- package/node_modules/mdream/napi/rust.win32-x64-msvc.node +0 -0
- package/node_modules/mdream/node_modules/@emnapi/core/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/core/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.d.ts +0 -392
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.full.js +0 -8351
- package/node_modules/mdream/node_modules/@emnapi/core/dist/emnapi-core.js +0 -7268
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/async-work.js +0 -843
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.d.ts +0 -4
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/index.js +0 -3
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/threadsafe-function.js +0 -1010
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.d.ts +0 -5
- package/node_modules/mdream/node_modules/@emnapi/core/dist/plugins/v8.js +0 -1446
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/README.md +0 -203
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -236
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1086
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/package.json +0 -35
- package/node_modules/mdream/node_modules/@emnapi/core/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
- package/node_modules/mdream/node_modules/@emnapi/core/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/core/rollup.config.js +0 -60
- package/node_modules/mdream/node_modules/@emnapi/runtime/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/runtime/README.md +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.d.ts +0 -833
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js +0 -2306
- package/node_modules/mdream/node_modules/@emnapi/runtime/dist/emnapi.js.map +0 -1
- package/node_modules/mdream/node_modules/@emnapi/runtime/index.cjs +0 -63
- package/node_modules/mdream/node_modules/@emnapi/runtime/package.json +0 -39
- package/node_modules/mdream/node_modules/@emnapi/runtime/rollup.config.js +0 -25
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/README.md +0 -203
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +0 -240
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +0 -1118
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/package.json +0 -35
- package/node_modules/mdream/node_modules/@emnapi/wasi-threads/rollup.config.js +0 -6
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +0 -1472
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +0 -1470
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +0 -237
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/dist/fs.js +0 -17578
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +0 -317
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/package.json +0 -67
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.cjs +0 -39
- package/node_modules/mdream/node_modules/@napi-rs/wasm-runtime/runtime.js +0 -36
- package/node_modules/mdream/node_modules/@tybys/wasm-util/LICENSE +0 -21
- package/node_modules/mdream/node_modules/@tybys/wasm-util/README.md +0 -193
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +0 -11
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +0 -423
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +0 -2932
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.js +0 -2954
- package/node_modules/mdream/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +0 -158
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/index.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +0 -46
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/load.js +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/memory.js +0 -35
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +0 -103
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +0 -268
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +0 -3
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +0 -192
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +0 -316
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +0 -1599
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +0 -141
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +0 -220
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +0 -128
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +0 -13
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +0 -153
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +0 -39
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +0 -89
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +0 -28
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +0 -97
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +0 -256
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +0 -1
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +0 -186
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +0 -310
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +0 -1593
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +0 -135
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +0 -216
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +0 -113
- package/node_modules/mdream/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +0 -9
- package/node_modules/mdream/node_modules/@tybys/wasm-util/package.json +0 -58
- package/node_modules/mdream/node_modules/tslib/CopyrightNotice.txt +0 -15
- package/node_modules/mdream/node_modules/tslib/LICENSE.txt +0 -12
- package/node_modules/mdream/node_modules/tslib/README.md +0 -164
- package/node_modules/mdream/node_modules/tslib/SECURITY.md +0 -41
- package/node_modules/mdream/node_modules/tslib/modules/index.d.ts +0 -38
- package/node_modules/mdream/node_modules/tslib/modules/index.js +0 -70
- package/node_modules/mdream/node_modules/tslib/modules/package.json +0 -3
- package/node_modules/mdream/node_modules/tslib/package.json +0 -47
- package/node_modules/mdream/node_modules/tslib/tslib.d.ts +0 -460
- package/node_modules/mdream/node_modules/tslib/tslib.es6.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.es6.js +0 -402
- package/node_modules/mdream/node_modules/tslib/tslib.es6.mjs +0 -401
- package/node_modules/mdream/node_modules/tslib/tslib.html +0 -1
- package/node_modules/mdream/node_modules/tslib/tslib.js +0 -484
- package/node_modules/mdream/package.json +0 -110
- package/node_modules/mdream/skills/mdream/SKILL.md +0 -124
- package/node_modules/mdream/skills/mdream/references/runtimes.md +0 -49
- package/node_modules/mdream/wasm/mdream_edge.d.ts +0 -90
- package/node_modules/mdream/wasm/mdream_edge.js +0 -517
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm/package.json +0 -17
- package/node_modules/mdream/wasm-bundler/mdream_edge.d.ts +0 -45
- package/node_modules/mdream/wasm-bundler/mdream_edge.js +0 -13
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.js +0 -413
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm +0 -0
- package/node_modules/mdream/wasm-bundler/mdream_edge_bg.wasm.d.ts +0 -20
- package/node_modules/mdream/wasm-bundler/package.json +0 -19
- package/node_modules/pathe/LICENSE +0 -70
- package/node_modules/pathe/README.md +0 -73
- package/node_modules/pathe/dist/index.cjs +0 -39
- package/node_modules/pathe/dist/index.d.cts +0 -47
- package/node_modules/pathe/dist/index.d.mts +0 -47
- package/node_modules/pathe/dist/index.d.ts +0 -47
- package/node_modules/pathe/dist/index.mjs +0 -19
- package/node_modules/pathe/dist/shared/pathe.BSlhyZSM.cjs +0 -266
- package/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +0 -249
- package/node_modules/pathe/dist/utils.cjs +0 -82
- package/node_modules/pathe/dist/utils.d.cts +0 -32
- package/node_modules/pathe/dist/utils.d.mts +0 -32
- package/node_modules/pathe/dist/utils.d.ts +0 -32
- package/node_modules/pathe/dist/utils.mjs +0 -77
- package/node_modules/pathe/package.json +0 -61
- package/node_modules/pathe/utils.d.ts +0 -1
|
@@ -1,1472 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region ../node_modules/@emnapi/core/dist/plugins/async-work.js
|
|
3
|
-
function asyncWork(emnapiPluginCtx) {
|
|
4
|
-
const { emnapiCtx, emnapiNodeBinding, emnapiAsyncWorkPoolSize } = emnapiPluginCtx;
|
|
5
|
-
var mod = (function(exports, emnapi_shared, emscripten_runtime) {
|
|
6
|
-
/**
|
|
7
|
-
* @__deps $emnapiCtx
|
|
8
|
-
* @__deps $emnapiEnv
|
|
9
|
-
* @__deps $emnapiNodeBinding
|
|
10
|
-
* @__deps $emnapiAsyncWorkPoolSize
|
|
11
|
-
* @__postset
|
|
12
|
-
* ```
|
|
13
|
-
* emnapiAWST.init();
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
var emnapiAWST = {
|
|
17
|
-
idGen: {},
|
|
18
|
-
values: [void 0],
|
|
19
|
-
queued: /* @__PURE__ */ new Set(),
|
|
20
|
-
pending: [],
|
|
21
|
-
pendingHead: 0,
|
|
22
|
-
init: function() {
|
|
23
|
-
const idGen = {
|
|
24
|
-
nextId: 1,
|
|
25
|
-
list: [],
|
|
26
|
-
listHead: 0,
|
|
27
|
-
generate: function() {
|
|
28
|
-
let id;
|
|
29
|
-
if (idGen.listHead < idGen.list.length) {
|
|
30
|
-
id = idGen.list[idGen.listHead++];
|
|
31
|
-
if (idGen.listHead === idGen.list.length) {
|
|
32
|
-
idGen.list.length = 0;
|
|
33
|
-
idGen.listHead = 0;
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
id = idGen.nextId;
|
|
37
|
-
idGen.nextId++;
|
|
38
|
-
}
|
|
39
|
-
return id;
|
|
40
|
-
},
|
|
41
|
-
reuse: function(id) {
|
|
42
|
-
idGen.list.push(id);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
emnapiAWST.idGen = idGen;
|
|
46
|
-
emnapiAWST.values = [void 0];
|
|
47
|
-
emnapiAWST.queued = /* @__PURE__ */ new Set();
|
|
48
|
-
emnapiAWST.pending = [];
|
|
49
|
-
emnapiAWST.pendingHead = 0;
|
|
50
|
-
},
|
|
51
|
-
create: function(env, resource, resourceName, execute, complete, data) {
|
|
52
|
-
let asyncId = 0;
|
|
53
|
-
let triggerAsyncId = 0;
|
|
54
|
-
if (emnapiNodeBinding) {
|
|
55
|
-
const asyncContext = emnapiNodeBinding.node.emitAsyncInit(resource, resourceName, -1);
|
|
56
|
-
asyncId = asyncContext.asyncId;
|
|
57
|
-
triggerAsyncId = asyncContext.triggerAsyncId;
|
|
58
|
-
}
|
|
59
|
-
const id = emnapiAWST.idGen.generate();
|
|
60
|
-
emnapiAWST.values[id] = {
|
|
61
|
-
env,
|
|
62
|
-
id,
|
|
63
|
-
resource,
|
|
64
|
-
asyncId,
|
|
65
|
-
triggerAsyncId,
|
|
66
|
-
status: 0,
|
|
67
|
-
execute,
|
|
68
|
-
complete,
|
|
69
|
-
data
|
|
70
|
-
};
|
|
71
|
-
return id;
|
|
72
|
-
},
|
|
73
|
-
callComplete: function(work, status) {
|
|
74
|
-
const complete = work.complete;
|
|
75
|
-
const env = work.env;
|
|
76
|
-
const data = work.data;
|
|
77
|
-
const callback = () => {
|
|
78
|
-
if (!complete) return;
|
|
79
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
80
|
-
const scope = emnapiCtx.openScope(envObject);
|
|
81
|
-
try {
|
|
82
|
-
envObject.callbackIntoModule(true, () => {
|
|
83
|
-
emnapiPluginCtx.wasmTable.get(complete)(env, status, data);
|
|
84
|
-
});
|
|
85
|
-
} finally {
|
|
86
|
-
emnapiCtx.closeScope(envObject, scope);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
if (emnapiNodeBinding) emnapiNodeBinding.node.makeCallback(work.resource, callback, [], {
|
|
90
|
-
asyncId: work.asyncId,
|
|
91
|
-
triggerAsyncId: work.triggerAsyncId
|
|
92
|
-
});
|
|
93
|
-
else callback();
|
|
94
|
-
},
|
|
95
|
-
queue: function(id) {
|
|
96
|
-
const work = emnapiAWST.values[id];
|
|
97
|
-
if (!work) return;
|
|
98
|
-
if (work.status === 0) {
|
|
99
|
-
work.status = 1;
|
|
100
|
-
if (emnapiAWST.queued.size >= (Math.abs(emnapiAsyncWorkPoolSize) || 4)) {
|
|
101
|
-
if (emnapiAWST.pendingHead >= 1024 && emnapiAWST.pendingHead * 2 >= emnapiAWST.pending.length) {
|
|
102
|
-
emnapiAWST.pending.splice(0, emnapiAWST.pendingHead);
|
|
103
|
-
emnapiAWST.pendingHead = 0;
|
|
104
|
-
}
|
|
105
|
-
emnapiAWST.pending.push(id);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
emnapiAWST.queued.add(id);
|
|
109
|
-
const env = work.env;
|
|
110
|
-
const data = work.data;
|
|
111
|
-
const execute = work.execute;
|
|
112
|
-
work.status = 2;
|
|
113
|
-
emnapiCtx.features.setImmediate(() => {
|
|
114
|
-
emnapiPluginCtx.wasmTable.get(execute)(env, data);
|
|
115
|
-
emnapiAWST.queued.delete(id);
|
|
116
|
-
work.status = 3;
|
|
117
|
-
emnapiCtx.features.setImmediate(() => {
|
|
118
|
-
emnapiAWST.callComplete(work, 0);
|
|
119
|
-
});
|
|
120
|
-
if (emnapiAWST.pendingHead < emnapiAWST.pending.length) {
|
|
121
|
-
const nextWorkId = emnapiAWST.pending[emnapiAWST.pendingHead++];
|
|
122
|
-
if (emnapiAWST.pendingHead === emnapiAWST.pending.length) {
|
|
123
|
-
emnapiAWST.pending.length = 0;
|
|
124
|
-
emnapiAWST.pendingHead = 0;
|
|
125
|
-
}
|
|
126
|
-
emnapiAWST.values[nextWorkId].status = 0;
|
|
127
|
-
emnapiAWST.queue(nextWorkId);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
cancel: function(id) {
|
|
133
|
-
const index = emnapiAWST.pending.indexOf(id, emnapiAWST.pendingHead);
|
|
134
|
-
if (index !== -1) {
|
|
135
|
-
const work = emnapiAWST.values[id];
|
|
136
|
-
if (work && work.status === 1) {
|
|
137
|
-
work.status = 4;
|
|
138
|
-
emnapiAWST.pending.splice(index, 1);
|
|
139
|
-
if (emnapiAWST.pendingHead === emnapiAWST.pending.length) {
|
|
140
|
-
emnapiAWST.pending.length = 0;
|
|
141
|
-
emnapiAWST.pendingHead = 0;
|
|
142
|
-
}
|
|
143
|
-
emnapiCtx.features.setImmediate(() => {
|
|
144
|
-
emnapiAWST.callComplete(work, 11);
|
|
145
|
-
});
|
|
146
|
-
return 0;
|
|
147
|
-
} else return 9;
|
|
148
|
-
}
|
|
149
|
-
return 9;
|
|
150
|
-
},
|
|
151
|
-
remove: function(id) {
|
|
152
|
-
const work = emnapiAWST.values[id];
|
|
153
|
-
if (!work) return;
|
|
154
|
-
if (emnapiNodeBinding) emnapiNodeBinding.node.emitAsyncDestroy({
|
|
155
|
-
asyncId: work.asyncId,
|
|
156
|
-
triggerAsyncId: work.triggerAsyncId
|
|
157
|
-
});
|
|
158
|
-
emnapiAWST.values[id] = void 0;
|
|
159
|
-
emnapiAWST.idGen.reuse(id);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
const { _emnapi_node_emit_async_init, _emnapi_node_emit_async_destroy, _emnapi_runtime_keepalive_pop, _emnapi_runtime_keepalive_push } = emnapiPluginCtx;
|
|
163
|
-
var emnapiAWMT = {
|
|
164
|
-
pool: [],
|
|
165
|
-
workerReady: null,
|
|
166
|
-
globalAddress: 0,
|
|
167
|
-
globalOffset: {
|
|
168
|
-
idle_threads: 0,
|
|
169
|
-
q: 4,
|
|
170
|
-
next: 4,
|
|
171
|
-
prev: 8,
|
|
172
|
-
mutex: 12,
|
|
173
|
-
cond: 16,
|
|
174
|
-
exit_message: 20,
|
|
175
|
-
end: 28
|
|
176
|
-
},
|
|
177
|
-
offset: {
|
|
178
|
-
resource: 0,
|
|
179
|
-
async_id: 8,
|
|
180
|
-
trigger_async_id: 16,
|
|
181
|
-
env: 24,
|
|
182
|
-
status: 28,
|
|
183
|
-
queue: 32,
|
|
184
|
-
queue_next: 32,
|
|
185
|
-
queue_prev: 36,
|
|
186
|
-
data: 40,
|
|
187
|
-
execute: 44,
|
|
188
|
-
complete: 48,
|
|
189
|
-
end: 52
|
|
190
|
-
},
|
|
191
|
-
/**
|
|
192
|
-
* When another thread grows the shared WebAssembly.Memory, this agent's
|
|
193
|
-
* cached `wasmMemory.buffer` may still have the old shorter length
|
|
194
|
-
* (V8 refreshes it lazily). If a pointer derived from shared memory lies
|
|
195
|
-
* beyond the cached length, `wasmMemory.grow(0)` forces the agent to
|
|
196
|
-
* observe the current memory size and refreshes the buffer.
|
|
197
|
-
*/
|
|
198
|
-
ensureBufferFor(end) {
|
|
199
|
-
let buffer = emscripten_runtime.wasmMemory.buffer;
|
|
200
|
-
if (end > buffer.byteLength) {
|
|
201
|
-
emscripten_runtime.wasmMemory.grow(0);
|
|
202
|
-
buffer = emscripten_runtime.wasmMemory.buffer;
|
|
203
|
-
}
|
|
204
|
-
return buffer;
|
|
205
|
-
},
|
|
206
|
-
init() {
|
|
207
|
-
emnapiAWMT.pool = [];
|
|
208
|
-
emnapiAWMT.workerReady = null;
|
|
209
|
-
if (typeof emscripten_runtime.PThread !== "undefined") {
|
|
210
|
-
emscripten_runtime.PThread.unusedWorkers.forEach(emnapiAWMT.addListener);
|
|
211
|
-
Object.values(emscripten_runtime.PThread.pthreads).forEach(emnapiAWMT.addListener);
|
|
212
|
-
const __original_getNewWorker = emscripten_runtime.PThread.getNewWorker;
|
|
213
|
-
emscripten_runtime.PThread.getNewWorker = function() {
|
|
214
|
-
const r = __original_getNewWorker.apply(this, arguments);
|
|
215
|
-
emnapiAWMT.addListener(r);
|
|
216
|
-
return r;
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
addListener(worker) {
|
|
221
|
-
if (!worker) return false;
|
|
222
|
-
if (worker._emnapiAWMTListener) return true;
|
|
223
|
-
const handler = function(e) {
|
|
224
|
-
const __emnapi__ = (emscripten_runtime.ENVIRONMENT_IS_NODE ? e : e.data).__emnapi__;
|
|
225
|
-
if (__emnapi__) {
|
|
226
|
-
const type = __emnapi__.type;
|
|
227
|
-
const payload = __emnapi__.payload;
|
|
228
|
-
if (type === "async-work-complete") emnapiAWMT.callComplete(payload.work, 0);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
const dispose = function() {
|
|
232
|
-
if (emscripten_runtime.ENVIRONMENT_IS_NODE) worker.off("message", handler);
|
|
233
|
-
else worker.removeEventListener("message", handler, false);
|
|
234
|
-
delete worker._emnapiAWMTListener;
|
|
235
|
-
};
|
|
236
|
-
worker._emnapiAWMTListener = {
|
|
237
|
-
handler,
|
|
238
|
-
dispose
|
|
239
|
-
};
|
|
240
|
-
if (emscripten_runtime.ENVIRONMENT_IS_NODE) worker.on("message", handler);
|
|
241
|
-
else worker.addEventListener("message", handler, false);
|
|
242
|
-
return true;
|
|
243
|
-
},
|
|
244
|
-
initGlobal() {
|
|
245
|
-
if (!emnapiAWMT.globalAddress) {
|
|
246
|
-
emnapiAWMT.globalAddress = emscripten_runtime._malloc(emnapiAWMT.globalOffset.end);
|
|
247
|
-
emnapiAWMT.globalAddress >>>= 0;
|
|
248
|
-
const size = emnapiAWMT.globalOffset.end;
|
|
249
|
-
const addr = emnapiAWMT.globalAddress;
|
|
250
|
-
new Uint8Array(emnapiAWMT.ensureBufferFor(addr + size), addr, size).fill(0);
|
|
251
|
-
emnapiAWMT.queueInit(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.q);
|
|
252
|
-
emnapiAWMT.queueInit(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.exit_message);
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
terminateWorkers() {
|
|
256
|
-
emnapiAWMT.pool.forEach((w) => {
|
|
257
|
-
w._emnapiAWMTListener?.dispose();
|
|
258
|
-
w._emnapiTSFNListener?.dispose();
|
|
259
|
-
w.terminate();
|
|
260
|
-
});
|
|
261
|
-
emnapiAWMT.pool.length = 0;
|
|
262
|
-
},
|
|
263
|
-
initWorkers(n) {
|
|
264
|
-
if (emscripten_runtime.ENVIRONMENT_IS_PTHREAD) return emnapiAWMT.workerReady || (emnapiAWMT.workerReady = Promise.resolve());
|
|
265
|
-
if (emnapiAWMT.workerReady) return emnapiAWMT.workerReady;
|
|
266
|
-
if (!("emnapi_async_worker_create" in emscripten_runtime.wasmInstance.exports)) throw new TypeError("`emnapi_async_worker_create` is not exported, please try to add `--export=emnapi_async_worker_create` to linker flags");
|
|
267
|
-
const emnapi_async_worker_create = emscripten_runtime.wasmInstance.exports.emnapi_async_worker_create;
|
|
268
|
-
const args = [];
|
|
269
|
-
emnapiAWMT.initGlobal();
|
|
270
|
-
for (let i = 0; i < n; ++i) args.push(emnapi_async_worker_create(1, emnapiAWMT.globalAddress));
|
|
271
|
-
const promises = args.map((index) => {
|
|
272
|
-
if (index === 0) return Promise.reject(/* @__PURE__ */ new Error("Failed to create async worker"));
|
|
273
|
-
let worker;
|
|
274
|
-
if (index < 0) {
|
|
275
|
-
worker = emnapiAWMT.pool[-index - 1];
|
|
276
|
-
if (worker) return worker.whenLoaded;
|
|
277
|
-
}
|
|
278
|
-
index >>>= 0;
|
|
279
|
-
const tidOffset = 20;
|
|
280
|
-
const tid = new DataView(emnapiAWMT.ensureBufferFor(index + tidOffset + 4)).getInt32(index + tidOffset, true);
|
|
281
|
-
worker = emscripten_runtime.PThread.pthreads[tid];
|
|
282
|
-
return worker.whenLoaded;
|
|
283
|
-
});
|
|
284
|
-
emnapiAWMT.workerReady = Promise.all(promises);
|
|
285
|
-
return emnapiAWMT.workerReady;
|
|
286
|
-
},
|
|
287
|
-
getResource(work) {
|
|
288
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.resource + 4);
|
|
289
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
290
|
-
return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.resource, true);
|
|
291
|
-
},
|
|
292
|
-
getExecute(work) {
|
|
293
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.execute + 4);
|
|
294
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
295
|
-
return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.execute, true);
|
|
296
|
-
},
|
|
297
|
-
getComplete(work) {
|
|
298
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.complete + 4);
|
|
299
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
300
|
-
return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.complete, true);
|
|
301
|
-
},
|
|
302
|
-
getEnv(work) {
|
|
303
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.env + 4);
|
|
304
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
305
|
-
return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.env, true);
|
|
306
|
-
},
|
|
307
|
-
getData(work) {
|
|
308
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.data + 4);
|
|
309
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
310
|
-
return GET_HEAP_DATA_VIEW().getUint32(work + emnapiAWMT.offset.data, true);
|
|
311
|
-
},
|
|
312
|
-
getMutex() {
|
|
313
|
-
const index = emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.mutex;
|
|
314
|
-
const mutex = {
|
|
315
|
-
lock() {
|
|
316
|
-
const isBrowserMain = typeof window !== "undefined" && typeof document !== "undefined" && !emscripten_runtime.ENVIRONMENT_IS_NODE;
|
|
317
|
-
const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1);
|
|
318
|
-
if (isBrowserMain) {
|
|
319
|
-
while (true) if (Atomics.compareExchange(i32a, 0, 0, 10) === 0) return;
|
|
320
|
-
} else while (true) {
|
|
321
|
-
if (Atomics.compareExchange(i32a, 0, 0, 10) === 0) return;
|
|
322
|
-
Atomics.wait(i32a, 0, 10);
|
|
323
|
-
}
|
|
324
|
-
},
|
|
325
|
-
unlock() {
|
|
326
|
-
const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1);
|
|
327
|
-
if (Atomics.compareExchange(i32a, 0, 10, 0) !== 10) throw new Error("Tried to unlock while not holding the mutex");
|
|
328
|
-
Atomics.notify(i32a, 0, 1);
|
|
329
|
-
},
|
|
330
|
-
execute(fn) {
|
|
331
|
-
mutex.lock();
|
|
332
|
-
try {
|
|
333
|
-
return fn();
|
|
334
|
-
} finally {
|
|
335
|
-
mutex.unlock();
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
return mutex;
|
|
340
|
-
},
|
|
341
|
-
getCond() {
|
|
342
|
-
const index = emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.cond;
|
|
343
|
-
const mutex = emnapiAWMT.getMutex();
|
|
344
|
-
return {
|
|
345
|
-
wait() {
|
|
346
|
-
const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1);
|
|
347
|
-
const value = Atomics.load(i32a, 0);
|
|
348
|
-
mutex.unlock();
|
|
349
|
-
Atomics.wait(i32a, 0, value);
|
|
350
|
-
mutex.lock();
|
|
351
|
-
},
|
|
352
|
-
signal() {
|
|
353
|
-
const i32a = new Int32Array(emnapiAWMT.ensureBufferFor(index + 4), index, 1);
|
|
354
|
-
Atomics.add(i32a, 0, 1);
|
|
355
|
-
Atomics.notify(i32a, 0, 1);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
},
|
|
359
|
-
queueInit(q) {
|
|
360
|
-
emnapiAWMT.ensureBufferFor(q + 4 + 4);
|
|
361
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
362
|
-
GET_HEAP_DATA_VIEW().setUint32(q, q, true);
|
|
363
|
-
GET_HEAP_DATA_VIEW().setUint32(q + 4, q, true);
|
|
364
|
-
},
|
|
365
|
-
queueInsertTail(h, q) {
|
|
366
|
-
emnapiAWMT.ensureBufferFor(h + 4 + 4);
|
|
367
|
-
emnapiAWMT.ensureBufferFor(q + 4 + 4);
|
|
368
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
369
|
-
GET_HEAP_DATA_VIEW().setUint32(q, h, true);
|
|
370
|
-
const tempValue = GET_HEAP_DATA_VIEW().getUint32(h + 4, true);
|
|
371
|
-
GET_HEAP_DATA_VIEW().setUint32(q + 4, tempValue, true);
|
|
372
|
-
const qprev = GET_HEAP_DATA_VIEW().getUint32(q + 4, true);
|
|
373
|
-
GET_HEAP_DATA_VIEW().setUint32(qprev, q, true);
|
|
374
|
-
GET_HEAP_DATA_VIEW().setUint32(h + 4, q, true);
|
|
375
|
-
},
|
|
376
|
-
queueRemove(q) {
|
|
377
|
-
emnapiAWMT.ensureBufferFor(q + 4 + 4);
|
|
378
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
379
|
-
const qprev = GET_HEAP_DATA_VIEW().getUint32(q + 4, true);
|
|
380
|
-
const qnext = GET_HEAP_DATA_VIEW().getUint32(q, true);
|
|
381
|
-
GET_HEAP_DATA_VIEW().setUint32(qprev, qnext, true);
|
|
382
|
-
GET_HEAP_DATA_VIEW().setUint32(qnext + 4, qprev, true);
|
|
383
|
-
},
|
|
384
|
-
queueEmpty(q) {
|
|
385
|
-
emnapiAWMT.ensureBufferFor(q + 4);
|
|
386
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
387
|
-
return q == GET_HEAP_DATA_VIEW().getUint32(q, true);
|
|
388
|
-
},
|
|
389
|
-
scheduleWork: function(work) {
|
|
390
|
-
if (!emnapiAWMT.workerReady?.ready) emnapiAWMT.initWorkers(emnapi_shared._emnapi_async_work_pool_size()).then(() => {
|
|
391
|
-
emnapiAWMT.workerReady.ready = true;
|
|
392
|
-
}).catch((err) => {
|
|
393
|
-
emnapiAWMT.workerReady = null;
|
|
394
|
-
throw err;
|
|
395
|
-
});
|
|
396
|
-
_emnapi_runtime_keepalive_push();
|
|
397
|
-
emnapiCtx.increaseWaitingRequestCounter();
|
|
398
|
-
const statusBuffer = new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1);
|
|
399
|
-
Atomics.store(statusBuffer, 0, 0);
|
|
400
|
-
const mutex = emnapiAWMT.getMutex();
|
|
401
|
-
const cond = emnapiAWMT.getCond();
|
|
402
|
-
mutex.lock();
|
|
403
|
-
try {
|
|
404
|
-
emnapiAWMT.queueInsertTail(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.q, work + emnapiAWMT.offset.queue);
|
|
405
|
-
} catch (err) {
|
|
406
|
-
_emnapi_runtime_keepalive_pop();
|
|
407
|
-
emnapiCtx.decreaseWaitingRequestCounter();
|
|
408
|
-
mutex.unlock();
|
|
409
|
-
throw err;
|
|
410
|
-
}
|
|
411
|
-
emnapiAWMT.ensureBufferFor(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.idle_threads + 4);
|
|
412
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
413
|
-
if (GET_HEAP_DATA_VIEW().getUint32(emnapiAWMT.globalAddress + emnapiAWMT.globalOffset.idle_threads, true) > 0) cond.signal();
|
|
414
|
-
mutex.unlock();
|
|
415
|
-
},
|
|
416
|
-
cancelWork(work) {
|
|
417
|
-
let cancelled = false;
|
|
418
|
-
emnapiAWMT.getMutex().execute(() => {
|
|
419
|
-
emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4);
|
|
420
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
421
|
-
cancelled = !emnapiAWMT.queueEmpty(work + emnapiAWMT.offset.queue) && GET_HEAP_DATA_VIEW().getInt32(work + emnapiAWMT.offset.status, true) !== 2;
|
|
422
|
-
if (cancelled) emnapiAWMT.queueRemove(work + emnapiAWMT.offset.queue);
|
|
423
|
-
});
|
|
424
|
-
if (!cancelled) return 9;
|
|
425
|
-
if (Atomics.compareExchange(new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1), 0, 0, 1) !== 0) return 9;
|
|
426
|
-
emnapiCtx.features.setImmediate(() => {
|
|
427
|
-
emnapiAWMT.callComplete(work, 11);
|
|
428
|
-
});
|
|
429
|
-
return 0;
|
|
430
|
-
},
|
|
431
|
-
callComplete: function(work, status) {
|
|
432
|
-
_emnapi_runtime_keepalive_pop();
|
|
433
|
-
emnapiCtx.decreaseWaitingRequestCounter();
|
|
434
|
-
const complete = emnapiAWMT.getComplete(work);
|
|
435
|
-
const env = emnapiAWMT.getEnv(work);
|
|
436
|
-
const data = emnapiAWMT.getData(work);
|
|
437
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
438
|
-
const scope = emnapiCtx.openScope(envObject);
|
|
439
|
-
const callback = () => {
|
|
440
|
-
if (!complete) return;
|
|
441
|
-
envObject.callbackIntoModule(true, () => {
|
|
442
|
-
emnapiPluginCtx.wasmTable.get(complete)(env, status, data);
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
try {
|
|
446
|
-
if (emnapiNodeBinding) {
|
|
447
|
-
const resource = emnapiAWMT.getResource(work);
|
|
448
|
-
const resource_value = emnapiCtx.getRef(resource).get();
|
|
449
|
-
const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value);
|
|
450
|
-
const view = new DataView(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.trigger_async_id + 8));
|
|
451
|
-
const asyncId = view.getFloat64(work + emnapiAWMT.offset.async_id, true);
|
|
452
|
-
const triggerAsyncId = view.getFloat64(work + emnapiAWMT.offset.trigger_async_id, true);
|
|
453
|
-
emnapiNodeBinding.node.makeCallback(resourceObject, callback, [], {
|
|
454
|
-
asyncId,
|
|
455
|
-
triggerAsyncId
|
|
456
|
-
});
|
|
457
|
-
} else callback();
|
|
458
|
-
} finally {
|
|
459
|
-
emnapiCtx.closeScope(envObject, scope);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
emnapiAWST.init();
|
|
464
|
-
emnapiAWMT.init();
|
|
465
|
-
/** @__sig ippppppp */
|
|
466
|
-
var napi_create_async_work = emnapi_shared.singleThreadAsyncWork ? function(env, resource, resource_name, execute, complete, data, result) {
|
|
467
|
-
if (!env) return 1;
|
|
468
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
469
|
-
envObject.checkGCAccess();
|
|
470
|
-
if (!execute) return envObject.setLastError(1);
|
|
471
|
-
if (!result) return envObject.setLastError(1);
|
|
472
|
-
let resourceObject;
|
|
473
|
-
if (resource) resourceObject = Object(emnapiCtx.jsValueFromNapiValue(resource));
|
|
474
|
-
else resourceObject = {};
|
|
475
|
-
if (!resource_name) return envObject.setLastError(1);
|
|
476
|
-
const resourceName = String(emnapiCtx.jsValueFromNapiValue(resource_name));
|
|
477
|
-
const id = emnapiAWST.create(env, resourceObject, resourceName, execute, complete, data);
|
|
478
|
-
result >>>= 0;
|
|
479
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
480
|
-
GET_HEAP_DATA_VIEW().setUint32(result, id, true);
|
|
481
|
-
return envObject.clearLastError();
|
|
482
|
-
} : function(env, resource, resource_name, execute, complete, data, result) {
|
|
483
|
-
if (!env) return 1;
|
|
484
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
485
|
-
envObject.checkGCAccess();
|
|
486
|
-
if (!execute) return envObject.setLastError(1);
|
|
487
|
-
if (!result) return envObject.setLastError(1);
|
|
488
|
-
let resourceObject;
|
|
489
|
-
if (resource) resourceObject = Object(emnapiCtx.jsValueFromNapiValue(resource));
|
|
490
|
-
else resourceObject = {};
|
|
491
|
-
if (!resource_name) return envObject.setLastError(1);
|
|
492
|
-
const sizeofAW = emnapiAWMT.offset.end;
|
|
493
|
-
let aw = emscripten_runtime._malloc(sizeofAW);
|
|
494
|
-
if (!aw) return envObject.setLastError(9);
|
|
495
|
-
aw >>>= 0;
|
|
496
|
-
new Uint8Array(emnapiAWMT.ensureBufferFor(aw + sizeofAW)).subarray(aw, aw + sizeofAW).fill(0);
|
|
497
|
-
const s = emnapiCtx.napiValueFromJsValue(resourceObject);
|
|
498
|
-
const resource_ = emnapiCtx.createReference(envObject, s, 1, 1).id;
|
|
499
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
500
|
-
GET_HEAP_DATA_VIEW().setUint32(aw, resource_, true);
|
|
501
|
-
_emnapi_node_emit_async_init(s, resource_name, -1, aw + emnapiAWMT.offset.async_id);
|
|
502
|
-
GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.env, env, true);
|
|
503
|
-
GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.execute, execute, true);
|
|
504
|
-
GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.complete, complete, true);
|
|
505
|
-
GET_HEAP_DATA_VIEW().setUint32(aw + emnapiAWMT.offset.data, data, true);
|
|
506
|
-
emnapiAWMT.queueInit(aw + emnapiAWMT.offset.queue);
|
|
507
|
-
result >>>= 0;
|
|
508
|
-
GET_HEAP_DATA_VIEW().setUint32(result, aw, true);
|
|
509
|
-
return envObject.clearLastError();
|
|
510
|
-
};
|
|
511
|
-
/** @__sig ipp */
|
|
512
|
-
var napi_delete_async_work = emnapi_shared.singleThreadAsyncWork ? function(env, work) {
|
|
513
|
-
if (!env) return 1;
|
|
514
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
515
|
-
envObject.checkGCAccess();
|
|
516
|
-
if (!work) return envObject.setLastError(1);
|
|
517
|
-
work >>>= 0;
|
|
518
|
-
emnapiAWST.remove(work);
|
|
519
|
-
return envObject.clearLastError();
|
|
520
|
-
} : function(env, work) {
|
|
521
|
-
if (!env) return 1;
|
|
522
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
523
|
-
envObject.checkGCAccess();
|
|
524
|
-
if (!work) return envObject.setLastError(1);
|
|
525
|
-
work >>>= 0;
|
|
526
|
-
const resource = emnapiAWMT.getResource(work);
|
|
527
|
-
emnapiCtx.getRef(resource).dispose();
|
|
528
|
-
if (emnapiNodeBinding) {
|
|
529
|
-
const view = new DataView(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.trigger_async_id + 8));
|
|
530
|
-
const asyncId = view.getFloat64(work + emnapiAWMT.offset.async_id, true);
|
|
531
|
-
const triggerAsyncId = view.getFloat64(work + emnapiAWMT.offset.trigger_async_id, true);
|
|
532
|
-
_emnapi_node_emit_async_destroy(asyncId, triggerAsyncId);
|
|
533
|
-
}
|
|
534
|
-
emscripten_runtime._free(work);
|
|
535
|
-
return envObject.clearLastError();
|
|
536
|
-
};
|
|
537
|
-
/** @__sig ipp */
|
|
538
|
-
var napi_queue_async_work = emnapi_shared.singleThreadAsyncWork ? function(env, work) {
|
|
539
|
-
if (!env) return 1;
|
|
540
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
541
|
-
if (!work) return envObject.setLastError(1);
|
|
542
|
-
work >>>= 0;
|
|
543
|
-
emnapiAWST.queue(work);
|
|
544
|
-
return envObject.clearLastError();
|
|
545
|
-
} : function(env, work) {
|
|
546
|
-
if (!env) return 1;
|
|
547
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
548
|
-
if (!work) return envObject.setLastError(1);
|
|
549
|
-
work >>>= 0;
|
|
550
|
-
emnapiAWMT.scheduleWork(work);
|
|
551
|
-
return envObject.clearLastError();
|
|
552
|
-
};
|
|
553
|
-
/** @__sig ipp */
|
|
554
|
-
var napi_cancel_async_work = emnapi_shared.singleThreadAsyncWork ? function(env, work) {
|
|
555
|
-
if (!env) return 1;
|
|
556
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
557
|
-
if (!work) return envObject.setLastError(1);
|
|
558
|
-
work >>>= 0;
|
|
559
|
-
const status = emnapiAWST.cancel(work);
|
|
560
|
-
if (status === 0) return envObject.clearLastError();
|
|
561
|
-
return envObject.setLastError(status);
|
|
562
|
-
} : function(env, work) {
|
|
563
|
-
if (!env) return 1;
|
|
564
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
565
|
-
if (!work) return envObject.setLastError(1);
|
|
566
|
-
work >>>= 0;
|
|
567
|
-
const status = emnapiAWMT.cancelWork(work);
|
|
568
|
-
if (status === 0) return envObject.clearLastError();
|
|
569
|
-
return envObject.setLastError(status);
|
|
570
|
-
};
|
|
571
|
-
/** @__sig pp */
|
|
572
|
-
function _emnapi_async_worker(globalAddress) {
|
|
573
|
-
globalAddress >>>= 0;
|
|
574
|
-
emnapiAWMT.globalAddress = globalAddress;
|
|
575
|
-
const mutex = emnapiAWMT.getMutex();
|
|
576
|
-
const cond = emnapiAWMT.getCond();
|
|
577
|
-
mutex.lock();
|
|
578
|
-
const exitMessageAddr = globalAddress + emnapiAWMT.globalOffset.exit_message;
|
|
579
|
-
const idleThreadsAddr = globalAddress + emnapiAWMT.globalOffset.idle_threads;
|
|
580
|
-
const workerQueueAddr = globalAddress + emnapiAWMT.globalOffset.q;
|
|
581
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
582
|
-
for (;;) {
|
|
583
|
-
emnapiAWMT.ensureBufferFor(workerQueueAddr + 4);
|
|
584
|
-
while (emnapiAWMT.queueEmpty(workerQueueAddr)) {
|
|
585
|
-
Atomics.add(new Int32Array(emnapiAWMT.ensureBufferFor(idleThreadsAddr + 4), idleThreadsAddr, 1), 0, 1);
|
|
586
|
-
cond.wait();
|
|
587
|
-
Atomics.sub(new Int32Array(emnapiAWMT.ensureBufferFor(idleThreadsAddr + 4), idleThreadsAddr, 1), 0, 1);
|
|
588
|
-
}
|
|
589
|
-
const q = GET_HEAP_DATA_VIEW().getUint32(workerQueueAddr, true);
|
|
590
|
-
if (q === exitMessageAddr) {
|
|
591
|
-
cond.signal();
|
|
592
|
-
mutex.unlock();
|
|
593
|
-
break;
|
|
594
|
-
}
|
|
595
|
-
const work = q - emnapiAWMT.offset.queue;
|
|
596
|
-
emnapiAWMT.queueRemove(q);
|
|
597
|
-
emnapiAWMT.queueInit(q);
|
|
598
|
-
mutex.unlock();
|
|
599
|
-
const statusBuffer = new Int32Array(emnapiAWMT.ensureBufferFor(work + emnapiAWMT.offset.status + 4), work + emnapiAWMT.offset.status, 1);
|
|
600
|
-
if (Atomics.load(statusBuffer, 0) === 1) emscripten_runtime.abort("unreachable");
|
|
601
|
-
const execute = emnapiAWMT.getExecute(work);
|
|
602
|
-
const env = emnapiAWMT.getEnv(work);
|
|
603
|
-
const data = emnapiAWMT.getData(work);
|
|
604
|
-
emnapiPluginCtx.wasmTable.get(execute)(env, data);
|
|
605
|
-
Atomics.store(statusBuffer, 0, 2);
|
|
606
|
-
const postMessage = emnapi_shared.napiModule.postMessage;
|
|
607
|
-
postMessage({ __emnapi__: {
|
|
608
|
-
type: "async-work-complete",
|
|
609
|
-
payload: { work }
|
|
610
|
-
} });
|
|
611
|
-
mutex.lock();
|
|
612
|
-
}
|
|
613
|
-
return 0;
|
|
614
|
-
}
|
|
615
|
-
/** @__sig ipp */
|
|
616
|
-
function _emnapi_spawn_worker(f, globalAddress) {
|
|
617
|
-
if (typeof emnapi_shared.onCreateWorker !== "function") throw new TypeError("`options.onCreateWorker` is not a function");
|
|
618
|
-
const promises = [];
|
|
619
|
-
const args = [];
|
|
620
|
-
if (!("emnapi_async_worker_create" in emscripten_runtime.wasmInstance.exports)) throw new TypeError("`emnapi_async_worker_create` is not exported, please try to add `--export=emnapi_async_worker_create` to linker flags");
|
|
621
|
-
args.push(emscripten_runtime.wasmInstance.exports.emnapi_async_worker_create(0, 0));
|
|
622
|
-
let ret;
|
|
623
|
-
try {
|
|
624
|
-
const worker = emnapi_shared.onCreateWorker({
|
|
625
|
-
type: "async-work",
|
|
626
|
-
name: "emnapi-async-worker"
|
|
627
|
-
});
|
|
628
|
-
const handleError = () => {
|
|
629
|
-
if (!worker.loaded) return;
|
|
630
|
-
Promise.resolve().then(() => {
|
|
631
|
-
emnapiAWMT.terminateWorkers();
|
|
632
|
-
emscripten_runtime.PThread.terminateAllThreads();
|
|
633
|
-
});
|
|
634
|
-
};
|
|
635
|
-
if (emscripten_runtime.ENVIRONMENT_IS_NODE) worker.on("error", handleError);
|
|
636
|
-
else worker.addEventListener("error", handleError, false);
|
|
637
|
-
const p = emscripten_runtime.PThread.loadWasmModuleToWorker(worker);
|
|
638
|
-
emnapiAWMT.addListener(worker);
|
|
639
|
-
if (typeof emnapiPluginCtx.emnapiTSFN !== "undefined") emnapiPluginCtx.emnapiTSFN.addListener(worker);
|
|
640
|
-
promises.push(p.then(() => {
|
|
641
|
-
if (typeof worker.unref === "function") worker.unref();
|
|
642
|
-
}));
|
|
643
|
-
ret = emnapiAWMT.pool.push(worker) - 1;
|
|
644
|
-
const arg = args[0];
|
|
645
|
-
worker.threadBlockBase = arg;
|
|
646
|
-
worker.postMessage({ __emnapi__: {
|
|
647
|
-
type: "async-worker-init",
|
|
648
|
-
payload: {
|
|
649
|
-
arg,
|
|
650
|
-
func: [f, globalAddress]
|
|
651
|
-
}
|
|
652
|
-
} });
|
|
653
|
-
} catch (err) {
|
|
654
|
-
const arg = args[0];
|
|
655
|
-
emscripten_runtime._free(arg);
|
|
656
|
-
throw err;
|
|
657
|
-
}
|
|
658
|
-
return ret;
|
|
659
|
-
}
|
|
660
|
-
function initWorker(startArg, func) {
|
|
661
|
-
if (emnapi_shared.napiModule.childThread) {
|
|
662
|
-
if (typeof emscripten_runtime.wasmInstance.exports.emnapi_async_worker_init !== "function") throw new TypeError("`emnapi_async_worker_init` is not exported, please try to add `--export=emnapi_async_worker_init` to linker flags");
|
|
663
|
-
emscripten_runtime.wasmInstance.exports.emnapi_async_worker_init(startArg);
|
|
664
|
-
emnapiPluginCtx.wasmTable.get(func[0])(func[1]);
|
|
665
|
-
} else throw new Error("startThread is only available in child threads");
|
|
666
|
-
}
|
|
667
|
-
emnapi_shared.napiModule.initWorker = initWorker;
|
|
668
|
-
exports._emnapi_async_worker = _emnapi_async_worker;
|
|
669
|
-
exports._emnapi_spawn_worker = _emnapi_spawn_worker;
|
|
670
|
-
exports.napi_cancel_async_work = napi_cancel_async_work;
|
|
671
|
-
exports.napi_create_async_work = napi_create_async_work;
|
|
672
|
-
exports.napi_delete_async_work = napi_delete_async_work;
|
|
673
|
-
exports.napi_queue_async_work = napi_queue_async_work;
|
|
674
|
-
return exports;
|
|
675
|
-
})({}, emnapiPluginCtx, emnapiPluginCtx);
|
|
676
|
-
return { importObject: (original) => {
|
|
677
|
-
Object.keys(mod).forEach((key) => {
|
|
678
|
-
if (key.startsWith("napi_") || key.startsWith("node_api_")) original.napi[key] = mod[key];
|
|
679
|
-
else original.env[key] = mod[key];
|
|
680
|
-
});
|
|
681
|
-
} };
|
|
682
|
-
}
|
|
683
|
-
//#endregion
|
|
684
|
-
//#region ../node_modules/@emnapi/core/dist/plugins/threadsafe-function.js
|
|
685
|
-
function threadsafeFunction(emnapiPluginCtx) {
|
|
686
|
-
const { emnapiCtx, emnapiNodeBinding, _emnapi_node_emit_async_destroy: __emnapi_node_emit_async_destroy, _emnapi_node_emit_async_init: __emnapi_node_emit_async_init, _emnapi_runtime_keepalive_pop: __emnapi_runtime_keepalive_pop, _emnapi_runtime_keepalive_push: __emnapi_runtime_keepalive_push } = emnapiPluginCtx;
|
|
687
|
-
var mod = (function(exports, emnapi_shared, emscripten_runtime) {
|
|
688
|
-
/**
|
|
689
|
-
* @__deps malloc
|
|
690
|
-
* @__deps free
|
|
691
|
-
* @__deps $emnapiCtx
|
|
692
|
-
* @__deps $emnapiEnv
|
|
693
|
-
* @__deps $emnapiNodeBinding
|
|
694
|
-
* @__deps _emnapi_node_emit_async_destroy
|
|
695
|
-
* @__deps _emnapi_runtime_keepalive_pop
|
|
696
|
-
* @__postset
|
|
697
|
-
* ```
|
|
698
|
-
* emnapiTSFN.init();
|
|
699
|
-
* ```
|
|
700
|
-
*/
|
|
701
|
-
const emnapiTSFN = {
|
|
702
|
-
_liveSet: {},
|
|
703
|
-
offset: {
|
|
704
|
-
__size__: 0,
|
|
705
|
-
resource: 0,
|
|
706
|
-
async_id: 0,
|
|
707
|
-
trigger_async_id: 0,
|
|
708
|
-
queue_size: 0,
|
|
709
|
-
is_some: 0,
|
|
710
|
-
queue: 0,
|
|
711
|
-
async_pending: 0,
|
|
712
|
-
async_u_fd: 0,
|
|
713
|
-
thread_count: 0,
|
|
714
|
-
state: 0,
|
|
715
|
-
dispatch_state: 0,
|
|
716
|
-
context: 0,
|
|
717
|
-
max_queue_size: 0,
|
|
718
|
-
ref: 0,
|
|
719
|
-
env: 0,
|
|
720
|
-
finalize_data: 0,
|
|
721
|
-
finalize_cb: 0,
|
|
722
|
-
call_js_cb: 0,
|
|
723
|
-
handles_closing: 0,
|
|
724
|
-
async_ref: 0,
|
|
725
|
-
mutex: 0,
|
|
726
|
-
cond: 0
|
|
727
|
-
},
|
|
728
|
-
init() {
|
|
729
|
-
emnapiTSFN._liveSet = /* @__PURE__ */ new Set();
|
|
730
|
-
emnapiTSFN.offset.__size__ = 184;
|
|
731
|
-
emnapiTSFN.offset.resource = 0;
|
|
732
|
-
emnapiTSFN.offset.async_id = 8;
|
|
733
|
-
emnapiTSFN.offset.trigger_async_id = 16;
|
|
734
|
-
emnapiTSFN.offset.queue_size = 60;
|
|
735
|
-
emnapiTSFN.offset.is_some = 24;
|
|
736
|
-
emnapiTSFN.offset.queue = 64;
|
|
737
|
-
emnapiTSFN.offset.async_pending = 132;
|
|
738
|
-
emnapiTSFN.offset.async_u_fd = 96;
|
|
739
|
-
emnapiTSFN.offset.thread_count = 136;
|
|
740
|
-
emnapiTSFN.offset.state = 140;
|
|
741
|
-
emnapiTSFN.offset.dispatch_state = 144;
|
|
742
|
-
emnapiTSFN.offset.context = 148;
|
|
743
|
-
emnapiTSFN.offset.max_queue_size = 152;
|
|
744
|
-
emnapiTSFN.offset.ref = 156;
|
|
745
|
-
emnapiTSFN.offset.env = 160;
|
|
746
|
-
emnapiTSFN.offset.finalize_data = 164;
|
|
747
|
-
emnapiTSFN.offset.finalize_cb = 168;
|
|
748
|
-
emnapiTSFN.offset.call_js_cb = 172;
|
|
749
|
-
emnapiTSFN.offset.handles_closing = 176;
|
|
750
|
-
emnapiTSFN.offset.async_ref = 180;
|
|
751
|
-
emnapiTSFN.offset.mutex = 32;
|
|
752
|
-
emnapiTSFN.offset.cond = 56;
|
|
753
|
-
emnapiTSFN.offset.mutex = emnapiTSFN.offset.mutex + 4;
|
|
754
|
-
if (typeof emscripten_runtime.PThread !== "undefined") {
|
|
755
|
-
emscripten_runtime.PThread.unusedWorkers.forEach(emnapiTSFN.addListener);
|
|
756
|
-
Object.values(emscripten_runtime.PThread.pthreads).forEach(emnapiTSFN.addListener);
|
|
757
|
-
const __original_getNewWorker = emscripten_runtime.PThread.getNewWorker;
|
|
758
|
-
emscripten_runtime.PThread.getNewWorker = function() {
|
|
759
|
-
const r = __original_getNewWorker.apply(this, arguments);
|
|
760
|
-
emnapiTSFN.addListener(r);
|
|
761
|
-
return r;
|
|
762
|
-
};
|
|
763
|
-
}
|
|
764
|
-
},
|
|
765
|
-
addListener(worker) {
|
|
766
|
-
if (!worker) return false;
|
|
767
|
-
if (worker._emnapiTSFNListener) return true;
|
|
768
|
-
const handler = function(e) {
|
|
769
|
-
const __emnapi__ = (emscripten_runtime.ENVIRONMENT_IS_NODE ? e : e.data).__emnapi__;
|
|
770
|
-
if (__emnapi__) {
|
|
771
|
-
const type = __emnapi__.type;
|
|
772
|
-
const payload = __emnapi__.payload;
|
|
773
|
-
if (type === "tsfn-send") {
|
|
774
|
-
const pendng = payload.tsfn + emnapiTSFN.offset.async_pending;
|
|
775
|
-
if (Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2) !== 0) emnapiTSFN.enqueue(payload.tsfn);
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
const dispose = function() {
|
|
780
|
-
if (emscripten_runtime.ENVIRONMENT_IS_NODE) worker.off("message", handler);
|
|
781
|
-
else worker.removeEventListener("message", handler, false);
|
|
782
|
-
delete worker._emnapiTSFNListener;
|
|
783
|
-
};
|
|
784
|
-
worker._emnapiTSFNListener = {
|
|
785
|
-
handler,
|
|
786
|
-
dispose
|
|
787
|
-
};
|
|
788
|
-
if (emscripten_runtime.ENVIRONMENT_IS_NODE) worker.on("message", handler);
|
|
789
|
-
else worker.addEventListener("message", handler, false);
|
|
790
|
-
return true;
|
|
791
|
-
},
|
|
792
|
-
/**
|
|
793
|
-
* When another thread grows the shared WebAssembly.Memory, this agent's
|
|
794
|
-
* cached `wasmMemory.buffer` may still have the old shorter length
|
|
795
|
-
* (V8 refreshes it lazily). If a pointer derived from shared memory lies
|
|
796
|
-
* beyond the cached length, `wasmMemory.grow(0)` forces the agent to
|
|
797
|
-
* observe the current memory size and refreshes the buffer.
|
|
798
|
-
*/
|
|
799
|
-
ensureBufferFor(end) {
|
|
800
|
-
let buffer = emscripten_runtime.wasmMemory.buffer;
|
|
801
|
-
if (end > buffer.byteLength) {
|
|
802
|
-
emscripten_runtime.wasmMemory.grow(0);
|
|
803
|
-
buffer = emscripten_runtime.wasmMemory.buffer;
|
|
804
|
-
}
|
|
805
|
-
return buffer;
|
|
806
|
-
},
|
|
807
|
-
initQueue(func) {
|
|
808
|
-
const size = 8;
|
|
809
|
-
let queue = emscripten_runtime._malloc(size);
|
|
810
|
-
if (!queue) return false;
|
|
811
|
-
queue >>>= 0;
|
|
812
|
-
new Uint8Array(emnapiTSFN.ensureBufferFor(queue + size), queue, size).fill(0);
|
|
813
|
-
emnapiTSFN.storeSizeTypeValue(func + emnapiTSFN.offset.queue, queue, false);
|
|
814
|
-
return true;
|
|
815
|
-
},
|
|
816
|
-
destroyQueue(func) {
|
|
817
|
-
const queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false);
|
|
818
|
-
if (queue) {
|
|
819
|
-
let node = emnapiTSFN.loadSizeTypeValue(queue, false);
|
|
820
|
-
while (node !== 0) {
|
|
821
|
-
const next = emnapiTSFN.loadSizeTypeValue(node + 4, false);
|
|
822
|
-
emscripten_runtime._free(node);
|
|
823
|
-
node = next;
|
|
824
|
-
}
|
|
825
|
-
emscripten_runtime._free(queue);
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
pushQueue(func, data) {
|
|
829
|
-
const queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false);
|
|
830
|
-
const head = emnapiTSFN.loadSizeTypeValue(queue, false);
|
|
831
|
-
const tail = emnapiTSFN.loadSizeTypeValue(queue + 4, false);
|
|
832
|
-
let node = emscripten_runtime._malloc(8);
|
|
833
|
-
if (!node) throw new Error("OOM");
|
|
834
|
-
node >>>= 0;
|
|
835
|
-
emnapiTSFN.storeSizeTypeValue(node, data, false);
|
|
836
|
-
emnapiTSFN.storeSizeTypeValue(node + 4, 0, false);
|
|
837
|
-
if (head === 0 && tail === 0) {
|
|
838
|
-
emnapiTSFN.storeSizeTypeValue(queue, node, false);
|
|
839
|
-
emnapiTSFN.storeSizeTypeValue(queue + 4, node, false);
|
|
840
|
-
} else {
|
|
841
|
-
emnapiTSFN.storeSizeTypeValue(tail + 4, node, false);
|
|
842
|
-
emnapiTSFN.storeSizeTypeValue(queue + 4, node, false);
|
|
843
|
-
}
|
|
844
|
-
emnapiTSFN.addQueueSize(func);
|
|
845
|
-
},
|
|
846
|
-
shiftQueue(func) {
|
|
847
|
-
const queue = emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue, false);
|
|
848
|
-
const head = emnapiTSFN.loadSizeTypeValue(queue, false);
|
|
849
|
-
if (head === 0) return 0;
|
|
850
|
-
const node = head;
|
|
851
|
-
const next = emnapiTSFN.loadSizeTypeValue(head + 4, false);
|
|
852
|
-
emnapiTSFN.storeSizeTypeValue(queue, next, false);
|
|
853
|
-
if (next === 0) emnapiTSFN.storeSizeTypeValue(queue + 4, 0, false);
|
|
854
|
-
emnapiTSFN.storeSizeTypeValue(node + 4, 0, false);
|
|
855
|
-
const value = emnapiTSFN.loadSizeTypeValue(node, false);
|
|
856
|
-
emscripten_runtime._free(node);
|
|
857
|
-
emnapiTSFN.subQueueSize(func);
|
|
858
|
-
return value;
|
|
859
|
-
},
|
|
860
|
-
push(func, data, mode) {
|
|
861
|
-
const mutex = emnapiTSFN.getMutex(func);
|
|
862
|
-
const cond = emnapiTSFN.getCond(func);
|
|
863
|
-
const waitCondition = () => {
|
|
864
|
-
const queueSize = emnapiTSFN.getQueueSize(func);
|
|
865
|
-
const maxSize = emnapiTSFN.getMaxQueueSize(func);
|
|
866
|
-
return queueSize >= maxSize && maxSize > 0 && emnapiTSFN.getState(func) === 0;
|
|
867
|
-
};
|
|
868
|
-
const isBrowserMain = typeof window !== "undefined" && typeof document !== "undefined" && !emscripten_runtime.ENVIRONMENT_IS_NODE;
|
|
869
|
-
let shouldDelete = false;
|
|
870
|
-
const ret = mutex.execute(() => {
|
|
871
|
-
while (waitCondition()) {
|
|
872
|
-
if (mode === 0) return 15;
|
|
873
|
-
/**
|
|
874
|
-
* Browser JS main thread can not use `Atomics.wait`
|
|
875
|
-
*
|
|
876
|
-
* Related:
|
|
877
|
-
* https://github.com/nodejs/node/pull/32689
|
|
878
|
-
* https://github.com/nodejs/node/pull/33453
|
|
879
|
-
*/
|
|
880
|
-
if (isBrowserMain) return 21;
|
|
881
|
-
cond.wait();
|
|
882
|
-
}
|
|
883
|
-
if (emnapiTSFN.getState(func) === 0) {
|
|
884
|
-
emnapiTSFN.pushQueue(func, data);
|
|
885
|
-
emnapiTSFN.send(func);
|
|
886
|
-
return 0;
|
|
887
|
-
}
|
|
888
|
-
if (emnapiTSFN.getThreadCount(func) === 0) return 1;
|
|
889
|
-
emnapiTSFN.subThreadCount(func);
|
|
890
|
-
if (!(emnapiTSFN.getState(func) === 2 && emnapiTSFN.getThreadCount(func) === 0)) return 16;
|
|
891
|
-
shouldDelete = true;
|
|
892
|
-
return 16;
|
|
893
|
-
});
|
|
894
|
-
if (shouldDelete) emnapiTSFN.destroy(func);
|
|
895
|
-
return ret;
|
|
896
|
-
},
|
|
897
|
-
getMutex(func) {
|
|
898
|
-
const index = func + emnapiTSFN.offset.mutex;
|
|
899
|
-
const mutex = {
|
|
900
|
-
lock() {
|
|
901
|
-
const isBrowserMain = typeof window !== "undefined" && typeof document !== "undefined" && !emscripten_runtime.ENVIRONMENT_IS_NODE;
|
|
902
|
-
const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1);
|
|
903
|
-
if (isBrowserMain) {
|
|
904
|
-
while (true) if (Atomics.compareExchange(i32a, 0, 0, 10) === 0) return;
|
|
905
|
-
} else while (true) {
|
|
906
|
-
if (Atomics.compareExchange(i32a, 0, 0, 10) === 0) return;
|
|
907
|
-
Atomics.wait(i32a, 0, 10);
|
|
908
|
-
}
|
|
909
|
-
},
|
|
910
|
-
unlock() {
|
|
911
|
-
const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1);
|
|
912
|
-
if (Atomics.compareExchange(i32a, 0, 10, 0) !== 10) throw new Error("Tried to unlock while not holding the mutex");
|
|
913
|
-
Atomics.notify(i32a, 0, 1);
|
|
914
|
-
},
|
|
915
|
-
execute(fn) {
|
|
916
|
-
mutex.lock();
|
|
917
|
-
try {
|
|
918
|
-
return fn();
|
|
919
|
-
} finally {
|
|
920
|
-
mutex.unlock();
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
};
|
|
924
|
-
return mutex;
|
|
925
|
-
},
|
|
926
|
-
getCond(func) {
|
|
927
|
-
const index = func + emnapiTSFN.offset.cond;
|
|
928
|
-
const mutex = emnapiTSFN.getMutex(func);
|
|
929
|
-
return {
|
|
930
|
-
wait() {
|
|
931
|
-
const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1);
|
|
932
|
-
const value = Atomics.load(i32a, 0);
|
|
933
|
-
mutex.unlock();
|
|
934
|
-
Atomics.wait(i32a, 0, value);
|
|
935
|
-
mutex.lock();
|
|
936
|
-
},
|
|
937
|
-
signal() {
|
|
938
|
-
const i32a = new Int32Array(emnapiTSFN.ensureBufferFor(index + 4), index, 1);
|
|
939
|
-
Atomics.add(i32a, 0, 1);
|
|
940
|
-
Atomics.notify(i32a, 0, 1);
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
},
|
|
944
|
-
getQueueSize(func) {
|
|
945
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.queue_size, true);
|
|
946
|
-
},
|
|
947
|
-
addQueueSize(func) {
|
|
948
|
-
const offset = emnapiTSFN.offset.queue_size;
|
|
949
|
-
let arr, index;
|
|
950
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4));
|
|
951
|
-
index = func + offset >>> 2;
|
|
952
|
-
Atomics.add(arr, index, 1);
|
|
953
|
-
},
|
|
954
|
-
subQueueSize(func) {
|
|
955
|
-
const offset = emnapiTSFN.offset.queue_size;
|
|
956
|
-
let arr, index;
|
|
957
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4));
|
|
958
|
-
index = func + offset >>> 2;
|
|
959
|
-
Atomics.sub(arr, index, 1);
|
|
960
|
-
},
|
|
961
|
-
getThreadCount(func) {
|
|
962
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.thread_count, true);
|
|
963
|
-
},
|
|
964
|
-
addThreadCount(func) {
|
|
965
|
-
const offset = emnapiTSFN.offset.thread_count;
|
|
966
|
-
let arr, index;
|
|
967
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4));
|
|
968
|
-
index = func + offset >>> 2;
|
|
969
|
-
Atomics.add(arr, index, 1);
|
|
970
|
-
},
|
|
971
|
-
subThreadCount(func) {
|
|
972
|
-
const offset = emnapiTSFN.offset.thread_count;
|
|
973
|
-
let arr, index;
|
|
974
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(func + offset + 4));
|
|
975
|
-
index = func + offset >>> 2;
|
|
976
|
-
Atomics.sub(arr, index, 1);
|
|
977
|
-
},
|
|
978
|
-
getState(func) {
|
|
979
|
-
return Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.state + 4)), func + emnapiTSFN.offset.state >>> 2);
|
|
980
|
-
},
|
|
981
|
-
setState(func, value) {
|
|
982
|
-
Atomics.store(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.state + 4)), func + emnapiTSFN.offset.state >>> 2, value);
|
|
983
|
-
},
|
|
984
|
-
getHandlesClosing(func) {
|
|
985
|
-
return Atomics.load(new Int8Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.handles_closing + 1)), func + emnapiTSFN.offset.handles_closing);
|
|
986
|
-
},
|
|
987
|
-
setHandlesClosing(func, value) {
|
|
988
|
-
Atomics.store(new Int8Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.handles_closing + 1)), func + emnapiTSFN.offset.handles_closing, value);
|
|
989
|
-
},
|
|
990
|
-
getDispatchState(func) {
|
|
991
|
-
return Atomics.load(new Uint32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.dispatch_state + 4)), func + emnapiTSFN.offset.dispatch_state >>> 2);
|
|
992
|
-
},
|
|
993
|
-
getContext(func) {
|
|
994
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.context, false);
|
|
995
|
-
},
|
|
996
|
-
getMaxQueueSize(func) {
|
|
997
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.max_queue_size, true);
|
|
998
|
-
},
|
|
999
|
-
getEnv(func) {
|
|
1000
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.env, false);
|
|
1001
|
-
},
|
|
1002
|
-
getCallJSCb(func) {
|
|
1003
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.call_js_cb, false);
|
|
1004
|
-
},
|
|
1005
|
-
getRef(func) {
|
|
1006
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.ref, false);
|
|
1007
|
-
},
|
|
1008
|
-
getResource(func) {
|
|
1009
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.resource, false);
|
|
1010
|
-
},
|
|
1011
|
-
getFinalizeCb(func) {
|
|
1012
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.finalize_cb, false);
|
|
1013
|
-
},
|
|
1014
|
-
getFinalizeData(func) {
|
|
1015
|
-
return emnapiTSFN.loadSizeTypeValue(func + emnapiTSFN.offset.finalize_data, false);
|
|
1016
|
-
},
|
|
1017
|
-
loadSizeTypeValue(offset, unsigned) {
|
|
1018
|
-
let ret;
|
|
1019
|
-
let arr;
|
|
1020
|
-
if (unsigned) {
|
|
1021
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(offset + 4));
|
|
1022
|
-
ret = Atomics.load(arr, offset >>> 2);
|
|
1023
|
-
return ret;
|
|
1024
|
-
} else {
|
|
1025
|
-
arr = new Int32Array(emnapiTSFN.ensureBufferFor(offset + 4));
|
|
1026
|
-
ret = Atomics.load(arr, offset >>> 2);
|
|
1027
|
-
return ret;
|
|
1028
|
-
}
|
|
1029
|
-
},
|
|
1030
|
-
storeSizeTypeValue(offset, value, unsigned) {
|
|
1031
|
-
let arr;
|
|
1032
|
-
if (unsigned) {
|
|
1033
|
-
arr = new Uint32Array(emnapiTSFN.ensureBufferFor(offset + 4));
|
|
1034
|
-
Atomics.store(arr, offset >>> 2, value);
|
|
1035
|
-
return;
|
|
1036
|
-
} else {
|
|
1037
|
-
arr = new Int32Array(emnapiTSFN.ensureBufferFor(offset + 4));
|
|
1038
|
-
Atomics.store(arr, offset >>> 2, value >>> 0);
|
|
1039
|
-
return;
|
|
1040
|
-
}
|
|
1041
|
-
},
|
|
1042
|
-
releaseResources(func) {
|
|
1043
|
-
if (emnapiTSFN.getState(func) !== 2) {
|
|
1044
|
-
emnapiTSFN.setState(func, 2);
|
|
1045
|
-
emnapiTSFN.getEnv(func);
|
|
1046
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
1047
|
-
const ref = emnapiTSFN.getRef(func);
|
|
1048
|
-
if (ref) emnapiCtx.getRef(ref).dispose();
|
|
1049
|
-
const resource = emnapiTSFN.getResource(func);
|
|
1050
|
-
emnapiCtx.getRef(resource).dispose();
|
|
1051
|
-
emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.is_some + 1);
|
|
1052
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
1053
|
-
GET_HEAP_DATA_VIEW().setInt8(func + emnapiTSFN.offset.is_some, 0, true);
|
|
1054
|
-
emnapiCtx.removeCleanupHook(envObject, emnapiTSFN.cleanup, func);
|
|
1055
|
-
envObject.unref();
|
|
1056
|
-
const asyncRefAddress = func + emnapiTSFN.offset.async_ref;
|
|
1057
|
-
const asyncRefOffset = asyncRefAddress >>> 2;
|
|
1058
|
-
const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4));
|
|
1059
|
-
if (Atomics.load(arr, asyncRefOffset) > 0) {
|
|
1060
|
-
Atomics.store(arr, asyncRefOffset, 0);
|
|
1061
|
-
__emnapi_runtime_keepalive_pop();
|
|
1062
|
-
emnapiCtx.decreaseWaitingRequestCounter();
|
|
1063
|
-
}
|
|
1064
|
-
if (emnapiNodeBinding) {
|
|
1065
|
-
const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8));
|
|
1066
|
-
const asyncId = view.getFloat64(func + emnapiTSFN.offset.async_id, true);
|
|
1067
|
-
const triggerAsyncId = view.getFloat64(func + emnapiTSFN.offset.trigger_async_id, true);
|
|
1068
|
-
__emnapi_node_emit_async_destroy(asyncId, triggerAsyncId);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
},
|
|
1072
|
-
destroy(func) {
|
|
1073
|
-
emnapiTSFN._liveSet.delete(func);
|
|
1074
|
-
emnapiTSFN.destroyQueue(func);
|
|
1075
|
-
emnapiTSFN.releaseResources(func);
|
|
1076
|
-
emscripten_runtime._free(func);
|
|
1077
|
-
},
|
|
1078
|
-
emptyQueue(func) {
|
|
1079
|
-
const drainQueue = [];
|
|
1080
|
-
emnapiTSFN.getMutex(func).execute(() => {
|
|
1081
|
-
while (emnapiTSFN.getQueueSize(func) > 0) drainQueue.push(emnapiTSFN.shiftQueue(func));
|
|
1082
|
-
});
|
|
1083
|
-
const callJsCb = emnapiTSFN.getCallJSCb(func);
|
|
1084
|
-
const context = emnapiTSFN.getContext(func);
|
|
1085
|
-
let data;
|
|
1086
|
-
for (let i = 0; i < drainQueue.length; i++) {
|
|
1087
|
-
data = drainQueue[i];
|
|
1088
|
-
if (callJsCb) emnapiPluginCtx.wasmTable.get(callJsCb)(0, 0, context, data);
|
|
1089
|
-
}
|
|
1090
|
-
},
|
|
1091
|
-
maybeDelete(func) {
|
|
1092
|
-
let shouldDelete = false;
|
|
1093
|
-
emnapiTSFN.getMutex(func).execute(() => {
|
|
1094
|
-
if (emnapiTSFN.getThreadCount(func) > 0) emnapiTSFN.releaseResources(func);
|
|
1095
|
-
else shouldDelete = true;
|
|
1096
|
-
});
|
|
1097
|
-
if (shouldDelete) emnapiTSFN.destroy(func);
|
|
1098
|
-
},
|
|
1099
|
-
finalize(func) {
|
|
1100
|
-
emnapiTSFN.getEnv(func);
|
|
1101
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
1102
|
-
emnapiCtx.openScope(envObject);
|
|
1103
|
-
const finalize = emnapiTSFN.getFinalizeCb(func);
|
|
1104
|
-
const data = emnapiTSFN.getFinalizeData(func);
|
|
1105
|
-
const context = emnapiTSFN.getContext(func);
|
|
1106
|
-
const f = () => {
|
|
1107
|
-
envObject.callFinalizerInternal(0, finalize, data, context);
|
|
1108
|
-
};
|
|
1109
|
-
try {
|
|
1110
|
-
emnapiTSFN.emptyQueue(func);
|
|
1111
|
-
if (finalize) {
|
|
1112
|
-
if (emnapiNodeBinding) {
|
|
1113
|
-
const resource = emnapiTSFN.getResource(func);
|
|
1114
|
-
const resource_value = emnapiCtx.getRef(resource).get();
|
|
1115
|
-
const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value);
|
|
1116
|
-
const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8));
|
|
1117
|
-
const asyncId = view.getFloat64(func + emnapiTSFN.offset.async_id, true);
|
|
1118
|
-
const triggerAsyncId = view.getFloat64(func + emnapiTSFN.offset.trigger_async_id, true);
|
|
1119
|
-
emnapiNodeBinding.node.makeCallback(resourceObject, f, [], {
|
|
1120
|
-
asyncId,
|
|
1121
|
-
triggerAsyncId
|
|
1122
|
-
});
|
|
1123
|
-
} else f();
|
|
1124
|
-
}
|
|
1125
|
-
emnapiTSFN.maybeDelete(func);
|
|
1126
|
-
} finally {
|
|
1127
|
-
emnapiCtx.closeScope(envObject);
|
|
1128
|
-
}
|
|
1129
|
-
},
|
|
1130
|
-
cleanup(func) {
|
|
1131
|
-
emnapiTSFN.closeHandlesAndMaybeDelete(func, 1);
|
|
1132
|
-
},
|
|
1133
|
-
closeHandlesAndMaybeDelete(func, set_closing) {
|
|
1134
|
-
emnapiTSFN.getEnv(func);
|
|
1135
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
1136
|
-
emnapiCtx.openScope(envObject);
|
|
1137
|
-
try {
|
|
1138
|
-
if (set_closing) emnapiTSFN.getMutex(func).execute(() => {
|
|
1139
|
-
emnapiTSFN.setState(func, 1);
|
|
1140
|
-
if (emnapiTSFN.getMaxQueueSize(func) > 0) emnapiTSFN.getCond(func).signal();
|
|
1141
|
-
});
|
|
1142
|
-
if (emnapiTSFN.getHandlesClosing(func)) return;
|
|
1143
|
-
emnapiTSFN.setHandlesClosing(func, 1);
|
|
1144
|
-
Atomics.store(new Int32Array(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.async_pending + 4)), func + emnapiTSFN.offset.async_pending >>> 2, 1);
|
|
1145
|
-
emnapiCtx.features.setImmediate(() => {
|
|
1146
|
-
emnapiTSFN.finalize(func);
|
|
1147
|
-
});
|
|
1148
|
-
} finally {
|
|
1149
|
-
emnapiCtx.closeScope(envObject);
|
|
1150
|
-
}
|
|
1151
|
-
},
|
|
1152
|
-
dispatchOne(func) {
|
|
1153
|
-
let data = 0;
|
|
1154
|
-
let popped_value = false;
|
|
1155
|
-
let has_more = false;
|
|
1156
|
-
const mutex = emnapiTSFN.getMutex(func);
|
|
1157
|
-
const cond = emnapiTSFN.getCond(func);
|
|
1158
|
-
mutex.execute(() => {
|
|
1159
|
-
if (emnapiTSFN.getState(func) === 0) {
|
|
1160
|
-
let size = emnapiTSFN.getQueueSize(func);
|
|
1161
|
-
if (size > 0) {
|
|
1162
|
-
data = emnapiTSFN.shiftQueue(func);
|
|
1163
|
-
popped_value = true;
|
|
1164
|
-
const maxQueueSize = emnapiTSFN.getMaxQueueSize(func);
|
|
1165
|
-
if (size === maxQueueSize && maxQueueSize > 0) cond.signal();
|
|
1166
|
-
size--;
|
|
1167
|
-
}
|
|
1168
|
-
if (size === 0) {
|
|
1169
|
-
if (emnapiTSFN.getThreadCount(func) === 0) {
|
|
1170
|
-
emnapiTSFN.setState(func, 1);
|
|
1171
|
-
if (emnapiTSFN.getMaxQueueSize(func) > 0) cond.signal();
|
|
1172
|
-
emnapiTSFN.closeHandlesAndMaybeDelete(func, 0);
|
|
1173
|
-
}
|
|
1174
|
-
} else has_more = true;
|
|
1175
|
-
} else emnapiTSFN.closeHandlesAndMaybeDelete(func, 0);
|
|
1176
|
-
});
|
|
1177
|
-
if (popped_value) {
|
|
1178
|
-
const env = emnapiTSFN.getEnv(func);
|
|
1179
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
1180
|
-
emnapiCtx.openScope(envObject);
|
|
1181
|
-
const f = () => {
|
|
1182
|
-
envObject.callbackIntoModule(false, () => {
|
|
1183
|
-
const callJsCb = emnapiTSFN.getCallJSCb(func);
|
|
1184
|
-
const ref = emnapiTSFN.getRef(func);
|
|
1185
|
-
const js_callback = ref ? emnapiCtx.getRef(ref).get() : 0;
|
|
1186
|
-
if (callJsCb) {
|
|
1187
|
-
const context = emnapiTSFN.getContext(func);
|
|
1188
|
-
emnapiPluginCtx.wasmTable.get(callJsCb)(env, js_callback, context, data);
|
|
1189
|
-
} else {
|
|
1190
|
-
const jsCallback = js_callback ? emnapiCtx.jsValueFromNapiValue(js_callback) : null;
|
|
1191
|
-
if (typeof jsCallback === "function") jsCallback();
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
};
|
|
1195
|
-
try {
|
|
1196
|
-
if (emnapiNodeBinding) {
|
|
1197
|
-
const resource = emnapiTSFN.getResource(func);
|
|
1198
|
-
const resource_value = emnapiCtx.getRef(resource).get();
|
|
1199
|
-
const resourceObject = emnapiCtx.jsValueFromNapiValue(resource_value);
|
|
1200
|
-
const view = new DataView(emnapiTSFN.ensureBufferFor(func + emnapiTSFN.offset.trigger_async_id + 8));
|
|
1201
|
-
emnapiNodeBinding.node.makeCallback(resourceObject, f, [], {
|
|
1202
|
-
asyncId: view.getFloat64(func + emnapiTSFN.offset.async_id, true),
|
|
1203
|
-
triggerAsyncId: view.getFloat64(func + emnapiTSFN.offset.trigger_async_id, true)
|
|
1204
|
-
});
|
|
1205
|
-
} else f();
|
|
1206
|
-
} finally {
|
|
1207
|
-
emnapiCtx.closeScope(envObject);
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
return has_more;
|
|
1211
|
-
},
|
|
1212
|
-
dispatch(func) {
|
|
1213
|
-
let has_more = true;
|
|
1214
|
-
let iterations_left = 1e3;
|
|
1215
|
-
const dispatchStateAddress = func + emnapiTSFN.offset.dispatch_state;
|
|
1216
|
-
const index = dispatchStateAddress >>> 2;
|
|
1217
|
-
while (has_more && --iterations_left !== 0) {
|
|
1218
|
-
Atomics.store(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 1);
|
|
1219
|
-
try {
|
|
1220
|
-
has_more = emnapiTSFN.dispatchOne(func);
|
|
1221
|
-
} catch (err) {
|
|
1222
|
-
if (emnapiTSFN._liveSet.has(func)) {
|
|
1223
|
-
Atomics.exchange(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 0);
|
|
1224
|
-
emnapiTSFN.send(func);
|
|
1225
|
-
}
|
|
1226
|
-
throw err;
|
|
1227
|
-
}
|
|
1228
|
-
if (Atomics.exchange(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), index, 0) !== 1) has_more = true;
|
|
1229
|
-
}
|
|
1230
|
-
if (has_more) emnapiTSFN.send(func);
|
|
1231
|
-
},
|
|
1232
|
-
enqueue(func) {
|
|
1233
|
-
const pending = func + emnapiTSFN.offset.async_pending;
|
|
1234
|
-
const scheduled = func + emnapiTSFN.offset.async_u_fd;
|
|
1235
|
-
const end = Math.max(pending, scheduled) + 4;
|
|
1236
|
-
const state = () => new Int32Array(emnapiTSFN.ensureBufferFor(end));
|
|
1237
|
-
if (Atomics.exchange(state(), scheduled >>> 2, 1) !== 0) return;
|
|
1238
|
-
emnapiCtx.features.setImmediate(() => {
|
|
1239
|
-
if (!emnapiTSFN._liveSet.has(func)) return;
|
|
1240
|
-
if (Atomics.load(state(), pending >>> 2) === 0) {
|
|
1241
|
-
Atomics.store(state(), scheduled >>> 2, 0);
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
emnapiCtx.features.setImmediate(() => {
|
|
1245
|
-
if (!emnapiTSFN._liveSet.has(func)) return;
|
|
1246
|
-
try {
|
|
1247
|
-
if (Atomics.exchange(state(), pending >>> 2, 0) === 0) return;
|
|
1248
|
-
emnapiTSFN.dispatch(func);
|
|
1249
|
-
} finally {
|
|
1250
|
-
if (emnapiTSFN._liveSet.has(func)) {
|
|
1251
|
-
Atomics.store(state(), scheduled >>> 2, 0);
|
|
1252
|
-
if (Atomics.load(state(), pending >>> 2) !== 0) emnapiTSFN.enqueue(func);
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
});
|
|
1256
|
-
});
|
|
1257
|
-
},
|
|
1258
|
-
send(func) {
|
|
1259
|
-
const dispatchStateAddress = func + emnapiTSFN.offset.dispatch_state;
|
|
1260
|
-
if ((Atomics.or(new Uint32Array(emnapiTSFN.ensureBufferFor(dispatchStateAddress + 4)), dispatchStateAddress >>> 2, 2) & 1) === 1) return;
|
|
1261
|
-
const pendng = func + emnapiTSFN.offset.async_pending;
|
|
1262
|
-
if (Atomics.load(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2) !== 0) return;
|
|
1263
|
-
if (Atomics.exchange(new Int32Array(emnapiTSFN.ensureBufferFor(pendng + 4)), pendng >>> 2, 1) === 0) {
|
|
1264
|
-
if (typeof emscripten_runtime.ENVIRONMENT_IS_PTHREAD !== "undefined" && emscripten_runtime.ENVIRONMENT_IS_PTHREAD) postMessage({ __emnapi__: {
|
|
1265
|
-
type: "tsfn-send",
|
|
1266
|
-
payload: { tsfn: func }
|
|
1267
|
-
} });
|
|
1268
|
-
else emnapiTSFN.enqueue(func);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
emnapiTSFN.init();
|
|
1273
|
-
emnapiPluginCtx.emnapiTSFN = emnapiTSFN;
|
|
1274
|
-
/**
|
|
1275
|
-
* @__deps _emnapi_node_emit_async_init
|
|
1276
|
-
* @__deps _emnapi_runtime_keepalive_push
|
|
1277
|
-
* @__sig ippppppppppp
|
|
1278
|
-
*/
|
|
1279
|
-
function napi_create_threadsafe_function(env, func, async_resource, async_resource_name, max_queue_size, initial_thread_count, thread_finalize_data, thread_finalize_cb, context, call_js_cb, result) {
|
|
1280
|
-
if (!env) return 1;
|
|
1281
|
-
const envObject = emnapi_shared.emnapiEnv;
|
|
1282
|
-
envObject.checkGCAccess();
|
|
1283
|
-
if (!async_resource_name) return envObject.setLastError(1);
|
|
1284
|
-
max_queue_size >>>= 0;
|
|
1285
|
-
initial_thread_count >>>= 0;
|
|
1286
|
-
env >>>= 0;
|
|
1287
|
-
thread_finalize_data >>>= 0;
|
|
1288
|
-
thread_finalize_cb >>>= 0;
|
|
1289
|
-
context >>>= 0;
|
|
1290
|
-
call_js_cb >>>= 0;
|
|
1291
|
-
max_queue_size = max_queue_size >>> 0;
|
|
1292
|
-
initial_thread_count = initial_thread_count >>> 0;
|
|
1293
|
-
if (initial_thread_count === 0) return envObject.setLastError(1);
|
|
1294
|
-
if (!result) return envObject.setLastError(1);
|
|
1295
|
-
let ref = 0;
|
|
1296
|
-
func >>>= 0;
|
|
1297
|
-
if (!func) {
|
|
1298
|
-
if (!call_js_cb) return envObject.setLastError(1);
|
|
1299
|
-
} else {
|
|
1300
|
-
if (typeof emnapiCtx.jsValueFromNapiValue(func) !== "function") return envObject.setLastError(1);
|
|
1301
|
-
ref = emnapiCtx.createReference(envObject, func, 1, 1).id;
|
|
1302
|
-
}
|
|
1303
|
-
let asyncResourceObject;
|
|
1304
|
-
if (async_resource) {
|
|
1305
|
-
asyncResourceObject = emnapiCtx.jsValueFromNapiValue(async_resource);
|
|
1306
|
-
if (asyncResourceObject == null) return envObject.setLastError(2);
|
|
1307
|
-
asyncResourceObject = Object(asyncResourceObject);
|
|
1308
|
-
} else asyncResourceObject = {};
|
|
1309
|
-
const resource = emnapiCtx.napiValueFromJsValue(asyncResourceObject);
|
|
1310
|
-
let asyncResourceName = emnapiCtx.jsValueFromNapiValue(async_resource_name);
|
|
1311
|
-
if (typeof asyncResourceName === "symbol") return envObject.setLastError(3);
|
|
1312
|
-
asyncResourceName = String(asyncResourceName);
|
|
1313
|
-
const resource_name = emnapiCtx.napiValueFromJsValue(asyncResourceName);
|
|
1314
|
-
const sizeofTSFN = emnapiTSFN.offset.__size__;
|
|
1315
|
-
let tsfn = emscripten_runtime._malloc(sizeofTSFN);
|
|
1316
|
-
if (!tsfn) return envObject.setLastError(9);
|
|
1317
|
-
tsfn >>>= 0;
|
|
1318
|
-
new Uint8Array(emnapiTSFN.ensureBufferFor(tsfn + sizeofTSFN)).subarray(tsfn, tsfn + sizeofTSFN).fill(0);
|
|
1319
|
-
const resourceRef = emnapiCtx.createReference(envObject, resource, 1, 1);
|
|
1320
|
-
const resource_ = resourceRef.id;
|
|
1321
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
1322
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.resource, resource_, true);
|
|
1323
|
-
if (!emnapiTSFN.initQueue(tsfn)) {
|
|
1324
|
-
emscripten_runtime._free(tsfn);
|
|
1325
|
-
resourceRef.dispose();
|
|
1326
|
-
return envObject.setLastError(9);
|
|
1327
|
-
}
|
|
1328
|
-
__emnapi_node_emit_async_init(resource, resource_name, -1, tsfn + emnapiTSFN.offset.async_id);
|
|
1329
|
-
GET_HEAP_DATA_VIEW().setInt8(tsfn + emnapiTSFN.offset.is_some, 1, true);
|
|
1330
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.thread_count, initial_thread_count, true);
|
|
1331
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.context, context, true);
|
|
1332
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.max_queue_size, max_queue_size, true);
|
|
1333
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.ref, ref, true);
|
|
1334
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.env, env, true);
|
|
1335
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.finalize_data, thread_finalize_data, true);
|
|
1336
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.finalize_cb, thread_finalize_cb, true);
|
|
1337
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.call_js_cb, call_js_cb, true);
|
|
1338
|
-
emnapiCtx.addCleanupHook(envObject, emnapiTSFN.cleanup, tsfn);
|
|
1339
|
-
emnapiTSFN._liveSet.add(tsfn);
|
|
1340
|
-
envObject.ref();
|
|
1341
|
-
__emnapi_runtime_keepalive_push();
|
|
1342
|
-
emnapiCtx.increaseWaitingRequestCounter();
|
|
1343
|
-
GET_HEAP_DATA_VIEW().setUint32(tsfn + emnapiTSFN.offset.async_ref, 1, true);
|
|
1344
|
-
result >>>= 0;
|
|
1345
|
-
GET_HEAP_DATA_VIEW().setUint32(result, tsfn, true);
|
|
1346
|
-
return envObject.clearLastError();
|
|
1347
|
-
}
|
|
1348
|
-
/** @__sig ipp */
|
|
1349
|
-
function napi_get_threadsafe_function_context(func, result) {
|
|
1350
|
-
if (!func || !result) {
|
|
1351
|
-
emscripten_runtime.abort();
|
|
1352
|
-
return 1;
|
|
1353
|
-
}
|
|
1354
|
-
func >>>= 0;
|
|
1355
|
-
result >>>= 0;
|
|
1356
|
-
const context = emnapiTSFN.getContext(func);
|
|
1357
|
-
var HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer), GET_HEAP_DATA_VIEW = () => HEAP_DATA_VIEW.buffer === emnapiPluginCtx.wasmMemory.buffer ? HEAP_DATA_VIEW : HEAP_DATA_VIEW = new DataView(emnapiPluginCtx.wasmMemory.buffer);
|
|
1358
|
-
GET_HEAP_DATA_VIEW().setUint32(result, context, true);
|
|
1359
|
-
return 0;
|
|
1360
|
-
}
|
|
1361
|
-
/** @__sig ippi */
|
|
1362
|
-
function napi_call_threadsafe_function(func, data, mode) {
|
|
1363
|
-
if (!func) {
|
|
1364
|
-
emscripten_runtime.abort();
|
|
1365
|
-
return 1;
|
|
1366
|
-
}
|
|
1367
|
-
func >>>= 0;
|
|
1368
|
-
data >>>= 0;
|
|
1369
|
-
return emnapiTSFN.push(func, data, mode);
|
|
1370
|
-
}
|
|
1371
|
-
/** @__sig ip */
|
|
1372
|
-
function napi_acquire_threadsafe_function(func) {
|
|
1373
|
-
if (!func) {
|
|
1374
|
-
emscripten_runtime.abort();
|
|
1375
|
-
return 1;
|
|
1376
|
-
}
|
|
1377
|
-
func >>>= 0;
|
|
1378
|
-
return emnapiTSFN.getMutex(func).execute(() => {
|
|
1379
|
-
if (emnapiTSFN.getState(func) === 0) {
|
|
1380
|
-
emnapiTSFN.addThreadCount(func);
|
|
1381
|
-
return 0;
|
|
1382
|
-
}
|
|
1383
|
-
return 16;
|
|
1384
|
-
});
|
|
1385
|
-
}
|
|
1386
|
-
/** @__sig ipi */
|
|
1387
|
-
function napi_release_threadsafe_function(func, mode) {
|
|
1388
|
-
if (!func) {
|
|
1389
|
-
emscripten_runtime.abort();
|
|
1390
|
-
return 1;
|
|
1391
|
-
}
|
|
1392
|
-
func >>>= 0;
|
|
1393
|
-
const mutex = emnapiTSFN.getMutex(func);
|
|
1394
|
-
const cond = emnapiTSFN.getCond(func);
|
|
1395
|
-
let shouldDelete = false;
|
|
1396
|
-
const ret = mutex.execute(() => {
|
|
1397
|
-
if (emnapiTSFN.getThreadCount(func) === 0) return 1;
|
|
1398
|
-
emnapiTSFN.subThreadCount(func);
|
|
1399
|
-
if (emnapiTSFN.getThreadCount(func) === 0 || mode === 1) {
|
|
1400
|
-
if (emnapiTSFN.getState(func) === 0) {
|
|
1401
|
-
if (mode === 1) emnapiTSFN.setState(func, 1);
|
|
1402
|
-
if (emnapiTSFN.getState(func) === 1 && emnapiTSFN.getMaxQueueSize(func) > 0) cond.signal();
|
|
1403
|
-
emnapiTSFN.send(func);
|
|
1404
|
-
}
|
|
1405
|
-
}
|
|
1406
|
-
if (!(emnapiTSFN.getState(func) === 2 && emnapiTSFN.getThreadCount(func) === 0)) return 0;
|
|
1407
|
-
shouldDelete = true;
|
|
1408
|
-
return 0;
|
|
1409
|
-
});
|
|
1410
|
-
if (shouldDelete) emnapiTSFN.destroy(func);
|
|
1411
|
-
return ret;
|
|
1412
|
-
}
|
|
1413
|
-
/**
|
|
1414
|
-
* @__deps _emnapi_runtime_keepalive_pop
|
|
1415
|
-
* @__sig ipp
|
|
1416
|
-
*/
|
|
1417
|
-
function napi_unref_threadsafe_function(env, func) {
|
|
1418
|
-
if (!func) {
|
|
1419
|
-
emscripten_runtime.abort();
|
|
1420
|
-
return 1;
|
|
1421
|
-
}
|
|
1422
|
-
func >>>= 0;
|
|
1423
|
-
const asyncRefAddress = func + emnapiTSFN.offset.async_ref;
|
|
1424
|
-
const asyncRefOffset = asyncRefAddress >>> 2;
|
|
1425
|
-
const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4));
|
|
1426
|
-
const currentValue = Atomics.load(arr, asyncRefOffset);
|
|
1427
|
-
if (currentValue > 0) {
|
|
1428
|
-
Atomics.store(arr, asyncRefOffset, currentValue - 1);
|
|
1429
|
-
if (currentValue === 1) {
|
|
1430
|
-
__emnapi_runtime_keepalive_pop();
|
|
1431
|
-
emnapiCtx.decreaseWaitingRequestCounter();
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
return 0;
|
|
1435
|
-
}
|
|
1436
|
-
/**
|
|
1437
|
-
* @__deps _emnapi_runtime_keepalive_push
|
|
1438
|
-
* @__sig ipp
|
|
1439
|
-
*/
|
|
1440
|
-
function napi_ref_threadsafe_function(env, func) {
|
|
1441
|
-
if (!func) {
|
|
1442
|
-
emscripten_runtime.abort();
|
|
1443
|
-
return 1;
|
|
1444
|
-
}
|
|
1445
|
-
func >>>= 0;
|
|
1446
|
-
const asyncRefAddress = func + emnapiTSFN.offset.async_ref;
|
|
1447
|
-
const asyncRefOffset = asyncRefAddress >>> 2;
|
|
1448
|
-
const arr = new Uint32Array(emnapiTSFN.ensureBufferFor(asyncRefAddress + 4));
|
|
1449
|
-
const currentValue = Atomics.load(arr, asyncRefOffset);
|
|
1450
|
-
if (!currentValue) {
|
|
1451
|
-
__emnapi_runtime_keepalive_push();
|
|
1452
|
-
emnapiCtx.increaseWaitingRequestCounter();
|
|
1453
|
-
}
|
|
1454
|
-
Atomics.store(arr, asyncRefOffset, currentValue + 1);
|
|
1455
|
-
return 0;
|
|
1456
|
-
}
|
|
1457
|
-
exports.napi_acquire_threadsafe_function = napi_acquire_threadsafe_function;
|
|
1458
|
-
exports.napi_call_threadsafe_function = napi_call_threadsafe_function;
|
|
1459
|
-
exports.napi_create_threadsafe_function = napi_create_threadsafe_function;
|
|
1460
|
-
exports.napi_get_threadsafe_function_context = napi_get_threadsafe_function_context;
|
|
1461
|
-
exports.napi_ref_threadsafe_function = napi_ref_threadsafe_function;
|
|
1462
|
-
exports.napi_release_threadsafe_function = napi_release_threadsafe_function;
|
|
1463
|
-
exports.napi_unref_threadsafe_function = napi_unref_threadsafe_function;
|
|
1464
|
-
return exports;
|
|
1465
|
-
})({}, emnapiPluginCtx, emnapiPluginCtx);
|
|
1466
|
-
return { importObject: (original) => {
|
|
1467
|
-
Object.assign(original.napi, mod);
|
|
1468
|
-
} };
|
|
1469
|
-
}
|
|
1470
|
-
//#endregion
|
|
1471
|
-
exports.emnapiAsyncWorkPlugin = asyncWork;
|
|
1472
|
-
exports.emnapiTSFNPlugin = threadsafeFunction;
|