xbintsc 0.6.24 → 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/graph.js +9 -5
- package/dist/src/driver/bundler/graph.js.map +1 -1
- 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/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/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/graph.ts +9 -5
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- 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/runtime/ext_node/worker_threads/worker_threads.c +0 -214
|
@@ -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.
|
package/doc/implemented/wasm.md
CHANGED
|
@@ -2,21 +2,83 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/wasm.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/
|
|
6
|
-
`runtime/xt_webassembly.c` (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
Location: `src/extensions/wasm.ts` (link feature), `runtime/xt_wasm/` (bridge and
|
|
6
|
+
API), `runtime/xt_webassembly.c` (core namespace stub), `vendor/wasm3/`
|
|
7
|
+
(interpreter, fetched by `npm run vendor`).
|
|
8
|
+
|
|
9
|
+
## The `wasm` link feature
|
|
10
|
+
|
|
11
|
+
`WebAssembly` is a first-class namespace object, like `Math` or `crypto`, so
|
|
12
|
+
`const W = WebAssembly` and `typeof WebAssembly` both work. The interpreter
|
|
13
|
+
behind it is not linked into every program: a usage scan selects the **`wasm`
|
|
14
|
+
link feature** when the bundled source mentions `WebAssembly`, and only then
|
|
15
|
+
compiles the pinned wasm3 sources plus the bridge. `--feature wasm` forces it on
|
|
16
|
+
(a program that reaches `globalThis["WebAssembly"]` through a string needs
|
|
17
|
+
that), and `--no-feature wasm` keeps it out, in which case the namespace members
|
|
18
|
+
throw `WebAssembly is not supported in this build` at run time.
|
|
19
|
+
|
|
20
|
+
The feature is *required*: if `vendor/wasm3` is missing, the build fails with the
|
|
21
|
+
`npm run vendor` instruction instead of warning and producing a binary with an
|
|
22
|
+
unresolved symbol.
|
|
23
|
+
|
|
24
|
+
## Supported API
|
|
25
|
+
|
|
26
|
+
| Surface | Behaviour |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `WebAssembly.validate(bytes)` | parses/validates a module; invalid bytecode returns `false` |
|
|
29
|
+
| `WebAssembly.compile(bytes)` | `Promise<Module>`; invalid bytecode rejects with `CompileError` |
|
|
30
|
+
| `WebAssembly.instantiate(bytes, imports?)` | `Promise<{ module, instance }>` |
|
|
31
|
+
| `WebAssembly.instantiate(module, imports?)` | `Promise<Instance>` |
|
|
32
|
+
| `new WebAssembly.Module(bytes)` | synchronous compile; throws `CompileError` |
|
|
33
|
+
| `new WebAssembly.Instance(module, imports?)` | synchronous instantiation; throws `LinkError` |
|
|
34
|
+
| `WebAssembly.Module.exports(module)` / `.imports(module)` | descriptor arrays (`{ name, kind }` / `{ module, name, kind }`) |
|
|
35
|
+
| `WebAssembly.Module.customSections(module, name)` | returns `[]` (custom sections are not exposed yet) |
|
|
36
|
+
| `new WebAssembly.Memory({ initial, maximum? })` | a standalone page-backed `ArrayBuffer` with `buffer` and `grow()` |
|
|
37
|
+
| `instance.exports.<function>` | callable from JS; `i32`/`f32`/`f64` are numbers, `i64` is a BigInt |
|
|
38
|
+
| `instance.exports.<memory>` | `.buffer` is an `ArrayBuffer` snapshot and `.grow(pages)` grows the wasm memory |
|
|
39
|
+
| JS function imports | called from wasm with their declared numeric types; a thrown JS exception propagates back to the wasm caller |
|
|
40
|
+
| `CompileError` / `LinkError` / `RuntimeError` | real `Error` subclasses; `instanceof WebAssembly.CompileError` and `instanceof Error` work |
|
|
41
|
+
|
|
42
|
+
Both `WebAssembly.compile` and `instantiate` settle through the normal promise
|
|
43
|
+
queue, so `await` works and timers/sockets continue to run while they are
|
|
44
|
+
pending.
|
|
45
|
+
|
|
46
|
+
### Memory is synchronised around calls
|
|
47
|
+
|
|
48
|
+
The runtime's `ArrayBuffer` is a JavaScript-heap byte array, not a live alias of
|
|
49
|
+
wasm3's linear memory. `instance.exports.<memory>.buffer` copies the wasm bytes
|
|
50
|
+
out, and every exported function call copies the JS buffer into wasm memory
|
|
51
|
+
before the call and back out afterwards. Reads and writes made through a typed
|
|
52
|
+
array are therefore visible to the next wasm call (and vice versa), but a view
|
|
53
|
+
is not a zero-copy window: a write is observed on the next call or `.buffer`
|
|
54
|
+
read, not instantly.
|
|
55
|
+
|
|
56
|
+
### `.wasm` imports
|
|
57
|
+
|
|
58
|
+
The core extension installs a binary asset loader, so a module can import a wasm
|
|
59
|
+
file directly:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import bytes from "./add.wasm";
|
|
63
|
+
|
|
64
|
+
const { instance } = await WebAssembly.instantiate(bytes, {});
|
|
65
|
+
console.log(instance.exports.add(2, 3));
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The bytes are embedded in the executable (base64 in the generated module), so
|
|
69
|
+
the built program needs no `.wasm` file at run time.
|
|
70
|
+
|
|
71
|
+
## Limits
|
|
72
|
+
|
|
73
|
+
- Only **function** imports are bridged. A module that imports a memory, table or
|
|
74
|
+
global is rejected with a `LinkError`.
|
|
75
|
+
- Exported **tables** and **globals** are listed by `Module.exports` but are not
|
|
76
|
+
wrapped on `instance.exports`; only functions and memories are.
|
|
77
|
+
- `WebAssembly.Table` and `WebAssembly.Global` constructors are not implemented.
|
|
78
|
+
- `compileStreaming` / `instantiateStreaming` are not exposed.
|
|
79
|
+
- wasm3's supported instruction set bounds execution (no SIMD opcodes, no GC,
|
|
80
|
+
no host threads); the parser accepts the proposals the pinned wasm3 build
|
|
81
|
+
enables, and an unsupported body fails with a WebAssembly error when the
|
|
82
|
+
module is compiled or instantiated.
|
|
83
|
+
|
|
84
|
+
See [Unimplemented: WebAssembly](../unimplemented/wasm.md) for the tracked gaps.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Web Worker
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/web-worker.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/webworker/index.ts`, `runtime/worker/`
|
|
6
|
+
|
|
7
|
+
Enable the extension with `--ext webworker` (or `"extensions": ["webworker"]`
|
|
8
|
+
in `xbintsc.config.json`). It adds the browser globals `Worker`,
|
|
9
|
+
`MessageChannel`, `MessagePort`, `self`, `isMainThread` and the bare
|
|
10
|
+
`postMessage` function used inside a worker script.
|
|
11
|
+
|
|
12
|
+
## How a worker runs
|
|
13
|
+
|
|
14
|
+
xbintsc has no threads: the value model, the collector and the event loop are
|
|
15
|
+
single-threaded. A worker is a **second process** running the same executable.
|
|
16
|
+
`new Worker(...)` starts it, the two processes talk over a loopback control
|
|
17
|
+
socket, and every message is structured-cloned in the sender and rebuilt in the
|
|
18
|
+
receiver (arrays, objects, `Map`, `Set`, `Date`, `RegExp`, `ArrayBuffer`,
|
|
19
|
+
typed arrays, `BigInt`, `undefined`, shared references and cycles).
|
|
20
|
+
|
|
21
|
+
Because the binary is compiled ahead of time, the only worker script it can run
|
|
22
|
+
is itself. Pass `import.meta.filename` and branch on the `isMainThread` global:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
const worker = new Worker(import.meta.filename, { name: "echo" });
|
|
26
|
+
worker.onmessage = (event) => console.log("reply", event.data);
|
|
27
|
+
|
|
28
|
+
if (!isMainThread) {
|
|
29
|
+
self.onmessage = (event) => {
|
|
30
|
+
self.postMessage(String(event.data).toUpperCase());
|
|
31
|
+
self.close();
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
A different script path throws an actionable error instead of silently running
|
|
37
|
+
the wrong code.
|
|
38
|
+
|
|
39
|
+
## Surface
|
|
40
|
+
|
|
41
|
+
| API | Notes |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `new Worker(url, options?)` | `url` must name this executable (`import.meta.filename`); `options.name` becomes `self.name`; `options.workerData` is not a Web Worker option (use the Node API) |
|
|
44
|
+
| `worker.postMessage(value, transfer?)` | The value is structured-cloned; `transfer` is accepted but copies |
|
|
45
|
+
| `worker.terminate()` | Kills the worker process and emits `exit` |
|
|
46
|
+
| `worker.onmessage` / `onmessageerror` / `onerror` | Receive `MessageEvent`-shaped objects (`type`, `data`, `target`) |
|
|
47
|
+
| `worker.addEventListener(type, fn)` / `removeEventListener` | `message`, `error`, `messageerror` |
|
|
48
|
+
| `self.postMessage(value)` | Worker → parent |
|
|
49
|
+
| `self.onmessage` / `addEventListener` | Parent → worker |
|
|
50
|
+
| `self.close()` | Stops the worker; the process exits once its loop drains |
|
|
51
|
+
| `self.name` | The `name` the parent passed |
|
|
52
|
+
| `postMessage(value)` | The bare global form of `self.postMessage` inside a worker |
|
|
53
|
+
| `new MessageChannel()` | `port1`/`port2`, with `postMessage`, `onmessage`, `addEventListener`, `close` |
|
|
54
|
+
|
|
55
|
+
Both conventions share one event list, so `worker.on("message", fn)` (Node) and
|
|
56
|
+
`worker.onmessage = fn` can be mixed: the Node listener receives the raw value,
|
|
57
|
+
the browser listener receives the `MessageEvent`. The same names are also
|
|
58
|
+
importable from the `webworker` module
|
|
59
|
+
(`import { Worker, self, isMainThread } from "webworker"`).
|
|
60
|
+
|
|
61
|
+
## Lifetime
|
|
62
|
+
|
|
63
|
+
The parent process stays alive while a worker runs. A worker stays alive while
|
|
64
|
+
it has a message listener (or other event-loop work such as a timer); a worker
|
|
65
|
+
that only posts and returns exits on its own. `self.close()` or
|
|
66
|
+
`worker.terminate()` ends it early, and the parent then emits `exit`.
|
|
67
|
+
|
|
68
|
+
## Combining with the GUI extension
|
|
69
|
+
|
|
70
|
+
`gui` also defines a `self` global (the window). `webworker` is registered after
|
|
71
|
+
`gui`, so when both extensions are enabled `self` is the worker scope and a page
|
|
72
|
+
uses `window` for the window object. Do not rely on `self === window` in a page
|
|
73
|
+
built with both.
|
|
74
|
+
|
|
75
|
+
## Limitations
|
|
76
|
+
|
|
77
|
+
- A worker cannot run a separate source file: everything is one binary, so the
|
|
78
|
+
script is the current program and the program branches on `isMainThread`.
|
|
79
|
+
- A `MessagePort` cannot be transferred to another process yet; sending one
|
|
80
|
+
throws `MessagePort could not be cloned.`
|
|
81
|
+
- `importScripts`, `SharedArrayBuffer` and real parallelism are not available
|
|
82
|
+
(workers are processes; values are copied, never shared).
|
|
83
|
+
- An uncaught exception in a worker prints on stderr and ends that process with
|
|
84
|
+
a non-zero code; the parent observes the `exit` event, not `error`.
|
package/doc/implemented.md
CHANGED
|
@@ -39,13 +39,15 @@ small file instead of a single monolithic document.
|
|
|
39
39
|
- [Typed arrays and binary data](./implemented/typed-arrays.md) — typed arrays, ArrayBuffer, DataView
|
|
40
40
|
- [Async, promises and generators](./implemented/async.md) — async/await, async generators, promises, timers
|
|
41
41
|
- [fetch](./implemented/fetch.md) — reactor-driven HTTP/1.1 client (HTTP and HTTPS) and Headers
|
|
42
|
-
- [
|
|
42
|
+
- [Web Streams](./implemented/streams.md) — `ReadableStream`, `WritableStream`, `TransformStream`, readers/writers and text streams
|
|
43
|
+
- [WebAssembly](./implemented/wasm.md) — wasm3-backed compilation/execution, the `WebAssembly` namespace and `.wasm` imports
|
|
44
|
+
- [Web Worker](./implemented/web-worker.md) — `Worker`, `self`, `MessageChannel` and the `webworker` extension
|
|
43
45
|
|
|
44
46
|
### Modules and tooling
|
|
45
47
|
|
|
46
48
|
- [Module system](./implemented/modules.md) — import/export, bundling, `node_modules`, `import.meta`
|
|
47
49
|
- [Extension mechanism](./implemented/extensions.md) — registry, the `node` extension, native C++/Rust extensions
|
|
48
|
-
- [Node extension](./implemented/node.md) —
|
|
50
|
+
- [Node extension](./implemented/node.md) — 25 Node built-in modules, one page per module
|
|
49
51
|
- [Storage extension](./implemented/storage.md) — SQLite-backed `localStorage`, `sessionStorage` and `indexedDB`
|
|
50
52
|
- [Driver, incremental compilation and toolchain](./implemented/driver.md) — cache, clang/LTO/PGO, config, icons
|
|
51
53
|
- [CLI and programmatic API](./implemented/cli.md) — commands, flags, embedder API
|
|
@@ -72,6 +74,8 @@ same file.
|
|
|
72
74
|
| typed arrays, ArrayBuffer, DataView | [Typed arrays](./implemented/typed-arrays.md) |
|
|
73
75
|
| async/await, promises, generators, timers | [Async](./implemented/async.md) |
|
|
74
76
|
| HTTP client | [fetch](./implemented/fetch.md) |
|
|
77
|
+
| `ReadableStream` / `WritableStream` / `TransformStream` | [Web Streams](./implemented/streams.md) |
|
|
78
|
+
| `Worker`, `self`, `MessageChannel` | [Web Worker](./implemented/web-worker.md) |
|
|
75
79
|
| import/export and bundling | [Modules](./implemented/modules.md) |
|
|
76
80
|
| extension registry or the `node` extension | [Extensions](./implemented/extensions.md) |
|
|
77
81
|
| a specific Node module (`fs`, `path`, `http`, ...) | [Node extension](./implemented/node.md) |
|
|
@@ -23,6 +23,7 @@ These features **compile and run**, but the result does not fully match ECMAScri
|
|
|
23
23
|
| `let` in a `for` loop header | One binding per loop, not one per iteration: closures created inside the body all observe the final value (`for (let i = 0; i < 3; i++) fns.push(() => i)` gives `3,3,3`) |
|
|
24
24
|
| Module live bindings | Namespace imports and imported bindings are snapshots (see [Module system](./modules.md)) |
|
|
25
25
|
| `import.meta` | ✓ `import.meta.url` / `.dirname` / `.filename`, resolved from the executable path |
|
|
26
|
+
| Workers | A worker is a separate **process**, not a thread: values are structured-cloned and never shared, `postMessage` transfer lists copy, and the worker script is the current binary (`import.meta.filename` plus `isMainThread`) |
|
|
26
27
|
|
|
27
28
|
> Number formatting, loose equality, `+` / relational `ToPrimitive`, whole-chain
|
|
28
29
|
> optional chaining, `finally` on early exit and object-key ordering have all
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# `worker_threads` (unimplemented)
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: unimplemented](../node.md) · [简体中文](../../zh-CN/unimplemented/node/worker-threads.md)
|
|
4
|
+
|
|
5
|
+
The transport is a second process, not an OS thread, and a port is local to one
|
|
6
|
+
process. The following are therefore missing:
|
|
7
|
+
|
|
8
|
+
- Transferring a `MessagePort` / `ArrayBuffer` to another worker or the parent
|
|
9
|
+
(`postMessage(value, [port])`). The transfer list is accepted but values are
|
|
10
|
+
copied, and sending a port throws `MessagePort could not be cloned.`
|
|
11
|
+
- `BroadcastChannel`, `setEnvironmentData` / `getEnvironmentData`,
|
|
12
|
+
`SHARE_ENV` and `resourceLimits`.
|
|
13
|
+
- Real parallelism: workers are processes, so values are copied and
|
|
14
|
+
`SharedArrayBuffer` cannot be shared. The worker always runs the current
|
|
15
|
+
program (`import.meta.filename`), not an arbitrary script file.
|
|
16
|
+
- Worker `"error"` events: an uncaught exception in the worker prints on that
|
|
17
|
+
process's stderr and ends it with a non-zero code; the parent sees `"exit"`.
|
|
18
|
+
- `worker.unref()` / `worker.ref()` are accepted but do not change whether the
|
|
19
|
+
parent's event loop stays alive (a running worker keeps it alive).
|
|
20
|
+
- `receiveMessageOnPort` returns `undefined`; a local port already delivers its
|
|
21
|
+
queue on a zero-delay timer.
|
|
22
|
+
- `workerData` travels through the environment, so it is limited to 32 KiB on
|
|
23
|
+
Windows.
|
|
@@ -12,6 +12,7 @@ is missing or differs from Node.
|
|
|
12
12
|
- [`fs`](./node/fs.md) — callback-style async operations, real file watching, option callbacks
|
|
13
13
|
- [`fs/promises`](./node/fs-promises.md) — `FileHandle` append/read offsets, immediate `Dir` callbacks, inert `watch`, no cancellation
|
|
14
14
|
- [Fully unimplemented modules](./node/modules.md) — `https`, `tls`, `cluster`, `vm`, ...
|
|
15
|
+
- [`worker_threads`](./node/worker-threads.md) — no port transfer, no real threads, no `BroadcastChannel`
|
|
15
16
|
- [Global objects and namespaces](./node/globals.md) — `global`, `__dirname`, `require` outside `node_modules`
|
|
16
17
|
- [Async and the event-loop model](./node/async.md) — blocked file watching, blocking `net.connect`, no keep-alive, fixed-size offload pool
|
|
17
18
|
- [The Bun extension](./node/bun.md) — design example only
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
| Generators (`function*`, `yield`, `yield*`, `next`/`throw`/`return`) | ✓ implemented with stackful coroutines; `for...of`, spread and delegation supported. `return()` completes without running `finally` |
|
|
34
34
|
| Timers and microtasks | ✓ `setTimeout` / `clearTimeout` / `setInterval` / `clearInterval` / `setImmediate` / `clearImmediate` / `queueMicrotask` and `performance.now` (numeric ids, no `Timeout` / `Immediate` object). A promise settled from a timer can be awaited: the async body suspends on the pending promise and resumes when the timer fires |
|
|
35
35
|
| I/O / process and other host APIs | only via extensions (e.g. Node `fs`) |
|
|
36
|
-
| Web-platform globals (`globalThis`, `AbortController`, `AbortSignal`, `Reflect`, `Proxy`, `Intl`, `FormData`, `Blob`, `Headers`, `Request`, `Response`, `
|
|
36
|
+
| Web-platform globals (`globalThis`, `AbortController`, `AbortSignal`, `Reflect`, `Proxy`, `Intl`, `FormData`, `Blob`, `Headers`, `Request`, `Response`, `EventTarget`) | ✗ recognized (they type-check and lower to `undefined`), but no runtime implementation |
|
|
37
|
+
| Web Streams (`ReadableStream`, `WritableStream`, `TransformStream`, readers/writers, text streams) | ✓ implemented as core globals; see [Web Streams](../implemented/streams.md). BYOB byte streams and compression streams are not implemented |
|
|
37
38
|
|
|
38
39
|
## Typed arrays
|
|
39
40
|
|
|
@@ -4,12 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
## Not implemented
|
|
6
6
|
|
|
7
|
-
- **
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- `WebAssembly.
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
- **Non-function imports.** A module that imports a memory, table or global is
|
|
8
|
+
rejected with a `LinkError`; only imported functions are bridged from the JS
|
|
9
|
+
import object.
|
|
10
|
+
- **Exported tables and globals.** `WebAssembly.Module.exports` lists them, but
|
|
11
|
+
`instance.exports` only wraps functions and memories. `WebAssembly.Table` and
|
|
12
|
+
`WebAssembly.Global` constructors throw "not supported".
|
|
13
|
+
- **Streaming.** `WebAssembly.compileStreaming` and
|
|
14
|
+
`WebAssembly.instantiateStreaming` are not exposed.
|
|
15
|
+
- **Custom sections.** `WebAssembly.Module.customSections` returns an empty
|
|
16
|
+
array; section contents are not preserved.
|
|
17
|
+
- **Instruction-set coverage beyond wasm3.** The pinned interpreter implements a
|
|
18
|
+
large core subset (the parser also accepts several proposals), but SIMD
|
|
19
|
+
opcodes, the GC proposal, host threads/shared memory and WASI are not
|
|
20
|
+
available. A body using an unsupported opcode fails when the module is
|
|
21
|
+
compiled or instantiated.
|
|
22
|
+
- **Multi-module linking.** Importing one WebAssembly module's exports into
|
|
23
|
+
another is not wired up; each instantiation is self-contained plus JS
|
|
24
|
+
function imports.
|
|
25
|
+
|
|
26
|
+
The execution path itself is implemented (wasm3 behind the namespace) — see
|
|
27
|
+
[Implemented: WebAssembly](../implemented/wasm.md).
|
package/doc/unimplemented.md
CHANGED
|
@@ -27,6 +27,6 @@ under [implemented](./implemented.md); git history records when it changed.
|
|
|
27
27
|
- [Classes and OO](./unimplemented/classes.md) — access control, `abstract`/`implements`, private-name collisions
|
|
28
28
|
- [Type system](./unimplemented/types.md) — parsed and erased; only inference-free facts are checked
|
|
29
29
|
- [Runtime deviations](./unimplemented/deviations.md) — compiles and runs, but differs from ECMAScript
|
|
30
|
-
- [WebAssembly](./unimplemented/wasm.md) —
|
|
30
|
+
- [WebAssembly](./unimplemented/wasm.md) — imported memories/tables/globals, streaming and the remaining API gaps
|
|
31
31
|
- [Toolchain and platform](./unimplemented/toolchain.md) — type checker, async I/O, GC modes, platform gaps
|
|
32
32
|
- [Node extension](./unimplemented/node.md) — Node module gaps, one page per area
|
package/doc/zh-CN/gui/api.md
CHANGED
|
@@ -107,7 +107,7 @@ requestAnimationFrame(frame);
|
|
|
107
107
|
| `HTMLCanvasElement`、`HTMLImageElement`、`WebGLRenderingContext`、`WebGL2RenderingContext`、`WebGLBuffer`/`WebGLTexture`/`WebGLShader`/`WebGLProgram`/`WebGLFramebuffer`/`WebGLRenderbuffer`/`WebGLUniformLocation`/`WebGLActiveInfo`/`WebGLVertexArrayObject`/`WebGLSampler`/`WebGLQuery`/`WebGLSync`/`WebGLTransformFeedback` | 真实的构造函数值。`canvas.getContext("webgl")` 与 `getContext("webgl2")` 返回 GPU 上下文(见 [WebGL](./webgl.md))。 |
|
|
108
108
|
| `ImageBitmap`、`createImageBitmap(source)` | 由已解码像素支撑的不可变位图(`<img>`、`<canvas>`、`<video>` 帧、`OffscreenCanvas` 与 `ImageData` 形状);promise 立即 settle,`texImage2D` 可直接接受该对象 |
|
|
109
109
|
| `OffscreenCanvas` | 真正的 2D 离屏位图,带 `getContext("2d")`、`width`/`height`、`transferToImageBitmap()` 与 `convertToBlob()`;`canvas.transferControlToOffscreen()` 会把元素位图交给它(见 [Canvas](./canvas.md))。离屏 WebGL 上下文不提供。 |
|
|
110
|
-
| `ImageData`、`XRWebGL*`、`Request`、`Headers`、`Response`、`
|
|
110
|
+
| `ImageData`、`XRWebGL*`、`Request`、`Headers`、`Response`、`DOMParser` | `typeof` 探测返回 `"undefined"`(没有 XR、DOM 解析器或流式后端),让页面走自己的“不支持”分支,而不是调用空壳。`fetch` 仍然可用,并返回 response 形状的对象,但没有 `Response` 构造函数,且 `response.arrayBuffer()` 目前返回字节数组而不是 `ArrayBuffer`;`ReadableStream` 等 Web Streams 类来自核心运行时。Three.js 页面在本后端上使用真实渲染器(见[已知问题](./known-issues.md))。 |
|
|
111
111
|
| `requestAnimationFrame` / `cancelAnimationFrame` | 排入窗口的动画帧列表,见[运行时集成](./runtime.md) |
|
|
112
112
|
| `alert` / `confirm` / `prompt`、`matchMedia`、`getComputedStyle`、`escape` | 宿主实现。`matchMedia` 返回**实时**列表(按查询缓存):`matches` 在窗口尺寸变化时重新求值,翻转时触发 `change` 监听器。`confirm`/`prompt` 仅在 `XT_GUI_DIALOGS=1` 时使用原生对话框,否则把消息写到 stderr 并返回文档化的默认值(Annex B `escape` 按 UTF-16 码元编码,与 `decodeURIComponent(escape(bytes))` 一致) |
|
|
113
113
|
|
|
@@ -28,7 +28,7 @@ xbintsc help 帮助
|
|
|
28
28
|
--emit <kind> exe | obj | ir(默认 exe)
|
|
29
29
|
-O0..-O3 优化级别(默认 -O2)
|
|
30
30
|
--ext <names> 逗号分隔扩展(如 node)
|
|
31
|
-
--feature <names> 强制开启可选链接特性(media,gpu,images,shaping,webgl,all)
|
|
31
|
+
--feature <names> 强制开启可选链接特性(media,gpu,images,shaping,webgl,storage,tls,wasm,all)
|
|
32
32
|
--no-feature <n> 即使检测到也不链接该可选特性
|
|
33
33
|
--ext-native <m> 从 JSON manifest 注册 C++/Rust 扩展
|
|
34
34
|
--config <path> 使用项目配置(默认自动查找 xbintsc.config.json)
|
|
@@ -2,21 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
> 属于[已实现语法与功能](../implemented.md) · [English](../../implemented/extensions.md)
|
|
4
4
|
|
|
5
|
-
实现位置:`src/extensions/registry.ts`、`src/extensions/node/`、`src/extensions/link-feature.ts`、`src/driver/usage.ts`、`src/driver/link-features.ts`
|
|
5
|
+
实现位置:`src/extensions/registry.ts`、`src/extensions/node/`、`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
|
- 扩展是普通对象:`runtimeSources()`(额外 C 源)、`linkerFlags()`(额外链接参数)、`builtins()`(全局标识符 → 运行时符号,统一 `(argc, argv)` ABI)、`modules()`(导入说明符 → 命名导出 / 命名空间)与 `linkFeatures()`(可选的重型能力)。
|
|
8
8
|
- `ExtensionRegistry`:注册 / 注销 / 查询 / 汇总 builtins、modules、runtime 源、链接参数与链接特性。
|
|
9
|
-
- **可选链接特性**(`media`、`gpu`、`images`、`shaping`、`webgl`):
|
|
10
|
-
- 特性声明 `runtimeSources()`(只在启用时编译的 C bridge)、`nativeObjects()`(只在启用时链接的归档)、`linkerFlags()`、可选的 `requires
|
|
9
|
+
- **可选链接特性**(`media`、`gpu`、`images`、`shaping`、`webgl`、`storage`、`wasm`):
|
|
10
|
+
- 特性声明 `runtimeSources()`(只在启用时编译的 C bridge)、`nativeObjects()`(只在启用时链接的归档)、`linkerFlags()`、可选的 `requires`(依赖的另一个特性)、可选的 `required`(源不可用时构建报错而不是 warning)与 `used(usage)`。
|
|
11
11
|
- driver 从打包后的 AST 构造 `ProgramUsage`(`src/driver/usage.ts` 的 `collectUsage`):字符串字面量(含导入 HTML 与内联 CSS)、标识符/属性名、`getContext(...)` 的 kind,以及 markup 是否可能在运行时拼出。简单的 `const` 别名会被解析;无法解析的 markup 让程序走保守回退。
|
|
12
|
-
- `resolveLinkFeatures` 应用 `--feature` / `--no-feature`(以及 `all`),展开 `requires
|
|
12
|
+
- `resolveLinkFeatures` 应用 `--feature` / `--no-feature`(以及 `all`),展开 `requires`,把自动检测到但不可用的可选特性报为 warning、把 required 或强制开启却不可用的报为 error,并返回要链接的 bridge/归档/参数。
|
|
13
13
|
- bridge 就是强引用:构造函数安装特性的分发表,其引用迫使链接器取出实现;没有 bridge 时表保持 null,实现成员永不被链接。
|
|
14
|
-
- 当前客户端:`media`(FFmpeg,`runtime/xt_media/media_bridge.c` + `media.a`)、`gpu`(glslang/SPIRV-Cross,`runtime/ext_gui/gpu_bridge.c` + `gui.a` 内的 `gpu_feature.cpp`)、`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 绑定,`runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`,依赖 `gpu
|
|
14
|
+
- 当前客户端:`media`(FFmpeg,`runtime/xt_media/media_bridge.c` + `media.a`)、`gpu`(glslang/SPIRV-Cross,`runtime/ext_gui/gpu_bridge.c` + `gui.a` 内的 `gpu_feature.cpp`)、`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 绑定,`runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`,依赖 `gpu`)、`storage`(基于 SQLite 的 Web Storage/IndexedDB,其实现完全位于该特性的 `runtimeSources` —— `runtime/xt_storage/*.c`,因为这些全局变量本身就是强引用)以及 `wasm`(`WebAssembly` 命名空间背后的 wasm3;`runtime/xt_wasm/wasm_bridge.c` 安装分发表,`vendor/wasm3` 提供解释器)。
|
|
15
15
|
- TLS/HTTP2 客户端:`tls`(`runtime/xt_tls/tls_core.c` 中的 mbedTLS 传输层加 `tls` 归档,供 `fetch` 与 `node:tls` 使用)、`node-tls`(`TLSSocket`/服务端接口,依赖 `tls`)与 `http2`(`runtime/ext_node/http2/http2_backend.c` 中的 nghttp2 后端,依赖 `tls` 与 `node-tls`;`npm run tls` 构建两个归档)。
|
|
16
|
-
- 内置核心扩展 `core`:暴露 `print`(映射 `xt_println
|
|
16
|
+
- 内置核心扩展 `core`:暴露 `print`(映射 `xt_println`)、Web Storage 全局对象、`storage`/`tls`/`wasm` 链接特性以及二进制 `.wasm` 资源加载器,始终注册。
|
|
17
17
|
- Node 扩展 `node`:
|
|
18
18
|
- 模块化组织:`src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
19
19
|
- 暴露可导入模块(`fs`、`fs/promises`、`path`、`os`、`process` 等),同时支持裸名称与 `node:` 前缀;`import { readFileSync } from "fs"` 解析到 `xt_node_read_text_file`,`path`/`os`/`process` 的导出映射到命名空间分发器。
|
|
20
|
+
- Web Worker 扩展 `webworker`:浏览器全局对象 `Worker`、`MessageChannel`、`MessagePort`、`self`、`isMainThread` 与裸 `postMessage`。worker 是运行同一可执行文件的第二个进程(没有线程),因此入口模式是 `new Worker(import.meta.filename)` 加 `isMainThread` 分支。传输层(`runtime/worker/`)与 `node:worker_threads` 共用;见 [Web Worker](./web-worker.md)。
|
|
20
21
|
- 添加新模块只需新增目录 + C 实现,核心编译器无需改动。
|
|
21
22
|
- 原生 C++/Rust 扩展(`src/extensions/native.ts`、`--ext-native`):
|
|
22
23
|
- `nativeObjects()` 链接以 `(argc, argv)` ABI 暴露 `extern "C"` 符号的预编译对象/静态库;JSON manifest 把它们映射为 builtins/modules(`linkerFlags` / `linkerFlagsByPlatform` 用于 C++/Rust 运行时)。
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# `stream/web`
|
|
2
|
+
|
|
3
|
+
> 属于[Node 扩展:已实现](../node.md) · [English](../../../implemented/node/stream-web.md)
|
|
4
|
+
|
|
5
|
+
实现位置:`src/extensions/node/stream-web/index.ts`、`runtime/ext_node/stream_web/stream_web.c`。
|
|
6
|
+
|
|
7
|
+
Node 的 `stream/web` 子路径重新导出 WHATWG 流类。实现位于核心运行时(见 [Web Streams](../streams.md)),因此编译后的程序既可以把它当作浏览器全局使用,也可以按名字导入:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { ReadableStream, TransformStream } from "node:stream/web";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
| 导出 | 说明 |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `ReadableStream`、`ReadableStreamDefaultReader`、`ReadableStreamDefaultController` | 完整实现 |
|
|
16
|
+
| `WritableStream`、`WritableStreamDefaultWriter`、`WritableStreamDefaultController` | 完整实现 |
|
|
17
|
+
| `TransformStream`、`TransformStreamDefaultController` | 完整实现 |
|
|
18
|
+
| `TextEncoderStream`、`TextDecoderStream` | UTF-8 文本转换流 |
|
|
19
|
+
| `CountQueuingStrategy`、`ByteLengthQueuingStrategy` | 队列策略 |
|
|
20
|
+
| `ReadableStreamBYOBReader`、`ReadableStreamBYOBRequest` | 有导出;构造函数抛错(不支持字节流) |
|
|
21
|
+
| `CompressionStream`、`DecompressionStream` | 有导出;构造函数抛错(不支持压缩流) |
|
|
22
|
+
| `ReadableStreamTee` | 为 `undefined`,undici 的 `ReadableStreamTee?.(...) ?? body.stream.tee()` 会回退到 body 自身的 `tee` |
|
|
23
|
+
|
|
24
|
+
构造函数是一等值:`const RS = ReadableStream`、`new RS(...)`、`stream instanceof ReadableStream` 与 `ReadableStream.from(...)` 均可用。异步模型、支持的方法与剩余限制(BYOB、压缩流)见 [Web Streams](../streams.md)。
|