xbintsc 0.6.20 → 0.6.23
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 +5 -0
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +1 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +3 -0
- package/dist/src/driver/build-key.js +5 -2
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/compiler.js +11 -0
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +12 -0
- package/dist/src/driver/config.js +22 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/fingerprint.d.ts +11 -0
- package/dist/src/driver/fingerprint.js +25 -0
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/index.d.ts +2 -1
- package/dist/src/driver/index.js +1 -0
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/link-features.js +36 -11
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/options.d.ts +8 -1
- package/dist/src/driver/paths.d.ts +10 -0
- package/dist/src/driver/paths.js +18 -0
- 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 +22 -6
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/storage.d.ts +34 -0
- package/dist/src/driver/storage.js +67 -0
- package/dist/src/driver/storage.js.map +1 -0
- package/dist/src/driver/toolchain.d.ts +1 -1
- package/dist/src/driver/toolchain.js +10 -1
- package/dist/src/driver/toolchain.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/gui/features.d.ts +1 -1
- package/dist/src/extensions/gui/features.js +2 -2
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/node/http2/feature.d.ts +14 -0
- package/dist/src/extensions/node/http2/feature.js +28 -0
- package/dist/src/extensions/node/http2/feature.js.map +1 -0
- package/dist/src/extensions/node/http2/index.d.ts +5 -1
- package/dist/src/extensions/node/http2/index.js +6 -1
- package/dist/src/extensions/node/http2/index.js.map +1 -1
- package/dist/src/extensions/node/index.js +3 -1
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/tls/feature.d.ts +12 -0
- package/dist/src/extensions/node/tls/feature.js +24 -0
- package/dist/src/extensions/node/tls/feature.js.map +1 -0
- package/dist/src/extensions/node/tls/index.d.ts +5 -1
- package/dist/src/extensions/node/tls/index.js +5 -1
- package/dist/src/extensions/node/tls/index.js.map +1 -1
- package/dist/src/extensions/node/zlib/compression.js +11 -6
- package/dist/src/extensions/node/zlib/compression.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +4 -1
- package/dist/src/extensions/registry.js +9 -2
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/storage.d.ts +22 -0
- package/dist/src/extensions/storage.js +51 -0
- package/dist/src/extensions/storage.js.map +1 -0
- package/dist/src/extensions/tls.d.ts +26 -0
- package/dist/src/extensions/tls.js +46 -0
- package/dist/src/extensions/tls.js.map +1 -0
- package/dist/tests/driver/config.test.js +31 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +13 -2
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/storage.test.d.ts +1 -0
- package/dist/tests/driver/storage.test.js +29 -0
- package/dist/tests/driver/storage.test.js.map +1 -0
- package/dist/tests/e2e/fetch.test.js +3 -1
- package/dist/tests/e2e/fetch.test.js.map +1 -1
- package/dist/tests/e2e/http2.test.d.ts +7 -0
- package/dist/tests/e2e/http2.test.js +201 -0
- package/dist/tests/e2e/http2.test.js.map +1 -0
- package/dist/tests/e2e/net-helpers.d.ts +28 -0
- package/dist/tests/e2e/net-helpers.js +59 -0
- package/dist/tests/e2e/net-helpers.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +3 -5
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/storage.test.d.ts +7 -0
- package/dist/tests/e2e/storage.test.js +86 -0
- package/dist/tests/e2e/storage.test.js.map +1 -0
- package/dist/tests/e2e/tls.test.d.ts +10 -0
- package/dist/tests/e2e/tls.test.js +197 -0
- package/dist/tests/e2e/tls.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +1 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/dist/tests/extensions/storage.test.d.ts +1 -0
- package/dist/tests/extensions/storage.test.js +51 -0
- package/dist/tests/extensions/storage.test.js.map +1 -0
- package/doc/ai/cli.md +2 -0
- package/doc/ai/contributing.md +14 -0
- package/doc/ai/extensions.md +31 -3
- package/doc/ai/language-support.md +1 -1
- package/doc/ai/zh-CN/cli.md +2 -0
- package/doc/ai/zh-CN/contributing.md +12 -0
- package/doc/ai/zh-CN/extensions.md +27 -2
- package/doc/ai/zh-CN/language-support.md +1 -1
- package/doc/gui/api.md +1 -1
- package/doc/gui/build.md +7 -5
- package/doc/gui/media.md +4 -4
- package/doc/gui/rendering.md +1 -1
- package/doc/gui.md +3 -3
- package/doc/implemented/async.md +1 -1
- package/doc/implemented/extensions.md +2 -1
- package/doc/implemented/fetch.md +19 -4
- package/doc/implemented/node/http2.md +51 -0
- package/doc/implemented/node/tls.md +56 -0
- package/doc/implemented/node.md +8 -0
- package/doc/implemented/storage.md +65 -0
- package/doc/implemented.md +4 -2
- package/doc/unimplemented/node/modules.md +6 -6
- package/doc/unimplemented/toolchain.md +1 -1
- package/doc/xbintsc.config.schema.json +16 -1
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/gui/build.md +6 -4
- package/doc/zh-CN/gui/media.md +3 -3
- package/doc/zh-CN/gui/rendering.md +1 -1
- package/doc/zh-CN/gui.md +3 -3
- package/doc/zh-CN/implemented/async.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +2 -1
- package/doc/zh-CN/implemented/fetch.md +15 -3
- package/doc/zh-CN/implemented/node/http2.md +44 -0
- package/doc/zh-CN/implemented/node/tls.md +47 -0
- package/doc/zh-CN/implemented/node.md +7 -0
- package/doc/zh-CN/implemented/storage.md +52 -0
- package/doc/zh-CN/implemented.md +4 -2
- package/doc/zh-CN/unimplemented/node/modules.md +3 -3
- package/doc/zh-CN/unimplemented/toolchain.md +1 -1
- package/package.json +16 -8
- package/runtime/ext_gui/dom_api_form.cpp +10 -0
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/media.cpp +1 -1
- package/runtime/ext_gui/media_api.h +2 -2
- package/runtime/ext_node/http2/http2.c +25 -11
- package/runtime/ext_node/http2/http2_backend.c +48 -0
- package/runtime/ext_node/http2/http2_bridge.c +25 -0
- package/runtime/ext_node/http2/parts/api.inc +40 -0
- package/runtime/ext_node/http2/parts/client.inc +215 -0
- package/runtime/ext_node/http2/parts/common.inc +330 -0
- package/runtime/ext_node/http2/parts/events.inc +139 -0
- package/runtime/ext_node/http2/parts/server.inc +301 -0
- package/runtime/ext_node/http2/parts/streams.inc +254 -0
- package/runtime/ext_node/tls/parts/api.inc +38 -0
- package/runtime/ext_node/tls/parts/connect.inc +107 -0
- package/runtime/ext_node/tls/parts/helpers.inc +121 -0
- package/runtime/ext_node/tls/parts/server.inc +101 -0
- package/runtime/ext_node/tls/parts/socket.inc +171 -0
- package/runtime/ext_node/tls/tls.c +21 -13
- package/runtime/ext_node/tls/tls_backend.c +50 -0
- package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
- package/runtime/xt_fetch/async.inc +19 -12
- package/runtime/xt_fetch/socket.inc +55 -0
- package/runtime/xt_fetch.c +3 -0
- package/runtime/xt_http2/nghttp2_compat.h +19 -0
- package/runtime/xt_http2/nghttp2_static.h +18 -0
- package/runtime/xt_http2_api.h +38 -0
- package/runtime/xt_node_tls_api.h +37 -0
- package/runtime/xt_protocol_registry.c +22 -0
- package/runtime/xt_storage/indexed_db.c +408 -0
- package/runtime/xt_storage/indexed_db_internal.h +26 -0
- package/runtime/xt_storage/indexed_db_store.c +305 -0
- package/runtime/xt_storage/storage.c +209 -0
- package/runtime/xt_storage/storage_internal.h +66 -0
- package/runtime/xt_tls/parts/api.inc +21 -0
- package/runtime/xt_tls/parts/client.inc +112 -0
- package/runtime/xt_tls/parts/io.inc +157 -0
- package/runtime/xt_tls/parts/server.inc +102 -0
- package/runtime/xt_tls/parts/setup.inc +146 -0
- package/runtime/xt_tls/tls_bridge.c +27 -0
- package/runtime/xt_tls/tls_core.c +39 -0
- package/runtime/xt_tls/tls_internal.h +73 -0
- package/runtime/xt_tls_api.h +73 -0
- package/scripts/build-gui.ts +9 -8
- package/scripts/build-media.ts +2 -2
- package/scripts/build-tls.ts +248 -0
- package/scripts/check-file-length.ts +4 -21
- package/scripts/fetch-vendored.ts +244 -0
- package/scripts/package-release.ts +13 -3
- package/src/cli/main.ts +1 -0
- package/src/driver/build-key.ts +13 -2
- package/src/driver/compiler.ts +13 -0
- package/src/driver/config.ts +35 -0
- package/src/driver/fingerprint.ts +24 -0
- package/src/driver/index.ts +8 -0
- package/src/driver/link-features.ts +33 -11
- package/src/driver/options.ts +8 -1
- package/src/driver/paths.ts +20 -0
- package/src/driver/runtime-objects.ts +25 -6
- package/src/driver/storage.ts +84 -0
- package/src/driver/toolchain.ts +11 -2
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +2 -2
- package/src/extensions/gui/index.ts +3 -1
- package/src/extensions/node/http2/feature.ts +33 -0
- package/src/extensions/node/http2/index.ts +6 -1
- package/src/extensions/node/index.ts +3 -1
- package/src/extensions/node/tls/feature.ts +29 -0
- package/src/extensions/node/tls/index.ts +5 -1
- package/src/extensions/node/zlib/compression.ts +11 -6
- package/src/extensions/registry.ts +9 -2
- package/src/extensions/storage.ts +58 -0
- package/src/extensions/tls.ts +52 -0
- package/vendor/sqlite3/sqlite3.c +271131 -0
- package/vendor/sqlite3/sqlite3.h +14447 -0
- package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
- /package/runtime/{ext_media → xt_media}/decode_audio.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media_bridge.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
- /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
- /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
- /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
package/doc/gui/rendering.md
CHANGED
|
@@ -197,7 +197,7 @@ unavailable it is skipped while the rest of the page still paints.
|
|
|
197
197
|
|
|
198
198
|
`runtime/ext_gui/text.{h,cpp}` is the front-end; it dispatches through a small
|
|
199
199
|
backend table. The default backend is the bundled **stb_truetype**
|
|
200
|
-
(`text_stb.cpp`, `
|
|
200
|
+
(`text_stb.cpp`, `vendor/stb/stb_truetype.h`). The optional **`shaping`**
|
|
201
201
|
link feature installs `text_hb.cpp`, a HarfBuzz + FreeType backend, and is
|
|
202
202
|
selected automatically for non-ASCII text or an author `@font-face` rule. Both
|
|
203
203
|
backends share the font database in `text_font_db.cpp` (discovery and indexing)
|
package/doc/gui.md
CHANGED
|
@@ -151,7 +151,7 @@ Pinned versions: SDL3 `release-3.2.10`, FreeType `2.13.3`, HarfBuzz `10.1.0`
|
|
|
151
151
|
`vulkan-sdk-1.4.313.0`, FFmpeg `7.1` for the optional `media` archive
|
|
152
152
|
(overridable with `SDL3_TAG` / `FREETYPE_VERSION` / `HARFBUZZ_VERSION` /
|
|
153
153
|
`GLSLANG_VERSION` / `SPIRV_CROSS_VERSION` / `FFMPEG_VERSION`). The default text
|
|
154
|
-
backend is the bundled `stb_truetype.h`; it accepts TrueType outlines (not
|
|
154
|
+
backend is the bundled `vendor/stb/stb_truetype.h`; it accepts TrueType outlines (not
|
|
155
155
|
CFF/OTF or variable fonts). The `shaping` feature swaps in HarfBuzz + FreeType
|
|
156
156
|
for full OpenType shaping.
|
|
157
157
|
|
|
@@ -289,7 +289,7 @@ engine were Rust.
|
|
|
289
289
|
`tests/e2e/gui-retention.test.ts` (see [Memory & GC](./gui/runtime.md#memory--gc)).
|
|
290
290
|
13. **M13 — video & audio** ✅
|
|
291
291
|
- `<video>` / `<audio>` decode through a statically vendored minimal FFmpeg
|
|
292
|
-
in the optional `media` link feature (`runtime/
|
|
292
|
+
in the optional `media` link feature (`runtime/xt_media/media.cpp`); the
|
|
293
293
|
compiler selects it from the program and only then compiles the bridge and
|
|
294
294
|
links `media.a`. Frames
|
|
295
295
|
upload to GPU textures through the existing image pipeline, audio is
|
|
@@ -505,7 +505,7 @@ engine were Rust.
|
|
|
505
505
|
merges it into `media.a` (or `media.lib` from clang-cl/MSVC objects on
|
|
506
506
|
Windows). The compiler selects the feature from the program and only then
|
|
507
507
|
compiles `media_bridge.c` and links `media.a`; a DOM/CSS program never links
|
|
508
|
-
FFmpeg. `runtime/
|
|
508
|
+
FFmpeg. `runtime/xt_media/media.cpp` decodes video to RGBA
|
|
509
509
|
frames and audio to 48 kHz stereo PCM on the main thread,
|
|
510
510
|
`runtime/ext_gui/gui_media.cpp` owns the players, implements the SDL audio
|
|
511
511
|
sink and pumps the media clock and events each frame,
|
package/doc/implemented/async.md
CHANGED
|
@@ -47,6 +47,6 @@ Location: `runtime/xt_async.c`, `runtime/xt_coroutine.c`, `runtime/xt_promise.c`
|
|
|
47
47
|
- `fetch` runs each request/redirect hop as a job; `fs/promises` runs every file and descriptor operation as a job. Neither blocks timers, sockets or other `await`s.
|
|
48
48
|
- The event loop stays alive while jobs are outstanding (`xt_loop_has_work`), and exits once the pool is idle again.
|
|
49
49
|
|
|
50
|
-
Known limits of the asynchronous surface (
|
|
50
|
+
Known limits of the asynchronous surface (streaming/abortable `fetch`, inert
|
|
51
51
|
`fs.watch`, four-worker pool) are listed in
|
|
52
52
|
[Runtime deviations](../unimplemented/deviations.md) and the Node pages.
|
|
@@ -11,7 +11,8 @@ Location: `src/extensions/registry.ts`, `src/extensions/node/`, `src/extensions/
|
|
|
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
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.
|
|
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/
|
|
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`), and `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).
|
|
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).
|
|
15
16
|
- The built-in core extension `core`: exposes `print` (mapped to `xt_println`), always registered.
|
|
16
17
|
- The Node extension `node`:
|
|
17
18
|
- Modular organisation: `src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
package/doc/implemented/fetch.md
CHANGED
|
@@ -4,15 +4,23 @@
|
|
|
4
4
|
|
|
5
5
|
Location: `runtime/xt_fetch.c`, `runtime/xt_fetch/async.inc`, `runtime/xt_async_io.c`.
|
|
6
6
|
|
|
7
|
-
- Global `fetch(input, init)` is an HTTP/1.1 client
|
|
7
|
+
- Global `fetch(input, init)` is an HTTP/1.1 client over either `http://` or
|
|
8
|
+
`https://`. The blocking socket exchange
|
|
8
9
|
(`getaddrinfo`, connect, send, receive) runs on the asynchronous I/O worker
|
|
9
10
|
pool, so a request in flight does **not** stall the event loop: timers, sockets
|
|
10
11
|
and other `await`s keep running and the promise settles when the reactor
|
|
11
12
|
dispatches the completed exchange.
|
|
12
13
|
- Redirects are followed on the main thread: each hop is one offloaded
|
|
13
14
|
exchange, up to 20 redirects, and a 301/302/303 switches POST to GET.
|
|
14
|
-
- It accepts `http://`
|
|
15
|
-
|
|
15
|
+
- It accepts `http://` and `https://` URLs. HTTPS is served by the optional
|
|
16
|
+
`tls` link feature (vendored mbedTLS): the compiler selects it for an
|
|
17
|
+
`https://` literal (or `--feature tls`), and a program that never makes an
|
|
18
|
+
HTTPS request pays nothing. Without the archive a request rejects with a
|
|
19
|
+
`TypeError` naming the missing feature. Certificates are verified against the
|
|
20
|
+
platform trust store (Windows `ROOT`, Linux CA bundles, macOS
|
|
21
|
+
`/etc/ssl/cert.pem`); `NODE_EXTRA_CA_CERTS` names an extra PEM bundle to
|
|
22
|
+
trust, which is how a private or self-signed CA is used. `fetch` takes no
|
|
23
|
+
`ca` option in `init`.
|
|
16
24
|
- A reference with **no scheme** (a relative path) and `file://` URLs read a
|
|
17
25
|
local file, so a compiled program can load an asset from disk without an HTTP
|
|
18
26
|
server. Relative paths resolve against the working directory; `GET` / `HEAD`
|
|
@@ -45,5 +53,12 @@ setTimeout(() => console.log("timer"), 10); // runs before the 150ms response
|
|
|
45
53
|
await pending;
|
|
46
54
|
```
|
|
47
55
|
|
|
48
|
-
|
|
56
|
+
An HTTPS request works the same way once the `tls` feature is linked:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const response = await fetch("https://example.com/status");
|
|
60
|
+
console.log(response.status, await response.text());
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Known limits (buffered body, no streaming or abort signal) are listed in
|
|
49
64
|
[Runtime deviations](../unimplemented/deviations.md).
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# `http2`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/http2.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/http2/`, `runtime/ext_node/http2/`, `runtime/xt_http2/`
|
|
6
|
+
|
|
7
|
+
HTTP/2 framing and HPACK come from vendored nghttp2. The `http2` link feature is
|
|
8
|
+
selected by importing `http2` / `node:http2` (or naming `createSecureServer`);
|
|
9
|
+
it `requires: ["tls", "node-tls"]`, because a secure server reuses the
|
|
10
|
+
`node:tls` server wrapper and both schemes negotiate ALPN `h2` through mbedTLS.
|
|
11
|
+
`runtime/ext_node/http2/http2_backend.c` is compiled into the pinned nghttp2
|
|
12
|
+
archive (`runtime/lib/<os>-<arch>/nghttp2.{a,lib}`); the feature's compiled
|
|
13
|
+
entry point is `http2_bridge.c`, whose call extracts the backend and installs
|
|
14
|
+
it. `npm run tls` builds that archive and the mbedTLS one, so an installed npm
|
|
15
|
+
package does not need the vendored headers.
|
|
16
|
+
|
|
17
|
+
An `Http2Session` owns one socket and one `nghttp2_session`. The runtime's
|
|
18
|
+
readiness reactor feeds bytes to `nghttp2_session_mem_recv2` and flushes
|
|
19
|
+
`nghttp2_session_mem_send2`; nghttp2 callbacks raise the JavaScript events.
|
|
20
|
+
There is no HTTP/1.1 upgrade: a cleartext `http://` connection speaks h2c with
|
|
21
|
+
prior knowledge, exactly like Node's client.
|
|
22
|
+
|
|
23
|
+
| API | Notes |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| `http2.connect(authority[, options][, listener])` | `http(s)://host:port`; `options`: `ca`, `rejectUnauthorized`; returns a connected `ClientHttp2Session` and emits `connect` |
|
|
26
|
+
| `session.request(headers[, options])` | `headers` with `:method` (default `GET`), `:path`, `:scheme`, `:authority` plus ordinary fields; returns a `ClientHttp2Stream` |
|
|
27
|
+
| `stream.end([data])` / `write(data)` / `close()` | request body and cancellation; emits `response(headers, flags)`, `data`, `end`, `close`, `error` |
|
|
28
|
+
| `session.close()` / `destroy()` | sends GOAWAY and closes the transport |
|
|
29
|
+
| `http2.createServer([options][, onRequest])` | cleartext h2c server; `listen` / `address` / `close` behave like `net.Server` |
|
|
30
|
+
| `http2.createSecureServer(options[, onRequest])` | TLS + ALPN `h2`; `options` needs `cert` and `key` (plus `ca` for client certificates) |
|
|
31
|
+
| `server.on("stream", (stream, headers) => …)` | server-side stream combines the request emitter with `respond` / `setHeader` / `write` / `end` |
|
|
32
|
+
| `http2.constants` | frame-type and error-code numbers (`NGHTTP2_FLAG_END_STREAM`, `NGHTTP2_CANCEL`, …) |
|
|
33
|
+
|
|
34
|
+
Server-side streams expose `method`, `url`, `scheme`, `authority`,
|
|
35
|
+
`httpVersion` (`"2.0"`) and `headers`; the second `stream` argument is the same
|
|
36
|
+
headers object. `respond(statusOrHeaders[, headers])` (or `respond({":status":
|
|
37
|
+
201})`), `setHeader` / `getHeader` and `write` / `end` submit the response. The
|
|
38
|
+
incoming request body is delivered through `data` / `end` and is also available
|
|
39
|
+
through the same stream object.
|
|
40
|
+
|
|
41
|
+
The e2e suite proves interoperability in both directions: a compiled client
|
|
42
|
+
against Node's `http2` server (h2c and TLS) and Node's client against a compiled
|
|
43
|
+
`createServer` / `createSecureServer`.
|
|
44
|
+
|
|
45
|
+
## Known limits
|
|
46
|
+
|
|
47
|
+
`pushStream`, trailers, extended CONNECT, session pooling / connection reuse,
|
|
48
|
+
`stream.priority` and flow-control tuning are not implemented. Response headers
|
|
49
|
+
and body are buffered until `end()` (which is when the response is submitted),
|
|
50
|
+
so a handler that wants to stream a long body still works but does not flush
|
|
51
|
+
partial responses early.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# `tls`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/tls.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/tls/`, `runtime/ext_node/tls/`, `runtime/xt_tls/`
|
|
6
|
+
|
|
7
|
+
`node:tls` is backed by vendored mbedTLS (TLS 1.2/1.3, X.509 and PSA crypto).
|
|
8
|
+
Two link features keep it optional:
|
|
9
|
+
|
|
10
|
+
- **`tls`** (declared by the core extension) is the mbedTLS transport:
|
|
11
|
+
`runtime/xt_tls/tls_core.c` is archived into `tls.{a,lib}` and the feature's
|
|
12
|
+
compiled entry point is the tiny `tls_bridge.c`, whose call extracts the
|
|
13
|
+
backend and installs it. `fetch` uses it for `https://` URLs. It is selected
|
|
14
|
+
by an `https://` literal, `node:tls`/`node:http2` usage, or `--feature tls`.
|
|
15
|
+
- **`node-tls`** (`requires: ["tls"]`) adds the JavaScript surface in
|
|
16
|
+
`runtime/ext_node/tls/tls_backend.c` and is selected by importing `tls` /
|
|
17
|
+
`node:tls` (the import specifier is a string literal in the bundle).
|
|
18
|
+
|
|
19
|
+
`npm run tls` fetches the pinned mbedTLS release into `vendor/mbedtls`, compiles
|
|
20
|
+
it together with `tls_core.c` and writes `runtime/lib/<os>-<arch>/tls.{a,lib}`.
|
|
21
|
+
The bridge and the backend are the only tracked sources, so an installed npm
|
|
22
|
+
package compiles a TLS-using program without the vendored headers. Without the
|
|
23
|
+
archive the modules still import, but the calls throw a clear runtime error;
|
|
24
|
+
`--feature tls` turns the missing archive into a build error.
|
|
25
|
+
|
|
26
|
+
| API | Notes |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `tls.connect(options[, callback])` | `options`: `port`, `host`, `servername`, `ca`, `cert`, `key`, `rejectUnauthorized`, `ALPNProtocols`. Also `connect(port[, host][, options][, callback])` |
|
|
29
|
+
| `tls.createServer(options[, onSecure])` | `options`: `cert`, `key`, `ca`, `requestCert`, `rejectUnauthorized`, `ALPNProtocols`; reuses `net.Server` for `listen` / `address` / `close` |
|
|
30
|
+
| `tls.TLSSocket` | EventEmitter with `write` / `end` / `destroy` / `address` / `setEncoding` / `getPeerCertificate`; emits `data`, `end`, `close`, `error` |
|
|
31
|
+
|
|
32
|
+
`connect` performs the TCP connect and TLS handshake synchronously, then returns
|
|
33
|
+
an already-secure socket. `secureConnect` and the callback are delivered on a
|
|
34
|
+
zero-delay timer, so they run after the `const socket = connect(...)` binding is
|
|
35
|
+
initialised, matching Node's ordering. The socket's readiness watcher decrypts
|
|
36
|
+
records on the reactor; writes block only for the duration of one record.
|
|
37
|
+
|
|
38
|
+
## Certificate verification
|
|
39
|
+
|
|
40
|
+
- `rejectUnauthorized` defaults to `true`. A supplied `ca` (PEM string or
|
|
41
|
+
Buffer) replaces the platform trust store; without one, Windows reads its
|
|
42
|
+
`ROOT` store through crypt32, Linux reads `ca-certificates.crt` /
|
|
43
|
+
`ca-bundle.crt` (or `/etc/ssl/certs`), and macOS/BSD read
|
|
44
|
+
`/etc/ssl/cert.pem`.
|
|
45
|
+
- `NODE_EXTRA_CA_CERTS` names a PEM bundle trusted **in addition** to the
|
|
46
|
+
platform roots, like Node. The `tls` e2e tests use it with a self-signed
|
|
47
|
+
fixture.
|
|
48
|
+
- `servername` defaults to `host` and is used for SNI and hostname verification.
|
|
49
|
+
|
|
50
|
+
## Known limits
|
|
51
|
+
|
|
52
|
+
`createServer` looks exactly like `net.Server` but performs the handshake on the
|
|
53
|
+
accept path (the runtime has no separate TLS thread). There is no session
|
|
54
|
+
resumption, 0-RTT, or TLS-over-a-preconnected-`net`-socket constructor: a
|
|
55
|
+
`TLSSocket` wraps a connection the module itself opened or accepted. PEM inputs
|
|
56
|
+
must be strings or Buffers; `key` and `cert` must be supplied together.
|
package/doc/implemented/node.md
CHANGED
|
@@ -29,6 +29,8 @@ work on another. Missing or different behaviour is recorded under
|
|
|
29
29
|
| `net` | [net](./node/net.md) | TCP server and client |
|
|
30
30
|
| `dgram` | [dgram](./node/dgram.md) | UDP sockets |
|
|
31
31
|
| `http` | [http](./node/http.md) | server and client, `Connection: close` |
|
|
32
|
+
| `tls` | [tls](./node/tls.md) | mbedTLS client/server (`node-tls` link feature) |
|
|
33
|
+
| `http2` | [http2](./node/http2.md) | nghttp2 h2c and TLS/ALPN (`http2` link feature) |
|
|
32
34
|
| `child_process` | [child_process](./node/child-process.md) | `spawnSync` / `spawn` / `execFile` / `execSync` |
|
|
33
35
|
| `events` | [events](./node/events.md) | `EventEmitter` (global and named export) |
|
|
34
36
|
| `util` | [util](./node/util.md) | formatting, inspection and predicates |
|
|
@@ -48,6 +50,12 @@ Additional small modules are provided with their core surface: `timers`
|
|
|
48
50
|
(`StringDecoder`), `diagnostics_channel` (`channel`/`tracingChannel`), and
|
|
49
51
|
`util/types` (the type predicates).
|
|
50
52
|
|
|
53
|
+
`tls` and `http2` are implemented as optional **link features** backed by the
|
|
54
|
+
vendored mbedTLS and nghttp2 libraries: `npm run tls` fetches and builds
|
|
55
|
+
`runtime/lib/<os>-<arch>/{tls,nghttp2}.{a,lib}`, and the driver links them only
|
|
56
|
+
when the program may use them. A checkout without those archives still compiles,
|
|
57
|
+
but the calls report a clear runtime error until `npm run tls` has run.
|
|
58
|
+
|
|
51
59
|
## Where does a change belong?
|
|
52
60
|
|
|
53
61
|
A Node module change normally touches `src/extensions/node/<module>/` and
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Storage (localStorage / sessionStorage / indexedDB)
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/storage.md)
|
|
4
|
+
|
|
5
|
+
The three browser storage globals — `localStorage`, `sessionStorage` and
|
|
6
|
+
`indexedDB` — are always available (they are core globals), backed by a
|
|
7
|
+
vendored SQLite (`vendor/sqlite3`, fetched by `npm run vendor`). No extension
|
|
8
|
+
flag is needed.
|
|
9
|
+
|
|
10
|
+
## Backend selection
|
|
11
|
+
|
|
12
|
+
The backend is chosen at build time from the `storage` object in
|
|
13
|
+
`xbintsc.config.json`; it defaults to an **in-memory** SQLite database:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{ "storage": { "backend": "memory" } }
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{ "storage": { "backend": "file", "path": "data/app.db" } }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`storage.path` resolves against the config file's directory (absolute paths are
|
|
24
|
+
used as-is). `sessionStorage` is **always** in-memory regardless of the backend,
|
|
25
|
+
because a session never outlives the process; `localStorage` and `indexedDB`
|
|
26
|
+
follow the configured backend. The driver embeds the resolved backend and path
|
|
27
|
+
as a small object the runtime reads at first use (`src/driver/storage.ts`).
|
|
28
|
+
|
|
29
|
+
## It is a link feature
|
|
30
|
+
|
|
31
|
+
SQLite is heavy, so the whole implementation is a **link feature** named
|
|
32
|
+
`storage`, declared by the always-on core extension: the driver scans the
|
|
33
|
+
bundled program and links it only when the code may reach one of the three
|
|
34
|
+
globals. A program that never touches storage pays nothing for SQLite.
|
|
35
|
+
`--feature storage` forces the backend on (for storage reached through names
|
|
36
|
+
the scan cannot see) and `--no-feature storage` keeps it out.
|
|
37
|
+
|
|
38
|
+
## Surface
|
|
39
|
+
|
|
40
|
+
| Global | Notes |
|
|
41
|
+
| --- | --- |
|
|
42
|
+
| `localStorage` | `getItem` / `setItem` / `removeItem` / `clear` / `key(i)` / `length`, backed by the configured backend. |
|
|
43
|
+
| `sessionStorage` | the same surface, always in-memory. |
|
|
44
|
+
| `indexedDB` | `open(name, version?)`, `deleteDatabase(name)`; databases with `createObjectStore` / `deleteObjectStore` / `transaction`; object stores with `put` / `add` / `get` / `getAll` / `getKey` / `delete` / `clear` / `count`; requests with `onsuccess` / `onerror` / `onupgradeneeded` / `result` / `error`. |
|
|
45
|
+
|
|
46
|
+
IndexedDB requests settle from a microtask, so the `onsuccess` / `onerror` /
|
|
47
|
+
`onupgradeneeded` handlers fire asynchronously like the browser. Values are
|
|
48
|
+
serialised as JSON; keys are canonicalised so a number key `5` and a string key
|
|
49
|
+
`"5"` stay distinct. `keyPath` and `autoIncrement` are supported on
|
|
50
|
+
`createObjectStore`.
|
|
51
|
+
|
|
52
|
+
## Limits
|
|
53
|
+
|
|
54
|
+
- The indexedDB subset is focused: no `index`, `IDBKeyRange`, cursors,
|
|
55
|
+
`createIndex`, or `count(key)`/`getAll(query, count)` filtering; `getAll`
|
|
56
|
+
returns the whole store and `count` the whole store.
|
|
57
|
+
- Transactions are not atomic — each object-store operation is committed
|
|
58
|
+
immediately — and `abort` is not implemented.
|
|
59
|
+
- JSON serialisation means non-JSON values (`undefined`, functions, `Date`
|
|
60
|
+
identity) round-trip as `null` or are dropped.
|
|
61
|
+
- The key returned by `key(i)` / `objectStoreNames` uses insertion order
|
|
62
|
+
(`rowid`); re-setting a Web Storage key keeps its original position.
|
|
63
|
+
- The `gui` extension keeps `window.localStorage` as its engine's own in-memory
|
|
64
|
+
store; the bare `localStorage` global (and `sessionStorage` / `indexedDB`)
|
|
65
|
+
are the SQLite-backed globals described here.
|
package/doc/implemented.md
CHANGED
|
@@ -38,14 +38,15 @@ small file instead of a single monolithic document.
|
|
|
38
38
|
- [Collections](./implemented/collections.md) — Map, Set, WeakMap, WeakSet, WeakRef, iteration
|
|
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
|
-
- [fetch](./implemented/fetch.md) — reactor-driven HTTP/1.1 client and Headers
|
|
41
|
+
- [fetch](./implemented/fetch.md) — reactor-driven HTTP/1.1 client (HTTP and HTTPS) and Headers
|
|
42
42
|
- [WebAssembly](./implemented/wasm.md) — the `WebAssembly` namespace surface (bytecode execution is not implemented)
|
|
43
43
|
|
|
44
44
|
### Modules and tooling
|
|
45
45
|
|
|
46
46
|
- [Module system](./implemented/modules.md) — import/export, bundling, `node_modules`, `import.meta`
|
|
47
47
|
- [Extension mechanism](./implemented/extensions.md) — registry, the `node` extension, native C++/Rust extensions
|
|
48
|
-
- [Node extension](./implemented/node.md) —
|
|
48
|
+
- [Node extension](./implemented/node.md) — 24 Node built-in modules, one page per module
|
|
49
|
+
- [Storage extension](./implemented/storage.md) — SQLite-backed `localStorage`, `sessionStorage` and `indexedDB`
|
|
49
50
|
- [Driver, incremental compilation and toolchain](./implemented/driver.md) — cache, clang/LTO/PGO, config, icons
|
|
50
51
|
- [CLI and programmatic API](./implemented/cli.md) — commands, flags, embedder API
|
|
51
52
|
- [Tests](./implemented/tests.md) — unit, e2e and the differential harness
|
|
@@ -74,6 +75,7 @@ same file.
|
|
|
74
75
|
| import/export and bundling | [Modules](./implemented/modules.md) |
|
|
75
76
|
| extension registry or the `node` extension | [Extensions](./implemented/extensions.md) |
|
|
76
77
|
| a specific Node module (`fs`, `path`, `http`, ...) | [Node extension](./implemented/node.md) |
|
|
78
|
+
| `localStorage` / `sessionStorage` / `indexedDB` | [Storage extension](./implemented/storage.md) |
|
|
77
79
|
| build cache, clang, LTO/PGO, config, icons | [Driver](./implemented/driver.md) |
|
|
78
80
|
| CLI flags or the embedder API | [CLI](./implemented/cli.md) |
|
|
79
81
|
| tests and the differential harness | [Tests](./implemented/tests.md) |
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
The following Node built-in modules have no corresponding extension / builtin
|
|
6
6
|
(`fs` / `fs/promises` / `path` / `os` / `process` / `buffer` / `stream` /
|
|
7
|
-
`dgram` / `http` / `
|
|
8
|
-
`test` are implemented, and `crypto` / `url` /
|
|
9
|
-
`stream/promises` / `worker_threads` are partially
|
|
10
|
-
[implemented: Node extension](../../implemented/node.md)):
|
|
7
|
+
`dgram` / `http` / `tls` / `http2` / `events` / `util` / `querystring` /
|
|
8
|
+
`readline` / `assert` / `test` are implemented, and `crypto` / `url` /
|
|
9
|
+
`child_process` / `zlib` / `stream/promises` / `worker_threads` are partially
|
|
10
|
+
implemented; see [implemented: Node extension](../../implemented/node.md)):
|
|
11
11
|
|
|
12
12
|
| Module | Notes |
|
|
13
13
|
| --- | --- |
|
|
14
|
-
| `https` | TLS version of HTTP |
|
|
15
|
-
| `
|
|
14
|
+
| `https` | TLS version of HTTP; use `http2` or `tls` directly, or `fetch` for `https://` |
|
|
15
|
+
| `cluster` / `vm` | other core modules not listed |
|
|
16
16
|
|
|
17
17
|
> `crypto` (only `createHash`, now with the streaming API), `url` (only
|
|
18
18
|
> `pathToFileURL` / `fileURLToPath`), `child_process` (only `spawnSync` /
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
| Type checker | partial: the default [semantic checker](../implemented/checker.md) reports unresolved names, redeclarations, call arity, property existence and definite assignability mismatches, with structural interfaces/classes, simple generics and basic flow narrowing; there is no full inference or strict-null pass |
|
|
10
10
|
| Full standard library | partial: Math / JSON / Date / Map / Set / RegExp / `Error` / `BigInt` / `Symbol` / `structuredClone` implemented; String.normalize missing |
|
|
11
11
|
| Multi-file module bundling | partial: relative-path `.ts` bundling, ESM `node_modules` packages, namespace imports and bare-specifier extension module imports implemented; CommonJS is handled only inside `node_modules`; circular dependencies / live bindings are not implemented |
|
|
12
|
-
| Real async runtime | ✓ `async`/`await` suspends on pending promises on the `select(2)` reactor: timers, TCP sockets, offloaded file/HTTP work and promise callbacks resume the coroutine. Still missing: real OS-level file watching, non-blocking `net.connect`,
|
|
12
|
+
| Real async runtime | ✓ `async`/`await` suspends on pending promises on the `select(2)` reactor: timers, TCP sockets, offloaded file/HTTP work and promise callbacks resume the coroutine. Still missing: real OS-level file watching, non-blocking `net.connect`, and user-visible worker threads (`worker_threads` uses child processes) |
|
|
13
13
|
| Windows binary artifact verification | adapted at the build layer (`.exe` suffix, link flag branch), verified in CI |
|
|
14
14
|
| Precise ECMAScript number / string / comparison semantics | partial, see [Runtime deviations](./deviations.md) |
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"features": {
|
|
52
52
|
"type": "array",
|
|
53
53
|
"items": { "type": "string" },
|
|
54
|
-
"description": "Optional link features to force on, e.g. [\"media\", \"gpu\", \"images\", \"shaping\", \"webgl\"] or [\"all\"]."
|
|
54
|
+
"description": "Optional link features to force on, e.g. [\"media\", \"gpu\", \"images\", \"shaping\", \"webgl\", \"storage\"] or [\"all\"]."
|
|
55
55
|
},
|
|
56
56
|
"noFeatures": {
|
|
57
57
|
"type": "array",
|
|
@@ -62,6 +62,21 @@
|
|
|
62
62
|
"type": "boolean",
|
|
63
63
|
"description": "Ignore the incremental cache."
|
|
64
64
|
},
|
|
65
|
+
"storage": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"description": "Storage backend for the storage extension (localStorage, sessionStorage, indexedDB). Defaults to memory.",
|
|
68
|
+
"additionalProperties": false,
|
|
69
|
+
"properties": {
|
|
70
|
+
"backend": {
|
|
71
|
+
"enum": ["memory", "file"],
|
|
72
|
+
"description": "Where the database lives. Default: memory (an in-memory SQLite database)."
|
|
73
|
+
},
|
|
74
|
+
"path": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"description": "Database file path for backend: file, resolved against this config's directory (absolute paths are used as-is)."
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
65
80
|
"app": {
|
|
66
81
|
"type": "object",
|
|
67
82
|
"description": "Application metadata and packaging.",
|
package/doc/zh-CN/gui/api.md
CHANGED
|
@@ -101,7 +101,7 @@ requestAnimationFrame(frame);
|
|
|
101
101
|
| `navigator` | `userAgent`(以 `xbintsc` 结尾的桌面 Chrome 字符串)、`platform`、`vendor`、`language(s)`、`hardwareConcurrency`、`maxTouchPoints`、`onLine`、`vibrate()` |
|
|
102
102
|
| `localStorage` | 内存中的 `getItem` / `setItem` / `removeItem` / `clear` / `key` / `length` |
|
|
103
103
|
| `AudioContext`、`webkitAudioContext` | 带真实混音器与解码器的 Web Audio 图(见下) |
|
|
104
|
-
| `fetch(input, init)` | 核心运行时的 HTTP/1.1 客户端,GUI 程序同样可用:支持 `http
|
|
104
|
+
| `fetch(input, init)` | 核心运行时的 HTTP/1.1 客户端,GUI 程序同样可用:支持 `http://` 与 `https://`(后者链接可选的 `tls` 特性)、本地 `file://` 与相对路径;响应整体缓冲。见[已实现的 fetch](../../implemented/fetch.md)。 |
|
|
105
105
|
| `Event`、`CustomEvent`、`ProgressEvent`、`MouseEvent`、`KeyboardEvent`、`PointerEvent`、`WheelEvent`、`FocusEvent`、`InputEvent`、`SubmitEvent` | 事件构造器;`init` 参数按原样保留(`detail`、`composed`、鼠标/键盘字段等) |
|
|
106
106
|
| `AbortController`、`AbortSignal` | 真实的 controller/signal 对,用于 `{ signal }` 移除监听器,支持 `abort()`、`aborted`、`reason`、`onabort` 与 `throwIfAborted()` |
|
|
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))。 |
|
package/doc/zh-CN/gui/build.md
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
> 属于 [GUI 扩展](../gui.md) 的一部分;引擎总览、锁定决策与路线图在那里。
|
|
6
6
|
|
|
7
7
|
- 源码位于 `runtime/ext_gui/`(C/C++),外加 `vendor/` 下的 vendored 库
|
|
8
|
-
(被 gitignore
|
|
8
|
+
(被 gitignore;按需获取)。`npm run vendor` 获取固定版本的 stb/NanoSVG 头文件
|
|
9
|
+
(以及链接特性要编译的 miniz/SQLite 源码);`npm run gui` 只获取它需要的两组
|
|
10
|
+
头文件。媒体解码位于 `runtime/xt_media/`,单独构建。
|
|
9
11
|
- `npm run gui`(`scripts/build-gui.ts`)获取固定版本的 SDL3(`SDL3_TAG`,
|
|
10
12
|
默认 `release-3.2.10`),构建静态 SDL3,获取并构建静态 **FreeType**
|
|
11
13
|
(`FREETYPE_VERSION`,默认 `2.13.3`)与 **HarfBuzz**(`HARFBUZZ_VERSION`,
|
|
@@ -17,7 +19,7 @@
|
|
|
17
19
|
MSL(见 [WebGL](./webgl.md)),两者都与其他库一样合并进归档。Metal 是唯一消费
|
|
18
20
|
MSL 的 SDL_GPU 后端,因此 Windows/Linux 上脚本既不获取也不合并 SPIRV-Cross:
|
|
19
21
|
那里的 `webgl_msl.cpp` 编译为空,合并进来只会多出约 2.5 MiB 不可达代码。
|
|
20
|
-
默认文本路径使用内置的 **stb_truetype**(`
|
|
22
|
+
默认文本路径使用内置的 **stb_truetype**(`vendor/stb/stb_truetype.h`);
|
|
21
23
|
HarfBuzz/FreeType 只在 `shaping` 特性启用时被取出。
|
|
22
24
|
每个库(SDL3、FreeType、HarfBuzz、glslang、SPIRV-Cross 与引擎)都用
|
|
23
25
|
`-ffunction-sections -fdata-sections` 编译;SDL 关闭引擎从不调用的子系统
|
|
@@ -37,7 +39,7 @@
|
|
|
37
39
|
- `npm run media`(`scripts/build-media.ts`)构建可选的 **FFmpeg** 后端。它获取
|
|
38
40
|
FFmpeg(`FFMPEG_VERSION`,默认 `7.1`),配置一个只启用媒体元素所需
|
|
39
41
|
demuxer/parser/decoder 的最小静态构建,用它编译
|
|
40
|
-
`runtime/
|
|
42
|
+
`runtime/xt_media/media.cpp`,并把所有内容合并到
|
|
41
43
|
`runtime/lib/<os>-<arch>/media.a`(Windows 上 MSVC ABI 则为 `media.lib`)。
|
|
42
44
|
下载会重试发布主机常见的瞬时 TLS 故障;解压后 tarball 保留为
|
|
43
45
|
`vendor/ffmpeg-<version>.tar.xz`,因此重建(或按 `FFMPEG_VERSION` 缓存它的
|
|
@@ -121,7 +123,7 @@ markup 会让程序按“动态 markup”保守处理,启用可选特性。
|
|
|
121
123
|
|
|
122
124
|
特性启用时,driver 只为本构建编译它的 C **bridge**,并链接在 `gui.a` 之前:
|
|
123
125
|
|
|
124
|
-
- `media` → `runtime/
|
|
126
|
+
- `media` → `runtime/xt_media/media_bridge.c`;构造函数安装解码表并引用
|
|
125
127
|
`xt_media_backend_*`,从而把 FFmpeg 成员从 `media.a` 里取出。
|
|
126
128
|
- `gpu` → `runtime/ext_gui/gpu_bridge.c`;构造函数调用 `gpu_feature.cpp` 里的
|
|
127
129
|
`xt_gpu_feature_register`,安装 `XtGpuShaderApi` 表并引用 `compile_glsl` /
|
package/doc/zh-CN/gui/media.md
CHANGED
|
@@ -70,8 +70,8 @@ opacity、`display`——与任何其他元素一样。盒子内部的艺术内
|
|
|
70
70
|
声明播放器接口,并通过媒体后端在启动时安装的函数表分发
|
|
71
71
|
(`runtime/ext_gui/media_api.h`)。
|
|
72
72
|
- **`media`**(`media.a`,Windows 上 MSVC ABI 则为 `media.lib`;
|
|
73
|
-
`runtime/
|
|
74
|
-
封装静态 vendored 的 **FFmpeg** 构建,`runtime/
|
|
73
|
+
`runtime/xt_media/`)是可选的解码后端:`runtime/xt_media/media.cpp`
|
|
74
|
+
封装静态 vendored 的 **FFmpeg** 构建,`runtime/xt_media/media_bridge.c`
|
|
75
75
|
把它注册进引擎。编译器在程序可能用到媒体时(导入 HTML 里的
|
|
76
76
|
`<video>`/`<audio>`、`createElement("video"/"audio")`、`new Audio()`、
|
|
77
77
|
`decodeAudioData`,或运行时拼出的 HTML)自动选中该特性,只在那时才编译
|
|
@@ -104,7 +104,7 @@ opacity、`display`——与任何其他元素一样。盒子内部的艺术内
|
|
|
104
104
|
- **线程。** 引擎是单线程且非线程感知,因此所有解码都在主线程的
|
|
105
105
|
`xt_gui_media_tick` 内完成——没有解码线程,也没有跨线程 GC 暴露。
|
|
106
106
|
- **`decodeAudioData`。** 同一套 FFmpeg 还会为 `AudioContext.decodeAudioData`
|
|
107
|
-
解码内存中的音频文件(`runtime/
|
|
107
|
+
解码内存中的音频文件(`runtime/xt_media/decode_audio.cpp`,经媒体表分发);
|
|
108
108
|
WAV 由 GUI 引擎自身处理(`audio_decode.cpp`),因此只有压缩格式需要该扩展。
|
|
109
109
|
- **DOM API。** 元素句柄直接暴露媒体接口(见
|
|
110
110
|
`runtime/ext_gui/dom_api_media.cpp` 与 `dom_api_proto.cpp` 中的原型):
|
|
@@ -154,7 +154,7 @@ shader 合成到场景上。全部十六种 CSS 模式(`multiply`、`screen`
|
|
|
154
154
|
## 文本技术栈(M4b)
|
|
155
155
|
|
|
156
156
|
`runtime/ext_gui/text.{h,cpp}` 是前端,通过一个小型后端表分发。默认后端是内置的
|
|
157
|
-
**stb_truetype**(`text_stb.cpp`、`
|
|
157
|
+
**stb_truetype**(`text_stb.cpp`、`vendor/stb/stb_truetype.h`)。可选的
|
|
158
158
|
**`shaping`** 链接特性会安装 `text_hb.cpp`(HarfBuzz + FreeType 后端),非 ASCII
|
|
159
159
|
文本或作者的 `@font-face` 规则会自动选中它。两个后端共享 `text_font_db.cpp` 中的
|
|
160
160
|
字体数据库(发现与索引)、`text_fonts.cpp` 中的 CSS 匹配器和
|
package/doc/zh-CN/gui.md
CHANGED
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
`vulkan-sdk-1.4.313.0`、FFmpeg `7.1`(供可选的 `media` 归档使用;可用
|
|
100
100
|
`SDL3_TAG` / `FREETYPE_VERSION` / `HARFBUZZ_VERSION` / `GLSLANG_VERSION` /
|
|
101
101
|
`SPIRV_CROSS_VERSION` / `FFMPEG_VERSION` 覆盖)。默认文本后端是内置的
|
|
102
|
-
`stb_truetype.h`;它只接受 TrueType 轮廓(不支持 CFF/OTF 或可变字体)。
|
|
102
|
+
`vendor/stb/stb_truetype.h`;它只接受 TrueType 轮廓(不支持 CFF/OTF 或可变字体)。
|
|
103
103
|
`shaping` 特性会换成 HarfBuzz + FreeType,提供完整 OpenType 整形。
|
|
104
104
|
|
|
105
105
|
如果否决 SDL3,备选是 **GLFW + OpenGL 3.3**(更简单,但 OpenGL 在 macOS 上
|
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
- `win.stats()` 暴露引擎计数器;e2e 覆盖见
|
|
218
218
|
`tests/e2e/gui-retention.test.ts`(见[内存与 GC](./gui/runtime.md))。
|
|
219
219
|
13. **M13 — 视频与音频** ✅
|
|
220
|
-
- `<video>` / `<audio>` 通过可选的 `media` **链接特性**(`runtime/
|
|
220
|
+
- `<video>` / `<audio>` 通过可选的 `media` **链接特性**(`runtime/xt_media/media.cpp`)
|
|
221
221
|
使用静态 vendored 的最小 FFmpeg 解码。编译器从程序里检测到媒体用法时才编译
|
|
222
222
|
`media_bridge.c` 并链接 `media.a`,只做 DOM/CSS 的程序不会链接 FFmpeg。
|
|
223
223
|
帧沿用现有图像管线上传到 GPU 纹理,
|
|
@@ -405,7 +405,7 @@
|
|
|
405
405
|
最小化的静态 FFmpeg(`scripts/build-media.ts`),合并进 `media.a`。编译器从程序里
|
|
406
406
|
选中该特性后才编译 `media_bridge.c` 并链接 `media.a`;只做 DOM/CSS 的程序不会链接
|
|
407
407
|
FFmpeg。
|
|
408
|
-
`runtime/
|
|
408
|
+
`runtime/xt_media/media.cpp` 在主线程把视频解码为 RGBA 帧、把音频解码为
|
|
409
409
|
48 kHz 立体声 PCM,`runtime/ext_gui/gui_media.cpp` 持有播放器、实现 SDL 音频
|
|
410
410
|
sink 并在每帧推进媒体时钟与事件,`renderer_image.cpp` 把每个新视频帧沿图像纹理
|
|
411
411
|
路径上传,`dom_api_media.cpp` 在元素句柄上暴露 `play`/`pause`/`load` 与媒体
|
|
@@ -47,4 +47,4 @@
|
|
|
47
47
|
- `fetch` 把每一跳请求/重定向作为 job 执行;`fs/promises` 把每个文件与描述符操作作为 job 执行。两者都不会阻塞定时器、套接字或其他 `await`。
|
|
48
48
|
- 仍有 job 未完成时事件循环保持存活(`xt_loop_has_work`),线程池空闲后退出。
|
|
49
49
|
|
|
50
|
-
异步表面的已知限制(`fetch`
|
|
50
|
+
异步表面的已知限制(`fetch` 无流式/abort、`fs.watch` 不触发、线程池固定 4 个 worker)列在[运行时偏差](../unimplemented/deviations.md)与各 Node 页面。
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
- driver 从打包后的 AST 构造 `ProgramUsage`(`src/driver/usage.ts` 的 `collectUsage`):字符串字面量(含导入 HTML 与内联 CSS)、标识符/属性名、`getContext(...)` 的 kind,以及 markup 是否可能在运行时拼出。简单的 `const` 别名会被解析;无法解析的 markup 让程序走保守回退。
|
|
12
12
|
- `resolveLinkFeatures` 应用 `--feature` / `--no-feature`(以及 `all`),展开 `requires`,把自动检测到但不可用的特性报为 warning、把强制开启却不可用的报为 error,并返回要链接的 bridge/归档/参数。
|
|
13
13
|
- bridge 就是强引用:构造函数安装特性的分发表,其引用迫使链接器取出实现;没有 bridge 时表保持 null,实现成员永不被链接。
|
|
14
|
-
- 当前客户端:`media`(FFmpeg,`runtime/
|
|
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`,因为这些全局变量本身就是强引用)。
|
|
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` 构建两个归档)。
|
|
15
16
|
- 内置核心扩展 `core`:暴露 `print`(映射 `xt_println`),始终注册。
|
|
16
17
|
- Node 扩展 `node`:
|
|
17
18
|
- 模块化组织:`src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
实现位置:`runtime/xt_fetch.c`、`runtime/xt_fetch/async.inc`、`runtime/xt_async_io.c`。
|
|
6
6
|
|
|
7
|
-
- 全局 `fetch(input, init)`
|
|
7
|
+
- 全局 `fetch(input, init)` 是同时支持 `http://` 与 `https://` 的 HTTP/1.1 客户端。阻塞的套接字交换(`getaddrinfo`、connect、send、receive)运行在异步 I/O 工作线程池上,因此进行中的请求**不会**卡住事件循环:定时器、套接字与其他 `await` 继续运行,promise 在 reactor 派发完成结果时 settle。
|
|
8
8
|
- 重定向在主线程上处理:每一跳是一次 offload 交换,最多 20 次;301/302/303 会把 POST 改成 GET。
|
|
9
|
-
-
|
|
9
|
+
- 接受 `http://` 与 `https://` URL。HTTPS 由可选 `tls` 链接特性(随仓库引入的 mbedTLS)
|
|
10
|
+
提供:出现 `https://` 字面量(或传入 `--feature tls`)时编译器会选中它,从不发起
|
|
11
|
+
HTTPS 请求的程序不会付出体积代价。缺少归档时请求会以 `TypeError` 拒绝并说明缺失的特性。
|
|
12
|
+
证书按平台信任库校验(Windows `ROOT`、Linux CA 包、macOS `/etc/ssl/cert.pem`);
|
|
13
|
+
`NODE_EXTRA_CA_CERTS` 指定额外信任的 PEM 包,私有或自签名 CA 通过它使用。
|
|
14
|
+
`fetch` 的 `init` 不接受 `ca` 选项。
|
|
10
15
|
- **没有协议的引用**(相对路径)与 `file://` URL 会读取本地文件,因此编译后的程序
|
|
11
16
|
无需 HTTP 服务即可加载磁盘资源。相对路径相对工作目录解析;支持 `GET` / `HEAD`。
|
|
12
17
|
在 Windows 上,标准写法 `file:///C:/dir/file` 与 `file://C:/dir/file` /
|
|
@@ -32,4 +37,11 @@ setTimeout(() => console.log("timer"), 10); // 会在 150ms 的响应之前运
|
|
|
32
37
|
await pending;
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
|
|
40
|
+
链接 `tls` 特性后,HTTPS 请求的用法完全相同:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const response = await fetch("https://example.com/status");
|
|
44
|
+
console.log(response.status, await response.text());
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
已知限制(响应体整体缓冲、无流式与 abort signal)列在[运行时偏差](../unimplemented/deviations.md)。
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# `http2` 模块
|
|
2
|
+
|
|
3
|
+
> 属于[Node 扩展:已实现](../node.md) · [English](../../../implemented/node/http2.md)
|
|
4
|
+
|
|
5
|
+
实现位置:`src/extensions/node/http2/`、`runtime/ext_node/http2/`、`runtime/xt_http2/`
|
|
6
|
+
|
|
7
|
+
HTTP/2 分帧与 HPACK 来自随仓库引入的 nghttp2。导入 `http2` / `node:http2`
|
|
8
|
+
(或出现 `createSecureServer`)时选中 `http2` 链接特性;它 `requires:
|
|
9
|
+
["tls", "node-tls"]`,因为安全服务端复用 `node:tls` 的服务端封装,两种方案都通过
|
|
10
|
+
mbedTLS 协商 ALPN `h2`。`runtime/ext_node/http2/http2_backend.c` 被编译进固定版本的 nghttp2 归档
|
|
11
|
+
(`runtime/lib/<os>-<arch>/nghttp2.{a,lib}`);该特性编译的入口是
|
|
12
|
+
`http2_bridge.c`,它的调用会取出后端并完成安装。`npm run tls` 会同时构建该归档与
|
|
13
|
+
mbedTLS 归档,因此已安装的 npm 包不需要 vendor 头文件。
|
|
14
|
+
|
|
15
|
+
一个 `Http2Session` 拥有一个套接字和一个 `nghttp2_session`。运行时的可读 reactor
|
|
16
|
+
把字节送入 `nghttp2_session_mem_recv2` 并冲刷 `nghttp2_session_mem_send2` 的输出;
|
|
17
|
+
nghttp2 回调负责触发 JavaScript 事件。没有 HTTP/1.1 upgrade:明文 `http://` 连接
|
|
18
|
+
直接使用 h2c prior knowledge,与 Node 客户端一致。
|
|
19
|
+
|
|
20
|
+
| API | 说明 |
|
|
21
|
+
| --- | --- |
|
|
22
|
+
| `http2.connect(authority[, options][, listener])` | `http(s)://host:port`;`options`:`ca`、`rejectUnauthorized`;返回已连接的 `ClientHttp2Session` 并触发 `connect` |
|
|
23
|
+
| `session.request(headers[, options])` | `headers` 含 `:method`(默认 `GET`)、`:path`、`:scheme`、`:authority` 及普通字段;返回 `ClientHttp2Stream` |
|
|
24
|
+
| `stream.end([data])` / `write(data)` / `close()` | 请求体与取消;触发 `response(headers, flags)`、`data`、`end`、`close`、`error` |
|
|
25
|
+
| `session.close()` / `destroy()` | 发送 GOAWAY 并关闭传输 |
|
|
26
|
+
| `http2.createServer([options][, onRequest])` | 明文 h2c 服务端;`listen` / `address` / `close` 与 `net.Server` 一致 |
|
|
27
|
+
| `http2.createSecureServer(options[, onRequest])` | TLS + ALPN `h2`;`options` 需要 `cert` 与 `key`(客户端证书再加 `ca`) |
|
|
28
|
+
| `server.on("stream", (stream, headers) => …)` | 服务端 stream 同时具有请求事件与 `respond` / `setHeader` / `write` / `end` |
|
|
29
|
+
| `http2.constants` | 帧类型与错误码数值(`NGHTTP2_FLAG_END_STREAM`、`NGHTTP2_CANCEL` 等) |
|
|
30
|
+
|
|
31
|
+
服务端 stream 暴露 `method`、`url`、`scheme`、`authority`、`httpVersion`
|
|
32
|
+
(`"2.0"`)与 `headers`;`stream` 事件的第二个参数就是同一个 headers 对象。
|
|
33
|
+
`respond(statusOrHeaders[, headers])`(或 `respond({":status": 201})`)、
|
|
34
|
+
`setHeader` / `getHeader` 与 `write` / `end` 负责提交响应。请求体通过 `data` /
|
|
35
|
+
`end` 事件送达,也可在同一个 stream 对象上访问。
|
|
36
|
+
|
|
37
|
+
端到端测试双向验证互操作性:编译后的客户端连接 Node 的 `http2` 服务端(h2c 与 TLS),
|
|
38
|
+
以及 Node 客户端连接编译后的 `createServer` / `createSecureServer`。
|
|
39
|
+
|
|
40
|
+
## 已知限制
|
|
41
|
+
|
|
42
|
+
未实现 `pushStream`、trailers、extended CONNECT、会话池 / 连接复用、`stream.priority`
|
|
43
|
+
与流控调优。响应头与响应体在 `end()` 之前会缓冲(`end()` 时才提交响应),因此想流式
|
|
44
|
+
发送大 body 的处理函数仍可工作,但不会提前冲刷部分响应。
|