xbintsc 0.6.23 → 0.6.28
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/AGENTS.md +1 -1
- package/dist/src/cli/extensions.js +11 -3
- package/dist/src/cli/extensions.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/state.js +7 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +19 -1
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +23 -0
- package/dist/src/driver/bundler/concatenate.js +210 -0
- package/dist/src/driver/bundler/concatenate.js.map +1 -0
- package/dist/src/driver/bundler/graph.js +9 -5
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.d.ts +4 -4
- package/dist/src/driver/bundler/merge.js +24 -207
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/{namespace-import.d.ts → namespace-object.d.ts} +5 -1
- package/dist/src/driver/bundler/{namespace-import.js → namespace-object.js} +6 -2
- package/dist/src/driver/bundler/namespace-object.js.map +1 -0
- package/dist/src/driver/bundler/{reexport-fixup.d.ts → reexport-resolution.d.ts} +9 -3
- package/dist/src/driver/bundler/{reexport-fixup.js → reexport-resolution.js} +16 -6
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -0
- package/dist/src/driver/fingerprint.d.ts +2 -2
- package/dist/src/driver/fingerprint.js +3 -3
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/link-features.js +1 -1
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/modules.d.ts +12 -5
- package/dist/src/driver/modules.js +12 -5
- package/dist/src/driver/modules.js.map +1 -1
- package/dist/src/driver/paths.js +8 -4
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +13 -1
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/catalog.js +5 -1
- package/dist/src/extensions/catalog.js.map +1 -1
- package/dist/src/extensions/gui/index.js +0 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/link-feature.d.ts +8 -0
- package/dist/src/extensions/node/stream-web/index.d.ts +6 -1
- package/dist/src/extensions/node/stream-web/index.js +59 -4
- package/dist/src/extensions/node/stream-web/index.js.map +1 -1
- package/dist/src/extensions/node/worker_threads/index.d.ts +14 -4
- package/dist/src/extensions/node/worker_threads/index.js +24 -11
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +9 -1
- package/dist/src/extensions/registry.js +4 -1
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/wasm-asset.d.ts +16 -0
- package/dist/src/extensions/wasm-asset.js +28 -0
- package/dist/src/extensions/wasm-asset.js.map +1 -0
- package/dist/src/extensions/wasm.d.ts +17 -0
- package/dist/src/extensions/wasm.js +68 -0
- package/dist/src/extensions/wasm.js.map +1 -0
- package/dist/src/extensions/webworker/index.d.ts +24 -0
- package/dist/src/extensions/webworker/index.js +54 -0
- package/dist/src/extensions/webworker/index.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/tests/driver/deferred-reexport.test.js +25 -0
- package/dist/tests/driver/deferred-reexport.test.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/e2e/async-fs.test.js +44 -0
- package/dist/tests/e2e/async-fs.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +6 -0
- package/dist/tests/e2e/harness.js +13 -1
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/node-crypto-random.test.d.ts +8 -0
- package/dist/tests/e2e/node-crypto-random.test.js +148 -0
- package/dist/tests/e2e/node-crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +1 -1
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.d.ts +8 -0
- package/dist/tests/e2e/web-streams.test.js +274 -0
- package/dist/tests/e2e/web-streams.test.js.map +1 -0
- package/dist/tests/e2e/web-worker.test.d.ts +7 -0
- package/dist/tests/e2e/web-worker.test.js +74 -0
- package/dist/tests/e2e/web-worker.test.js.map +1 -0
- package/dist/tests/e2e/webassembly.test.d.ts +8 -0
- package/dist/tests/e2e/webassembly.test.js +113 -0
- package/dist/tests/e2e/webassembly.test.js.map +1 -0
- package/dist/tests/e2e/worker-api.test.d.ts +14 -0
- package/dist/tests/e2e/worker-api.test.js +460 -0
- package/dist/tests/e2e/worker-api.test.js.map +1 -0
- package/dist/tests/e2e/worker-threads.test.d.ts +8 -0
- package/dist/tests/e2e/worker-threads.test.js +160 -0
- package/dist/tests/e2e/worker-threads.test.js.map +1 -0
- package/dist/tests/extensions/wasm.test.d.ts +1 -0
- package/dist/tests/extensions/wasm.test.js +53 -0
- package/dist/tests/extensions/wasm.test.js.map +1 -0
- package/doc/ai/cli.md +1 -1
- package/doc/ai/contributing.md +11 -4
- package/doc/ai/extensions.md +25 -2
- package/doc/ai/language-support.md +14 -2
- package/doc/ai/zh-CN/cli.md +1 -1
- package/doc/ai/zh-CN/contributing.md +8 -3
- package/doc/ai/zh-CN/extensions.md +23 -2
- package/doc/ai/zh-CN/language-support.md +13 -2
- package/doc/gui/api.md +1 -1
- package/doc/implemented/cli.md +1 -1
- package/doc/implemented/extensions.md +6 -5
- package/doc/implemented/node/stream-web.md +31 -0
- package/doc/implemented/node/worker-threads.md +88 -5
- package/doc/implemented/node.md +2 -1
- package/doc/implemented/streams.md +82 -0
- package/doc/implemented/wasm.md +80 -18
- package/doc/implemented/web-worker.md +84 -0
- package/doc/implemented.md +6 -2
- package/doc/unimplemented/deviations.md +1 -0
- package/doc/unimplemented/node/worker-threads.md +23 -0
- package/doc/unimplemented/node.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/unimplemented/wasm.md +21 -9
- package/doc/unimplemented.md +1 -1
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/implemented/cli.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +7 -6
- package/doc/zh-CN/implemented/node/stream-web.md +24 -0
- package/doc/zh-CN/implemented/node/worker-threads.md +77 -4
- package/doc/zh-CN/implemented/node.md +2 -1
- package/doc/zh-CN/implemented/streams.md +60 -0
- package/doc/zh-CN/implemented/wasm.md +73 -16
- package/doc/zh-CN/implemented/web-worker.md +79 -0
- package/doc/zh-CN/implemented.md +6 -2
- package/doc/zh-CN/unimplemented/deviations.md +1 -0
- package/doc/zh-CN/unimplemented/node/worker-threads.md +20 -0
- package/doc/zh-CN/unimplemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/doc/zh-CN/unimplemented/wasm.md +16 -8
- package/doc/zh-CN/unimplemented.md +1 -1
- package/llms.txt +2 -0
- package/package.json +8 -7
- package/runtime/ext_gui/browser.cpp +1 -1
- package/runtime/ext_node/stream_web/stream_web.c +20 -6
- package/runtime/worker/worker_api.c +422 -0
- package/runtime/worker/worker_codec.c +489 -0
- package/runtime/worker/worker_core.c +445 -0
- package/runtime/worker/worker_internal.h +223 -0
- package/runtime/worker/worker_platform.c +344 -0
- package/runtime/worker/worker_ports.c +203 -0
- package/runtime/worker/worker_transport.c +464 -0
- package/runtime/worker/worker_wire.c +150 -0
- package/runtime/xt_builtins.c +15 -0
- package/runtime/xt_constructors.c +49 -2
- package/runtime/xt_stdlib2/error.inc +4 -0
- package/runtime/xt_streams/common.inc +232 -0
- package/runtime/xt_streams/constructors.inc +232 -0
- package/runtime/xt_streams/encoding.inc +124 -0
- package/runtime/xt_streams/readable-extra.inc +372 -0
- package/runtime/xt_streams/readable.inc +415 -0
- package/runtime/xt_streams/transform.inc +195 -0
- package/runtime/xt_streams/writable.inc +542 -0
- package/runtime/xt_streams.c +30 -0
- package/runtime/xt_wasm/wasm.h +148 -0
- package/runtime/xt_wasm/wasm_api.c +357 -0
- package/runtime/xt_wasm/wasm_api.h +37 -0
- package/runtime/xt_wasm/wasm_bridge.c +30 -0
- package/runtime/xt_wasm/wasm_instance.c +591 -0
- package/runtime/xt_wasm/wasm_module.c +270 -0
- package/runtime/xt_wasm/wasm_values.c +177 -0
- package/runtime/xt_webassembly.c +15 -4
- package/scripts/fetch-vendored.ts +187 -20
- package/scripts/package-release.ts +3 -2
- package/src/cli/extensions.ts +11 -3
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/state.ts +7 -0
- package/src/codegen/generator/tables.ts +19 -1
- package/src/driver/bundler/README.md +55 -0
- package/src/driver/bundler/concatenate.ts +244 -0
- package/src/driver/bundler/graph.ts +9 -5
- package/src/driver/bundler/merge.ts +24 -215
- package/src/driver/bundler/{namespace-import.ts → namespace-object.ts} +5 -1
- package/src/driver/bundler/{reexport-fixup.ts → reexport-resolution.ts} +15 -5
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- package/src/driver/modules.ts +12 -5
- package/src/driver/paths.ts +8 -4
- package/src/driver/runtime-objects.ts +13 -1
- package/src/driver/version.ts +1 -1
- package/src/extensions/catalog.ts +5 -1
- package/src/extensions/gui/index.ts +0 -1
- package/src/extensions/link-feature.ts +8 -0
- package/src/extensions/node/stream-web/index.ts +59 -4
- package/src/extensions/node/worker_threads/index.ts +24 -11
- package/src/extensions/registry.ts +13 -2
- package/src/extensions/wasm-asset.ts +32 -0
- package/src/extensions/wasm.ts +74 -0
- package/src/extensions/webworker/index.ts +58 -0
- package/src/index.ts +1 -0
- package/vendor/wasm3/.pin +1 -0
- package/vendor/wasm3/LICENSE +21 -0
- package/vendor/wasm3/m3_api_libc.c +265 -0
- package/vendor/wasm3/m3_api_libc.h +19 -0
- package/vendor/wasm3/m3_api_meta_wasi.c +1107 -0
- package/vendor/wasm3/m3_api_tracer.c +173 -0
- package/vendor/wasm3/m3_api_tracer.h +19 -0
- package/vendor/wasm3/m3_api_uvwasi.c +1290 -0
- package/vendor/wasm3/m3_api_wasi.c +1207 -0
- package/vendor/wasm3/m3_api_wasi.h +74 -0
- package/vendor/wasm3/m3_api_wasi_host.h +137 -0
- package/vendor/wasm3/m3_api_wasi_posix.h +979 -0
- package/vendor/wasm3/m3_api_wasi_win32.h +1093 -0
- package/vendor/wasm3/m3_atomic.h +114 -0
- package/vendor/wasm3/m3_bind.c +174 -0
- package/vendor/wasm3/m3_bind.h +20 -0
- package/vendor/wasm3/m3_code.c +232 -0
- package/vendor/wasm3/m3_code.h +74 -0
- package/vendor/wasm3/m3_compile.c +6603 -0
- package/vendor/wasm3/m3_compile.h +354 -0
- package/vendor/wasm3/m3_config.h +448 -0
- package/vendor/wasm3/m3_config_platforms.h +345 -0
- package/vendor/wasm3/m3_core.c +1034 -0
- package/vendor/wasm3/m3_core.h +526 -0
- package/vendor/wasm3/m3_deterministic.c +65 -0
- package/vendor/wasm3/m3_deterministic.h +59 -0
- package/vendor/wasm3/m3_env.c +3146 -0
- package/vendor/wasm3/m3_env.h +748 -0
- package/vendor/wasm3/m3_exception.h +33 -0
- package/vendor/wasm3/m3_exec.c +8 -0
- package/vendor/wasm3/m3_exec.h +4110 -0
- package/vendor/wasm3/m3_exec_atomic.h +146 -0
- package/vendor/wasm3/m3_exec_defs.h +76 -0
- package/vendor/wasm3/m3_function.c +278 -0
- package/vendor/wasm3/m3_function.h +244 -0
- package/vendor/wasm3/m3_host.h +226 -0
- package/vendor/wasm3/m3_host_none.h +76 -0
- package/vendor/wasm3/m3_host_posix.h +543 -0
- package/vendor/wasm3/m3_host_win32.h +253 -0
- package/vendor/wasm3/m3_info.c +616 -0
- package/vendor/wasm3/m3_info.h +38 -0
- package/vendor/wasm3/m3_math_utils.h +560 -0
- package/vendor/wasm3/m3_module.c +431 -0
- package/vendor/wasm3/m3_parse.c +1549 -0
- package/vendor/wasm3/m3_snapshot.c +3825 -0
- package/vendor/wasm3/m3_validate.c +1770 -0
- package/vendor/wasm3/m3_validate.h +25 -0
- package/vendor/wasm3/m3_wasi.h +10 -0
- package/vendor/wasm3/m3_xxh64.c +211 -0
- package/vendor/wasm3/wasm3.h +684 -0
- package/vendor/wasm3/wasm3_defs.h +350 -0
- package/dist/src/driver/bundler/namespace-import.js.map +0 -1
- package/dist/src/driver/bundler/reexport-fixup.js.map +0 -1
- package/runtime/ext_node/worker_threads/worker_threads.c +0 -214
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { DiagnosticBag } from "../../src/diagnostics/diagnostic.js";
|
|
3
|
+
import { resolveLinkFeatures } from "../../src/driver/link-features.js";
|
|
4
|
+
import { collectUsage } from "../../src/driver/usage.js";
|
|
5
|
+
import { createDefaultRegistry, coreExtension } from "../../src/extensions/registry.js";
|
|
6
|
+
import { hasWasmUsage, wasmFeature } from "../../src/extensions/wasm.js";
|
|
7
|
+
import { loadWasmAsset } from "../../src/extensions/wasm-asset.js";
|
|
8
|
+
import { parse } from "../helpers.js";
|
|
9
|
+
describe("core extension wasm link feature", () => {
|
|
10
|
+
it("declares the wasm feature with the wasm3 and bridge sources", () => {
|
|
11
|
+
const features = coreExtension.linkFeatures?.() ?? [];
|
|
12
|
+
const wasm = features.find((feature) => feature.name === "wasm");
|
|
13
|
+
expect(wasm).toBe(wasmFeature);
|
|
14
|
+
expect(wasm?.required).toBe(true);
|
|
15
|
+
const sources = wasm?.runtimeSources?.() ?? [];
|
|
16
|
+
expect(sources.some((source) => /wasm3[\\/]m3_env\.c$/.test(source))).toBe(true);
|
|
17
|
+
expect(sources.some((source) => /xt_wasm[\\/]wasm_instance\.c$/.test(source))).toBe(true);
|
|
18
|
+
expect(sources.some((source) => /xt_wasm[\\/]wasm_bridge\.c$/.test(source))).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
describe("hasWasmUsage", () => {
|
|
22
|
+
const usage = (text) => collectUsage(parse(text).file);
|
|
23
|
+
it("detects direct and aliased uses of the namespace", () => {
|
|
24
|
+
expect(hasWasmUsage(usage("WebAssembly.instantiate(bytes);"))).toBe(true);
|
|
25
|
+
expect(hasWasmUsage(usage("const W = WebAssembly; W.validate(bytes);"))).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
it("does not fire for a program that never touches WebAssembly", () => {
|
|
28
|
+
expect(hasWasmUsage(usage("console.log('hello');"))).toBe(false);
|
|
29
|
+
expect(hasWasmUsage(usage("const wasm = 1; console.log(wasm);"))).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
it("is selected by resolveLinkFeatures only for a wasm-using program", () => {
|
|
32
|
+
const registry = createDefaultRegistry();
|
|
33
|
+
const bag = new DiagnosticBag();
|
|
34
|
+
const using = resolveLinkFeatures(registry, usage("WebAssembly.validate(bytes);"), {}, bag);
|
|
35
|
+
expect(using.map((feature) => feature.name)).toContain("wasm");
|
|
36
|
+
const unused = resolveLinkFeatures(registry, usage("console.log(1);"), {}, bag);
|
|
37
|
+
expect(unused.map((feature) => feature.name)).not.toContain("wasm");
|
|
38
|
+
expect(bag.diagnostics).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("wasm asset loader", () => {
|
|
42
|
+
it("is the core extension's binary .wasm loader", () => {
|
|
43
|
+
const loaders = coreExtension.assetLoaders?.() ?? {};
|
|
44
|
+
expect(loaders[".wasm"]).toBe(loadWasmAsset);
|
|
45
|
+
expect(loadWasmAsset.binary).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
it("embeds the bytes as a base64-decoded Uint8Array module", () => {
|
|
48
|
+
const loaded = loadWasmAsset("add.wasm", "\0asm\u0001\0\0\0");
|
|
49
|
+
expect(loaded.moduleSource).toContain('atob("AGFzbQEAAAA=")');
|
|
50
|
+
expect(loaded.moduleSource).toContain("export default __xt_wasm_bytes;");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=wasm.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm.test.js","sourceRoot":"","sources":["../../../tests/extensions/wasm.test.ts"],"names":[],"mappings":"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"}
|
package/doc/ai/cli.md
CHANGED
|
@@ -48,7 +48,7 @@ so restart it after installing a dependency.
|
|
|
48
48
|
--emit <kind> exe | obj | ir (default: exe)
|
|
49
49
|
-O0 .. -O3 Optimization level passed to clang (default: -O2)
|
|
50
50
|
--ext <names> Enable bundled extensions, comma separated (e.g. node,gui)
|
|
51
|
-
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,all)
|
|
51
|
+
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
52
52
|
--no-feature <n> Keep optional link features out even when detected
|
|
53
53
|
--ext-native <m> Register a C++/Rust extension from a JSON manifest
|
|
54
54
|
(comma separated for several)
|
package/doc/ai/contributing.md
CHANGED
|
@@ -8,7 +8,7 @@ get wrong.
|
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install
|
|
11
|
-
npm run vendor # fetch the pinned stb/NanoSVG/miniz/SQLite sources into vendor/
|
|
11
|
+
npm run vendor # fetch the pinned stb/NanoSVG/miniz/SQLite/wasm3 sources into vendor/
|
|
12
12
|
npm run typecheck # tsc --noEmit
|
|
13
13
|
npm run lint # eslint + the 600-line file budget
|
|
14
14
|
npm test # unit + end-to-end
|
|
@@ -16,8 +16,8 @@ npm test # unit + end-to-end
|
|
|
16
16
|
|
|
17
17
|
`vendor/` is not committed: `npm run vendor` fetches each package at an
|
|
18
18
|
immutable pinned revision and verifies its SHA-256 (`npm test` runs it through
|
|
19
|
-
`pretest`). Only the `gui` build and programs that use `storage`
|
|
20
|
-
`
|
|
19
|
+
`pretest`). Only the `gui` build and programs that use `storage`, `compression`
|
|
20
|
+
or `wasm` need the files.
|
|
21
21
|
|
|
22
22
|
Node.js ≥ 22 is required to run the compiler from source, and a **clang 16+**
|
|
23
23
|
toolchain is required for anything that links a binary (see
|
|
@@ -149,11 +149,18 @@ Verify locally:
|
|
|
149
149
|
|
|
150
150
|
```bash
|
|
151
151
|
npx tsx src/cli/main.ts emit src/cli/main.ts --ext node > scratch/ref.ll
|
|
152
|
-
npx tsx src/cli/main.ts build src/cli/main.ts --ext node --out scratch/self --force
|
|
152
|
+
npx tsx src/cli/main.ts build src/cli/main.ts --ext node --no-feature all --out scratch/self --force
|
|
153
153
|
./scratch/self/main emit src/cli/main.ts --ext node > scratch/gen2.ll # .exe on Windows
|
|
154
154
|
diff scratch/ref.ll scratch/gen2.ll
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
`--no-feature all` is part of the command: the compiler bundles the TypeScript
|
|
158
|
+
surface of every extension, so the usage scan sees names such as `localStorage`
|
|
159
|
+
and `TLSSocket` and would otherwise link SQLite/mbedTLS/miniz/wasm3 into the
|
|
160
|
+
compiler. It never uses those runtimes itself — it compiles them into the
|
|
161
|
+
programs it builds — so leaving them out also means the self-host job needs
|
|
162
|
+
neither `vendor/` nor the optional TLS/HTTP2 archives.
|
|
163
|
+
|
|
157
164
|
### 2. The runtime ABI and value model
|
|
158
165
|
|
|
159
166
|
- Every compiled function uses
|
package/doc/ai/extensions.md
CHANGED
|
@@ -44,12 +44,12 @@ resolve to the same implementation.
|
|
|
44
44
|
| `process` | `process.cwd()`, `argv`, `env`, …; namespace dispatch too |
|
|
45
45
|
| `buffer` | |
|
|
46
46
|
| `crypto` | |
|
|
47
|
-
| `stream`, `stream/promises` | |
|
|
47
|
+
| `stream`, `stream/promises`, `stream/web` | `stream/web` re-exports the core WHATWG Streams |
|
|
48
48
|
| `events` | |
|
|
49
49
|
| `net`, `dgram`, `http` | sockets and servers on the xbintsc event loop (see the async caveat below) |
|
|
50
50
|
| `tls`, `http2` | mbedTLS client/server and nghttp2 h2c/TLS+ALPN; optional link features built by `npm run tls` |
|
|
51
51
|
| `child_process` | |
|
|
52
|
-
| `worker_threads` | |
|
|
52
|
+
| `worker_threads` | process-isolated workers over a loopback control socket: two-way `postMessage`, `MessageChannel`, `terminate()`, structured clone |
|
|
53
53
|
| `util`, `querystring`, `url`, `assert`, `test`, `zlib` | |
|
|
54
54
|
|
|
55
55
|
Coverage per module (exact functions and options) is in
|
|
@@ -62,6 +62,29 @@ promise settled from a socket callback, a timer or an offloaded file/HTTP job ca
|
|
|
62
62
|
be awaited. `net.connect` itself is still blocking. See
|
|
63
63
|
[language-support.md](./language-support.md).
|
|
64
64
|
|
|
65
|
+
### `webworker` — Web Worker globals
|
|
66
|
+
|
|
67
|
+
Enable with `--ext webworker` for `Worker`, `MessageChannel`, `MessagePort`,
|
|
68
|
+
`self`, `isMainThread` and the bare `postMessage` global. A worker is a second
|
|
69
|
+
process running the same executable (xbintsc has no threads), so the script is
|
|
70
|
+
`import.meta.filename` and the program branches on `isMainThread`. Messages use
|
|
71
|
+
the same structured-clone codec as `worker_threads`; `worker.onmessage` and
|
|
72
|
+
`self.onmessage` receive `MessageEvent`-shaped objects, while a Node
|
|
73
|
+
`worker.on("message", ...)` listener on the same object receives the raw value.
|
|
74
|
+
See [../implemented/web-worker.md](../implemented/web-worker.md).
|
|
75
|
+
|
|
76
|
+
### `wasm` — WebAssembly (a core link feature)
|
|
77
|
+
|
|
78
|
+
No extension flag is needed: the core extension declares a **`wasm` link
|
|
79
|
+
feature**, and the usage scan selects it when the bundled program mentions
|
|
80
|
+
`WebAssembly`. It compiles the pinned wasm3 interpreter and the JS bridge, so a
|
|
81
|
+
program that never uses WebAssembly links neither. `--feature wasm` forces it
|
|
82
|
+
on and `--no-feature wasm` keeps it out (the namespace then reports "not
|
|
83
|
+
supported in this build"). The core extension also installs a binary `.wasm`
|
|
84
|
+
asset loader, so `import bytes from "./add.wasm"` embeds a module as a
|
|
85
|
+
`Uint8Array` for `WebAssembly.instantiate`. See
|
|
86
|
+
[../implemented/wasm.md](../implemented/wasm.md).
|
|
87
|
+
|
|
65
88
|
### `gui` — HTML/CSS window
|
|
66
89
|
|
|
67
90
|
Enable with `--ext gui` and import the `gui` module:
|
|
@@ -78,7 +78,8 @@ Canonical detail (always current, much longer):
|
|
|
78
78
|
| Sockets / servers (`http`, `net`, `dgram`) | ✅ | callbacks run on the event loop and can settle a promise you await (`net` / `http` examples included in the tests) |
|
|
79
79
|
| `fs/promises` | ✅ | file, directory and `FileHandle` operations run on the async I/O worker pool and settle on the reactor, so timers and sockets keep running while they wait |
|
|
80
80
|
| Global `fetch` | ✅ | HTTP/1.1 client whose connect/send/receive runs on the same worker pool; `await fetch(...)` yields and redirects are followed on the reactor. `http://` and `https://` (the optional `tls` link feature, mbedTLS; selected by an `https://` literal or `--feature tls`); the body is buffered before resolving |
|
|
81
|
-
|
|
|
81
|
+
| Web Streams | ✅ | `ReadableStream` / `WritableStream` / `TransformStream`, default readers/writers, controllers, queuing strategies, `tee`, `pipeTo`/`pipeThrough`, async iteration, `ReadableStream.from` and text encoder/decoder streams. `start`/`pull`/`write`/`flush` may return promises. No BYOB byte streams or compression streams; `node:stream/web` re-exports the same classes |
|
|
82
|
+
| Worker threads / Web Worker | ⚠️ | process-isolated workers: `node:worker_threads` and the `webworker` extension share a loopback control socket, two-way `postMessage` with structured clone, `MessageChannel`, `terminate()`. No real threads, no port transfer; the worker script is the current binary (`import.meta.filename` plus `isMainThread`) |
|
|
82
83
|
| `async` generators | ✅ | suspend at `await` and `yield`; every `.next()` returns a promise; `for await...of` supported |
|
|
83
84
|
|
|
84
85
|
## Types: structurally checked, then erased
|
|
@@ -129,6 +130,17 @@ Math`), and `Object.defineProperties` installs several descriptors at once.
|
|
|
129
130
|
|
|
130
131
|
See [Unimplemented: standard library](../unimplemented/stdlib.md) for the full list.
|
|
131
132
|
|
|
133
|
+
## WebAssembly
|
|
134
|
+
|
|
135
|
+
`WebAssembly.validate`, `compile`, `instantiate`, `Module`, `Instance`, exported
|
|
136
|
+
functions/memories and JS function imports are backed by the vendored **wasm3**
|
|
137
|
+
interpreter (the optional `wasm` link feature, selected automatically when the
|
|
138
|
+
program mentions `WebAssembly`; `--feature wasm` forces it). `i64` values are
|
|
139
|
+
BigInt, and `import bytes from "./x.wasm"` embeds a module as a `Uint8Array`.
|
|
140
|
+
Exported tables/globals and non-function imports are not wrapped yet; see
|
|
141
|
+
[Implemented: WebAssembly](../implemented/wasm.md) and
|
|
142
|
+
[Unimplemented: WebAssembly](../unimplemented/wasm.md).
|
|
143
|
+
|
|
132
144
|
## Modules
|
|
133
145
|
|
|
134
146
|
| Feature | Status | Notes |
|
|
@@ -152,7 +164,7 @@ See [Unimplemented: standard library](../unimplemented/stdlib.md) for the full l
|
|
|
152
164
|
| Number formatting and coercion | ✅ matches Node (`toFixed`, `toPrecision`, hex/octal/binary parsing) |
|
|
153
165
|
| `BigInt` | ✅ implemented |
|
|
154
166
|
| Garbage collection | ✅ non-moving mark-sweep; explicit roots plus a conservative C-stack scan; single-threaded and stop-the-world. WeakMap/WeakSet keys use an ephemeron fixed point and WeakRef targets are cleared when unreachable; a stale conservative stack word can delay clearing |
|
|
155
|
-
| Threads | 🚫
|
|
167
|
+
| Threads | 🚫 no OS threads; workers (`node:worker_threads` and the `webworker` extension) are separate processes with copied messages |
|
|
156
168
|
|
|
157
169
|
## Platform
|
|
158
170
|
|
package/doc/ai/zh-CN/cli.md
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
--emit <kind> exe | obj | ir(默认 exe)
|
|
42
42
|
-O0 .. -O3 传给 clang 的优化级别(默认 -O2)
|
|
43
43
|
--ext <names> 开启内置扩展,逗号分隔(如 node,gui)
|
|
44
|
-
--feature <names> 强制开启可选链接特性(media,gpu,images,shaping,webgl,all)
|
|
44
|
+
--feature <names> 强制开启可选链接特性(media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
45
45
|
--no-feature <n> 即使检测到也不链接该可选特性
|
|
46
46
|
--ext-native <m> 通过 JSON 清单注册 C++/Rust 扩展(多个用逗号分隔)
|
|
47
47
|
--config <path> 使用指定项目配置,不做自动发现
|
|
@@ -14,8 +14,8 @@ npm test # 单元测试 + 端到端测试
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
`vendor/` 不提交进仓库:`npm run vendor` 会按不可变的固定版本获取每个包并校验其
|
|
17
|
-
SHA-256(`npm test` 通过 `pretest` 自动运行)。只有 `gui` 构建以及使用
|
|
18
|
-
`compression` 的程序需要这些文件。
|
|
17
|
+
SHA-256(`npm test` 通过 `pretest` 自动运行)。只有 `gui` 构建以及使用
|
|
18
|
+
`storage`、`compression` 或 `wasm` 的程序需要这些文件。
|
|
19
19
|
|
|
20
20
|
从源码运行编译器需要 Node.js ≥ 22;任何会链接二进制的操作都需要 **clang 16+** 工具链
|
|
21
21
|
(见 [troubleshooting.md](./troubleshooting.md))。`xbintsc emit` 既不需要 clang 也不需要
|
|
@@ -125,11 +125,16 @@ gen2 --emit--> gen3.ll # 必须等于 ref.ll
|
|
|
125
125
|
|
|
126
126
|
```bash
|
|
127
127
|
npx tsx src/cli/main.ts emit src/cli/main.ts --ext node > scratch/ref.ll
|
|
128
|
-
npx tsx src/cli/main.ts build src/cli/main.ts --ext node --out scratch/self --force
|
|
128
|
+
npx tsx src/cli/main.ts build src/cli/main.ts --ext node --no-feature all --out scratch/self --force
|
|
129
129
|
./scratch/self/main emit src/cli/main.ts --ext node > scratch/gen2.ll # Windows 上是 .exe
|
|
130
130
|
diff scratch/ref.ll scratch/gen2.ll
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
`--no-feature all` 是命令的一部分:编译器会打包每个扩展的 TypeScript 接口,用法扫描因此
|
|
134
|
+
能看到 `localStorage`、`TLSSocket` 之类的名字,否则就会把 SQLite/mbedTLS/miniz/wasm3
|
|
135
|
+
链进编译器。编译器自身并不使用这些运行时——它们只会被编译进编译器产出的程序——所以不链接
|
|
136
|
+
它们也意味着 self-host 任务既不需要 `vendor/`,也不需要可选的 TLS/HTTP2 归档。
|
|
137
|
+
|
|
133
138
|
### 2. 运行时 ABI 与值模型
|
|
134
139
|
|
|
135
140
|
- 每个编译后的函数都用同一条 ABI:
|
|
@@ -42,12 +42,12 @@ xbintsc run app.ts --ext node
|
|
|
42
42
|
| `process` | `process.cwd()`、`argv`、`env` 等;也接入命名空间分发 |
|
|
43
43
|
| `buffer` | |
|
|
44
44
|
| `crypto` | |
|
|
45
|
-
| `stream`、`stream/promises` | |
|
|
45
|
+
| `stream`、`stream/promises`、`stream/web` | `stream/web` 重新导出核心运行时的 WHATWG Streams |
|
|
46
46
|
| `events` | |
|
|
47
47
|
| `net`、`dgram`、`http` | 跑在 xbintsc 事件循环上的套接字与服务端(注意下面的异步限制) |
|
|
48
48
|
| `tls`、`http2` | mbedTLS 客户端/服务端与 nghttp2 h2c/TLS+ALPN;由 `npm run tls` 构建的可选链接特性 |
|
|
49
49
|
| `child_process` | |
|
|
50
|
-
| `worker_threads` | |
|
|
50
|
+
| `worker_threads` | 基于回环控制 socket 的进程隔离 worker:双向 `postMessage`、`MessageChannel`、`terminate()`、结构化克隆 |
|
|
51
51
|
| `util`、`querystring`、`url`、`assert`、`test`、`zlib` | |
|
|
52
52
|
|
|
53
53
|
各模块的具体覆盖(确切函数与选项)见
|
|
@@ -59,6 +59,27 @@ xbintsc run app.ts --ext node
|
|
|
59
59
|
文件/HTTP job settle 的 Promise 都可以 await。`net.connect` 本身仍是阻塞的。见
|
|
60
60
|
[language-support.md](./language-support.md)。
|
|
61
61
|
|
|
62
|
+
### `webworker` —— Web Worker 全局对象
|
|
63
|
+
|
|
64
|
+
用 `--ext webworker` 获得 `Worker`、`MessageChannel`、`MessagePort`、`self`、
|
|
65
|
+
`isMainThread` 以及裸 `postMessage` 全局函数。worker 是运行同一可执行文件的第二个
|
|
66
|
+
进程(xbintsc 没有线程),所以脚本就是 `import.meta.filename`,程序用
|
|
67
|
+
`isMainThread` 分支。消息复用 `worker_threads` 的结构化克隆编解码器;
|
|
68
|
+
`worker.onmessage` 与 `self.onmessage` 收到 `MessageEvent` 形状的对象,而同一对象上
|
|
69
|
+
Node 的 `worker.on("message", ...)` 监听器收到原始值。见
|
|
70
|
+
[../../implemented/web-worker.md](../../implemented/web-worker.md)。
|
|
71
|
+
|
|
72
|
+
### `wasm` —— WebAssembly(核心链接特性)
|
|
73
|
+
|
|
74
|
+
不需要扩展开关:核心扩展声明了 **`wasm` 链接特性**,当打包程序提到
|
|
75
|
+
`WebAssembly` 时由用法扫描自动选择。它会编译固定版本的 wasm3 解释器和 JS
|
|
76
|
+
桥接层,因此从不使用 WebAssembly 的程序不会链入它们。`--feature wasm` 强制
|
|
77
|
+
启用,`--no-feature wasm` 保持不链入(此时命名空间报“not supported in this
|
|
78
|
+
build”)。核心扩展还安装了二进制 `.wasm` 资源加载器,因此
|
|
79
|
+
`import bytes from "./add.wasm"` 会把模块作为 `Uint8Array` 嵌入,可直接传给
|
|
80
|
+
`WebAssembly.instantiate`。见
|
|
81
|
+
[../../implemented/wasm.md](../../implemented/wasm.md)。
|
|
82
|
+
|
|
62
83
|
### `gui` —— HTML/CSS 窗口
|
|
63
84
|
|
|
64
85
|
用 `--ext gui` 开启并导入 `gui` 模块:
|
|
@@ -75,7 +75,8 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
75
75
|
| 套接字/服务端(`http`、`net`、`dgram`) | ✅ | 回调在事件循环上执行,可以 settle 你正在 await 的 Promise(测试含 `net`/`http` 示例) |
|
|
76
76
|
| `fs/promises` | ✅ | 文件、目录与 `FileHandle` 操作跑在异步 I/O 线程池上,并在 reactor 上 settle,等待期间定时器与套接字继续运行 |
|
|
77
77
|
| 全局 `fetch` | ✅ | HTTP/1.1 客户端,connect/send/receive 跑在同一线程池;`await fetch(...)` 会让出,重定向在 reactor 上处理。支持 `http://` 与 `https://`(可选 `tls` 链接特性,mbedTLS;由 `https://` 字面量或 `--feature tls` 选中),resolve 前缓冲整个响应体 |
|
|
78
|
-
|
|
|
78
|
+
| Web Streams | ✅ | `ReadableStream` / `WritableStream` / `TransformStream`、默认读写器、控制器、队列策略、`tee`、`pipeTo`/`pipeThrough`、异步迭代、`ReadableStream.from` 以及文本编解码流。`start`/`pull`/`write`/`flush` 可返回 Promise。不支持 BYOB 字节流与压缩流;`node:stream/web` 重新导出同一批类 |
|
|
79
|
+
| worker 线程 / Web Worker | ⚠️ | 进程隔离的 worker:`node:worker_threads` 与 `webworker` 扩展共用回环控制 socket,双向 `postMessage` 加结构化克隆、`MessageChannel`、`terminate()`。没有真正的线程,不支持端口转移;worker 脚本就是当前二进制(`import.meta.filename` 加 `isMainThread`) |
|
|
79
80
|
| `async` 生成器 | ✅ | 可在 `await` 与 `yield` 处挂起;每次 `.next()` 返回 Promise;支持 `for await...of` |
|
|
80
81
|
|
|
81
82
|
## 类型:结构化检查后擦除
|
|
@@ -124,6 +125,16 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
124
125
|
|
|
125
126
|
完整列表见[未实现:标准库](../../unimplemented/stdlib.md)。
|
|
126
127
|
|
|
128
|
+
## WebAssembly
|
|
129
|
+
|
|
130
|
+
`WebAssembly.validate`、`compile`、`instantiate`、`Module`、`Instance`、导出的
|
|
131
|
+
函数/内存以及 JS 函数导入都由 vendored **wasm3** 解释器支撑(可选的 `wasm`
|
|
132
|
+
链接特性,程序提到 `WebAssembly` 时自动选择;`--feature wasm` 可强制启用)。
|
|
133
|
+
`i64` 值使用 BigInt,`import bytes from "./x.wasm"` 会把模块作为
|
|
134
|
+
`Uint8Array` 嵌入。导出的 table/global 和非函数导入尚未包装;见
|
|
135
|
+
[已实现:WebAssembly](../../implemented/wasm.md) 与
|
|
136
|
+
[未实现:WebAssembly](../../unimplemented/wasm.md)。
|
|
137
|
+
|
|
127
138
|
## 模块
|
|
128
139
|
|
|
129
140
|
| 特性 | 状态 | 说明 |
|
|
@@ -147,7 +158,7 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
147
158
|
| 数字格式化与强转 | ✅ 与 Node 一致(`toFixed`、`toPrecision`、十六/八/二进制解析) |
|
|
148
159
|
| `BigInt` | ✅ 已实现 |
|
|
149
160
|
| 垃圾回收 | ✅ 非移动标记清扫;显式根 + C 栈保守扫描;单线程、stop-the-world。`WeakMap`/`WeakSet` 键使用 ephemeron 不动点,`WeakRef` 目标不可达时清空;保守栈上的残留字可能延迟清空 |
|
|
150
|
-
| 线程 | 🚫
|
|
161
|
+
| 线程 | 🚫 没有操作系统线程;worker(`node:worker_threads` 与 `webworker` 扩展)是独立进程,消息靠复制 |
|
|
151
162
|
|
|
152
163
|
## 平台
|
|
153
164
|
|
package/doc/gui/api.md
CHANGED
|
@@ -114,7 +114,7 @@ requestAnimationFrame(frame);
|
|
|
114
114
|
| `HTMLCanvasElement`, `HTMLImageElement`, `WebGLRenderingContext`, `WebGL2RenderingContext`, `WebGLBuffer`/`WebGLTexture`/`WebGLShader`/`WebGLProgram`/`WebGLFramebuffer`/`WebGLRenderbuffer`/`WebGLUniformLocation`/`WebGLActiveInfo`/`WebGLVertexArrayObject`/`WebGLSampler`/`WebGLQuery`/`WebGLSync`/`WebGLTransformFeedback` | real constructor values. `canvas.getContext("webgl")` and `getContext("webgl2")` return GPU contexts (see [WebGL](./webgl.md)). |
|
|
115
115
|
| `ImageBitmap`, `createImageBitmap(source)` | immutable bitmaps backed by decoded pixels (`<img>`, `<canvas>`, `<video>` frames, `OffscreenCanvas` and `ImageData` shapes); the promise resolves immediately and `texImage2D` accepts the result |
|
|
116
116
|
| `OffscreenCanvas` | a real 2D offscreen bitmap with `getContext("2d")`, `width`/`height`, `transferToImageBitmap()` and `convertToBlob()`; `canvas.transferControlToOffscreen()` hands an element's bitmap over (see [Canvas](./canvas.md)). There is no offscreen WebGL context. |
|
|
117
|
-
| `ImageData`, `XRWebGL*`, `Request`, `Headers`, `Response`, `
|
|
117
|
+
| `ImageData`, `XRWebGL*`, `Request`, `Headers`, `Response`, `DOMParser` | `typeof` probes answer `"undefined"` (no XR, DOM parser or streaming backend), which lets a page take its "unsupported" branch instead of calling a no-op stub. `fetch` still works and resolves with a response-shaped object, but there is no `Response` constructor and `response.arrayBuffer()` currently returns a byte array rather than an `ArrayBuffer`; `ReadableStream` and the other Web Streams classes come from the core runtime. Three.js pages use its real renderer on this backend (see [Known issues](./known-issues.md)). |
|
|
118
118
|
| `requestAnimationFrame` / `cancelAnimationFrame` | queued on the window's frame list; see [Runtime integration](./runtime.md) |
|
|
119
119
|
| `alert` / `confirm` / `prompt`, `matchMedia`, `getComputedStyle`, `escape` | host implementations. `matchMedia` returns a **live** list (cached per query): `matches` is re-evaluated on resize and `change` listeners fire when it flips. `confirm`/`prompt` use a native dialog only with `XT_GUI_DIALOGS=1`; otherwise they report the message on stderr and return the documented default (Annex B `escape` encodes per UTF-16 code unit, matching `decodeURIComponent(escape(bytes))`) |
|
|
120
120
|
|
package/doc/implemented/cli.md
CHANGED
|
@@ -29,7 +29,7 @@ default; `--no-check` skips it (and is part of the cache key). See
|
|
|
29
29
|
--emit <kind> exe | obj | ir (default: exe)
|
|
30
30
|
-O0..-O3 Optimization level (default: -O2)
|
|
31
31
|
--ext <names> Comma separated extensions (e.g. node)
|
|
32
|
-
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,all)
|
|
32
|
+
--feature <names> Force optional link features on (media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
33
33
|
--no-feature <n> Keep optional link features out even when detected
|
|
34
34
|
--ext-native <m> Register a C++/Rust extension from a JSON manifest
|
|
35
35
|
--config <path> Use a project config (default: xbintsc.config.json)
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/extensions.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/extensions/registry.ts`, `src/extensions/node/`, `src/extensions/link-feature.ts`, `src/driver/usage.ts`, `src/driver/link-features.ts`
|
|
5
|
+
Location: `src/extensions/registry.ts`, `src/extensions/node/`, `src/extensions/webworker/`, `src/extensions/wasm.ts`, `src/extensions/link-feature.ts`, `runtime/xt_wasm/`, `src/driver/usage.ts`, `src/driver/link-features.ts`
|
|
6
6
|
|
|
7
7
|
- An extension is a plain object: `runtimeSources()` (extra C sources), `linkerFlags()` (extra link flags), `builtins()` (global identifier → runtime symbol, uniform `(argc, argv)` ABI), `modules()` (import specifier → named exports / namespace) and `linkFeatures()` (optional heavy capabilities).
|
|
8
8
|
- `ExtensionRegistry`: register / unregister / lookup / aggregate builtins, modules, runtime sources, link flags and link features.
|
|
9
9
|
- **Optional link features** (`media`, `gpu`, `images`, `shaping`, `webgl`):
|
|
10
|
-
- A feature declares `runtimeSources()` (a C bridge compiled only when active), `nativeObjects()` (archives linked only when active), `linkerFlags()`, optional `requires` (another feature it depends on) and `used(usage)`.
|
|
10
|
+
- A feature declares `runtimeSources()` (a C bridge compiled only when active), `nativeObjects()` (archives linked only when active), `linkerFlags()`, optional `requires` (another feature it depends on), optional `required` (missing sources are a build error rather than a warning), and `used(usage)`.
|
|
11
11
|
- The driver builds `ProgramUsage` from the bundled AST (`collectUsage` in `src/driver/usage.ts`): string literals (including imported HTML and inlined CSS), identifiers/property names, `getContext(...)` kinds, and whether markup can be built at run time. Simple `const` aliases are resolved; unresolved markup makes the program conservative.
|
|
12
|
-
- `resolveLinkFeatures` applies `--feature` / `--no-feature` (and `all`), expands `requires`, reports an unavailable auto-detected feature as a warning and a forced one as an error, and returns the bridges/archives/flags to link.
|
|
12
|
+
- `resolveLinkFeatures` applies `--feature` / `--no-feature` (and `all`), expands `requires`, reports an unavailable auto-detected optional feature as a warning and a required or forced one as an error, and returns the bridges/archives/flags to link.
|
|
13
13
|
- The bridge is the strong reference: its constructor installs the feature's dispatch table and its references force the linker to extract the implementation. With no bridge, the table stays null and the implementation members are never linked.
|
|
14
|
-
- Current clients: `media` (FFmpeg, `runtime/xt_media/media_bridge.c` + `media.a`), `gpu` (glslang/SPIRV-Cross, `runtime/ext_gui/gpu_bridge.c` + `gpu_feature.cpp` inside `gui.a`), `images` (stb_image/NanoSVG, `runtime/ext_gui/image_bridge.c` + `image_feature.cpp`), `shaping` (HarfBuzz/FreeType, `runtime/ext_gui/text_bridge.c` + `text_hb.cpp`), `webgl` (context/DOM bindings, `runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`, requiring `gpu`),
|
|
14
|
+
- Current clients: `media` (FFmpeg, `runtime/xt_media/media_bridge.c` + `media.a`), `gpu` (glslang/SPIRV-Cross, `runtime/ext_gui/gpu_bridge.c` + `gpu_feature.cpp` inside `gui.a`), `images` (stb_image/NanoSVG, `runtime/ext_gui/image_bridge.c` + `image_feature.cpp`), `shaping` (HarfBuzz/FreeType, `runtime/ext_gui/text_bridge.c` + `text_hb.cpp`), `webgl` (context/DOM bindings, `runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`, requiring `gpu`), `storage` (SQLite-backed Web Storage/IndexedDB, whose implementation lives entirely in the feature's `runtimeSources` — `runtime/xt_storage/*.c` — because the globals themselves are the strong references), and `wasm` (wasm3 behind the `WebAssembly` namespace; `runtime/xt_wasm/wasm_bridge.c` installs the dispatch table, and `vendor/wasm3` supplies the interpreter).
|
|
15
15
|
- TLS/HTTP2 clients: `tls` (the mbedTLS transport in `runtime/xt_tls/tls_core.c` plus the `tls` archive, used by `fetch` and `node:tls`), `node-tls` (the `TLSSocket`/server surface, requiring `tls`) and `http2` (the nghttp2 backend in `runtime/ext_node/http2/http2_backend.c`, requiring `tls` and `node-tls`; `npm run tls` builds both archives).
|
|
16
|
-
- The built-in core extension `core`: exposes `print` (mapped to `xt_println`), always registered.
|
|
16
|
+
- The built-in core extension `core`: exposes `print` (mapped to `xt_println`), the Web Storage globals, the `storage`/`tls`/`wasm` link features and the binary `.wasm` asset loader; always registered.
|
|
17
17
|
- The Node extension `node`:
|
|
18
18
|
- Modular organisation: `src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
19
19
|
- Exposes importable modules (`fs`, `fs/promises`, `path`, `os`, `process`, ...) under both bare and `node:`-prefixed specifiers; `import { readFileSync } from "fs"` resolves to `xt_node_read_text_file`, and `path`/`os`/`process` map exports onto the namespace dispatchers.
|
|
20
|
+
- The Web Worker extension `webworker`: browser globals `Worker`, `MessageChannel`, `MessagePort`, `self`, `isMainThread` and bare `postMessage`. A worker is a second process running the same executable (there are no threads), so `new Worker(import.meta.filename)` plus `isMainThread` is the entry pattern. The transport (`runtime/worker/`) is shared with `node:worker_threads`; see [Web Worker](./web-worker.md).
|
|
20
21
|
- Adding a new module only requires a new directory plus a C implementation; the core compiler never changes.
|
|
21
22
|
- Native C++/Rust extensions (`src/extensions/native.ts`, `--ext-native`):
|
|
22
23
|
- `nativeObjects()` links pre-built objects/static archives that expose `extern "C"` symbols with the `(argc, argv)` ABI; a JSON manifest maps them onto builtins/modules (`linkerFlags` / `linkerFlagsByPlatform` cover C++/Rust runtimes).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# `stream/web`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/stream-web.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/stream-web/index.ts`,
|
|
6
|
+
`runtime/ext_node/stream_web/stream_web.c`.
|
|
7
|
+
|
|
8
|
+
Node's `stream/web` subpath re-exports the WHATWG stream classes. The
|
|
9
|
+
implementations live in the core runtime (see [Web Streams](../streams.md)), so
|
|
10
|
+
a compiled program can use the same classes as browser globals or import them by
|
|
11
|
+
name:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { ReadableStream, TransformStream } from "node:stream/web";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
| Export | Notes |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `ReadableStream`, `ReadableStreamDefaultReader`, `ReadableStreamDefaultController` | full implementation |
|
|
20
|
+
| `WritableStream`, `WritableStreamDefaultWriter`, `WritableStreamDefaultController` | full implementation |
|
|
21
|
+
| `TransformStream`, `TransformStreamDefaultController` | full implementation |
|
|
22
|
+
| `TextEncoderStream`, `TextDecoderStream` | UTF-8 text transform streams |
|
|
23
|
+
| `CountQueuingStrategy`, `ByteLengthQueuingStrategy` | queuing strategies |
|
|
24
|
+
| `ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest` | exported; constructors throw (no byte streams) |
|
|
25
|
+
| `CompressionStream`, `DecompressionStream` | exported; constructors throw (no compression streams) |
|
|
26
|
+
| `ReadableStreamTee` | `undefined`, so undici's `ReadableStreamTee?.(...) ?? body.stream.tee()` falls back to the body's own `tee` |
|
|
27
|
+
|
|
28
|
+
The constructors are first-class values: `const RS = ReadableStream`,
|
|
29
|
+
`new RS(...)`, `stream instanceof ReadableStream` and `ReadableStream.from(...)`
|
|
30
|
+
all work. See [Web Streams](../streams.md) for the async model, the supported
|
|
31
|
+
methods and the remaining limits (BYOB and compression streams).
|
|
@@ -2,9 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/worker-threads.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/extensions/node/worker_threads/index.ts`, `runtime/
|
|
5
|
+
Location: `src/extensions/node/worker_threads/index.ts`, `runtime/worker/`
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
xbintsc has no threads (the value model, the collector and the event loop are
|
|
8
|
+
single-threaded), so a worker is a **second process** running the same
|
|
9
|
+
executable. The worker entry is therefore the current program: pass
|
|
10
|
+
`import.meta.filename` and branch on `isMainThread`.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Worker, isMainThread, parentPort, workerData } from "node:worker_threads";
|
|
14
|
+
|
|
15
|
+
if (isMainThread) {
|
|
16
|
+
const worker = new Worker(import.meta.filename, { workerData: { n: 2 } });
|
|
17
|
+
worker.on("message", (reply) => {
|
|
18
|
+
console.log(reply.total);
|
|
19
|
+
worker.terminate();
|
|
20
|
+
});
|
|
21
|
+
worker.postMessage({ values: [1, 2, 3] });
|
|
22
|
+
} else {
|
|
23
|
+
parentPort.on("message", (message) => {
|
|
24
|
+
const values: number[] = message.values;
|
|
25
|
+
parentPort.postMessage({ total: values[0] + values[1] + values[2] });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Surface
|
|
31
|
+
|
|
32
|
+
- `Worker(script, options?)` — `options.workerData` (structured-cloned),
|
|
33
|
+
`options.name`; `script` must name this executable or the constructor throws
|
|
34
|
+
an actionable error. `options.env`, `argv`, `execArgv`, `resourceLimits`,
|
|
35
|
+
`stdin`/`stdout`/`stderr` are accepted but ignored.
|
|
36
|
+
- `worker.postMessage(value, transferList?)` — the value is structured-cloned;
|
|
37
|
+
the transfer list is accepted but copies. Sending a function, symbol,
|
|
38
|
+
promise, `WeakMap`/`WeakSet`/`WeakRef`, generator or `MessagePort` throws
|
|
39
|
+
`... could not be cloned.`
|
|
40
|
+
- `worker.on("message", ...)` / `worker.once` / `off` / `removeAllListeners` —
|
|
41
|
+
`message` delivers the raw value.
|
|
42
|
+
- `worker.on("online" | "error" | "exit", ...)` — `online` after the control
|
|
43
|
+
channel is accepted, `exit` with the process exit code (a terminated worker
|
|
44
|
+
reports `1`). `messageerror` is emitted when a frame cannot be decoded.
|
|
45
|
+
- `worker.terminate(): Promise<number>` — kills the process, resolves with the
|
|
46
|
+
exit code; `ref()`/`unref()` are accepted as no-ops.
|
|
47
|
+
- `worker.threadId` — a per-process worker id.
|
|
48
|
+
- `isMainThread`, `workerData` (null on the main thread), `parentPort` (null on
|
|
49
|
+
the main thread) with `postMessage`, `on("message")`, `close()`, `start()`,
|
|
50
|
+
`ref()`/`unref()`.
|
|
51
|
+
- `new MessageChannel()` / `MessagePort` — a local channel: `port1.postMessage`
|
|
52
|
+
is delivered to `port2` on a zero-delay timer, and either port accepts
|
|
53
|
+
`on("message")` (raw value) or `onmessage` / `addEventListener` (a
|
|
54
|
+
`MessageEvent`). `receiveMessageOnPort` exists but a local port already
|
|
55
|
+
delivers on a timer, so it returns `undefined`.
|
|
56
|
+
- `markAsUncloneable(value)` — accepted; the codec already rejects streams and
|
|
57
|
+
host handles.
|
|
58
|
+
|
|
59
|
+
## Message data
|
|
60
|
+
|
|
61
|
+
Messages and `workerData` use the structured-clone codec in
|
|
62
|
+
`runtime/worker/worker_codec.c`: `undefined`, booleans, numbers (including
|
|
63
|
+
`NaN`, `±Infinity`, `-0`), strings, `BigInt`, arrays, plain objects, `Map`,
|
|
64
|
+
`Set`, `Date`, `RegExp`, `ArrayBuffer`, typed arrays, shared references and
|
|
65
|
+
cycles. Classes arrive as plain objects; functions and symbols are rejected.
|
|
66
|
+
|
|
67
|
+
## Lifetime and errors
|
|
68
|
+
|
|
69
|
+
The parent stays alive while a worker runs. A worker stays alive while it has a
|
|
70
|
+
`message` listener (or other event-loop work); a worker that posts once and
|
|
71
|
+
returns exits on its own, so `worker.on("message")` plus `terminate()` is the
|
|
72
|
+
usual pattern for a long-lived worker. A worker that returns closes its control
|
|
73
|
+
channel before the process ends, so a message posted just before exit is still
|
|
74
|
+
delivered. An uncaught exception in the worker is printed by that process on
|
|
75
|
+
stderr and ends it with a non-zero code; the parent observes `exit`, not
|
|
76
|
+
`error`. Closing the parent's last handle ends the worker through the socket
|
|
77
|
+
EOF.
|
|
78
|
+
|
|
79
|
+
## Platform notes
|
|
80
|
+
|
|
81
|
+
The transport is a loopback TCP socket (Windows `select(2)` only accepts
|
|
82
|
+
sockets, so pipes would need a second implementation). POSIX uses
|
|
83
|
+
`fork`/`execvp` and `waitpid(WNOHANG)`; Windows uses `_spawnvp(_P_NOWAIT)` and
|
|
84
|
+
`WaitForSingleObject` on the process handle. The port and a random handshake
|
|
85
|
+
token travel through the environment, which caps `workerData` at 32 KiB on
|
|
86
|
+
Windows.
|
|
87
|
+
|
|
88
|
+
## Limitations
|
|
89
|
+
|
|
90
|
+
`MessagePort` transfer between processes, `BroadcastChannel`,
|
|
91
|
+
`setEnvironmentData`/`getEnvironmentData`, `SHARE_ENV` and real thread
|
|
92
|
+
parallelism are not implemented — see
|
|
93
|
+
[Node extension: unimplemented](../../unimplemented/node.md).
|
package/doc/implemented/node.md
CHANGED
|
@@ -26,6 +26,7 @@ work on another. Missing or different behaviour is recorded under
|
|
|
26
26
|
| `buffer` | [buffer](./node/buffer.md) | `Buffer` represented as a plain object |
|
|
27
27
|
| `stream` | [stream](./node/stream.md) | `Readable` / `Writable` / `Duplex` / `Transform` / `PassThrough` |
|
|
28
28
|
| `stream/promises` | [stream/promises](./node/stream-promises.md) | `pipeline` only |
|
|
29
|
+
| `stream/web` | [stream/web](./node/stream-web.md) | WHATWG streams, re-exported from the core runtime |
|
|
29
30
|
| `net` | [net](./node/net.md) | TCP server and client |
|
|
30
31
|
| `dgram` | [dgram](./node/dgram.md) | UDP sockets |
|
|
31
32
|
| `http` | [http](./node/http.md) | server and client, `Connection: close` |
|
|
@@ -41,7 +42,7 @@ work on another. Missing or different behaviour is recorded under
|
|
|
41
42
|
| `crypto` | [crypto](./node/crypto.md) | `createHash` (SHA-1 / SHA-256) |
|
|
42
43
|
| `url` | [url](./node/url.md) | `pathToFileURL` / `fileURLToPath` |
|
|
43
44
|
| `zlib` | [zlib](./node/zlib.md) | `createGzip` only |
|
|
44
|
-
| `worker_threads` | [worker_threads](./node/worker-threads.md) |
|
|
45
|
+
| `worker_threads` | [worker_threads](./node/worker-threads.md) | process-isolated workers: two-way messaging, `MessageChannel`, structured clone |
|
|
45
46
|
|
|
46
47
|
Additional small modules are provided with their core surface: `timers`
|
|
47
48
|
(`setTimeout`/`setInterval`/`setImmediate`), `timers/promises`, `console`
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Web Streams
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/streams.md)
|
|
4
|
+
|
|
5
|
+
Location: `runtime/xt_streams.c` and `runtime/xt_streams/`. The classes are core
|
|
6
|
+
runtime globals, so they are available without any extension flag; Node's
|
|
7
|
+
`stream/web` module re-exports the same constructors (see
|
|
8
|
+
[stream/web](./node/stream-web.md)).
|
|
9
|
+
|
|
10
|
+
## Classes
|
|
11
|
+
|
|
12
|
+
| Class | Notes |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `ReadableStream` | underlying source `start` / `pull` / `cancel`; `getReader`, `cancel`, `tee`, `pipeTo`, `pipeThrough`, `values`, `[Symbol.asyncIterator]`, `locked` |
|
|
15
|
+
| `ReadableStreamDefaultReader` | `read`, `cancel`, `releaseLock`, `closed` |
|
|
16
|
+
| `ReadableStreamDefaultController` | `enqueue`, `close`, `error`, `desiredSize` |
|
|
17
|
+
| `WritableStream` | underlying sink `start` / `write` / `close` / `abort`; `getWriter`, `close`, `abort`, `locked` |
|
|
18
|
+
| `WritableStreamDefaultWriter` | `write`, `close`, `abort`, `releaseLock`, `closed`, `ready`, `desiredSize` |
|
|
19
|
+
| `WritableStreamDefaultController` | `error` |
|
|
20
|
+
| `TransformStream` | transformer `start` / `transform` / `flush`; `readable`, `writable` |
|
|
21
|
+
| `TransformStreamDefaultController` | `enqueue`, `error`, `terminate`, `desiredSize` |
|
|
22
|
+
| `TextEncoderStream` | string chunks in, UTF-8 `Uint8Array` chunks out |
|
|
23
|
+
| `TextDecoderStream` | `Uint8Array` chunks in, string chunks out |
|
|
24
|
+
| `CountQueuingStrategy` / `ByteLengthQueuingStrategy` | `highWaterMark` and `size(chunk)` |
|
|
25
|
+
|
|
26
|
+
`ReadableStream.from(iterable)` builds a readable stream from an array, string
|
|
27
|
+
or any synchronous or asynchronous iterable. The constructors are first-class
|
|
28
|
+
values, so
|
|
29
|
+
`const RS = ReadableStream; new RS(...)`, `ReadableStream.from(...)` and
|
|
30
|
+
`stream instanceof ReadableStream` all work.
|
|
31
|
+
|
|
32
|
+
### Example
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
async function main(): Promise<void> {
|
|
36
|
+
const transform = new TransformStream<string, string>({
|
|
37
|
+
transform(chunk, controller) {
|
|
38
|
+
controller.enqueue(chunk.toUpperCase());
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const writer = transform.writable.getWriter();
|
|
42
|
+
const reader = transform.readable.getReader();
|
|
43
|
+
|
|
44
|
+
const first = reader.read();
|
|
45
|
+
await writer.write("hello");
|
|
46
|
+
console.log(JSON.stringify(await first)); // {"value":"HELLO","done":false}
|
|
47
|
+
const done = reader.read();
|
|
48
|
+
await writer.close();
|
|
49
|
+
console.log(JSON.stringify(await done)); // {"done":true}
|
|
50
|
+
}
|
|
51
|
+
main();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Async model
|
|
55
|
+
|
|
56
|
+
`start`, `pull`, `write`, `close`, `abort`, `cancel`, `transform` and `flush`
|
|
57
|
+
may return a promise. The stream machinery chains it through the runtime promise
|
|
58
|
+
queue, so a `pull` that waits for a timer or socket keeps the event loop alive
|
|
59
|
+
and a slow sink serialises writes without blocking it. Reader and writer methods
|
|
60
|
+
return promises; `reader.read()` on an empty stream stays pending until `pull`
|
|
61
|
+
(or another producer) enqueues a chunk.
|
|
62
|
+
|
|
63
|
+
Backpressure is honoured through `desiredSize` and `writer.ready`: `pull` is
|
|
64
|
+
called while a reader has demand and the readable queue is below its
|
|
65
|
+
high-water mark, and `writer.ready` stays pending while the writable queue is
|
|
66
|
+
full.
|
|
67
|
+
|
|
68
|
+
## Limits
|
|
69
|
+
|
|
70
|
+
- **No byte streams / BYOB.** `getReader({ mode: "byob" })` throws
|
|
71
|
+
`TypeError`; `ReadableStreamBYOBReader` and `ReadableStreamBYOBRequest` exist
|
|
72
|
+
as names but their constructors throw.
|
|
73
|
+
- **No compression streams.** `CompressionStream` and `DecompressionStream` are
|
|
74
|
+
exported by `node:stream/web` but their constructors throw a clear error.
|
|
75
|
+
- `TextDecoderStream` decodes each chunk independently, so a UTF-8 sequence
|
|
76
|
+
split across two chunks is not reassembled.
|
|
77
|
+
- `tee` buffers into the two branches without independent backpressure; for an
|
|
78
|
+
unbounded source the slower branch accumulates chunks.
|
|
79
|
+
- `pipeTo` ignores `preventClose` / `preventAbort` / `signal` options.
|
|
80
|
+
- The classes are ordinary runtime objects; the Web IDL brand checks, transfer
|
|
81
|
+
(`postMessage`) and `ReadableStream` ownership in `fetch` responses are not
|
|
82
|
+
implemented.
|