xbintsc 0.6.22 → 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.
Files changed (166) hide show
  1. package/AGENTS.md +5 -0
  2. package/dist/src/cli/help.d.ts +1 -1
  3. package/dist/src/driver/build-key.js +2 -1
  4. package/dist/src/driver/build-key.js.map +1 -1
  5. package/dist/src/driver/fingerprint.d.ts +11 -0
  6. package/dist/src/driver/fingerprint.js +25 -0
  7. package/dist/src/driver/fingerprint.js.map +1 -1
  8. package/dist/src/driver/link-features.js +36 -11
  9. package/dist/src/driver/link-features.js.map +1 -1
  10. package/dist/src/driver/paths.d.ts +10 -0
  11. package/dist/src/driver/paths.js +18 -0
  12. package/dist/src/driver/paths.js.map +1 -1
  13. package/dist/src/driver/runtime-objects.d.ts +1 -1
  14. package/dist/src/driver/runtime-objects.js +22 -6
  15. package/dist/src/driver/runtime-objects.js.map +1 -1
  16. package/dist/src/driver/toolchain.d.ts +1 -1
  17. package/dist/src/driver/toolchain.js +10 -1
  18. package/dist/src/driver/toolchain.js.map +1 -1
  19. package/dist/src/driver/version.d.ts +1 -1
  20. package/dist/src/driver/version.js +1 -1
  21. package/dist/src/extensions/node/http2/feature.d.ts +14 -0
  22. package/dist/src/extensions/node/http2/feature.js +28 -0
  23. package/dist/src/extensions/node/http2/feature.js.map +1 -0
  24. package/dist/src/extensions/node/http2/index.d.ts +5 -1
  25. package/dist/src/extensions/node/http2/index.js +6 -1
  26. package/dist/src/extensions/node/http2/index.js.map +1 -1
  27. package/dist/src/extensions/node/index.js +3 -1
  28. package/dist/src/extensions/node/index.js.map +1 -1
  29. package/dist/src/extensions/node/tls/feature.d.ts +12 -0
  30. package/dist/src/extensions/node/tls/feature.js +24 -0
  31. package/dist/src/extensions/node/tls/feature.js.map +1 -0
  32. package/dist/src/extensions/node/tls/index.d.ts +5 -1
  33. package/dist/src/extensions/node/tls/index.js +5 -1
  34. package/dist/src/extensions/node/tls/index.js.map +1 -1
  35. package/dist/src/extensions/node/zlib/compression.js +11 -6
  36. package/dist/src/extensions/node/zlib/compression.js.map +1 -1
  37. package/dist/src/extensions/registry.js +2 -1
  38. package/dist/src/extensions/registry.js.map +1 -1
  39. package/dist/src/extensions/storage.js +4 -3
  40. package/dist/src/extensions/storage.js.map +1 -1
  41. package/dist/src/extensions/tls.d.ts +26 -0
  42. package/dist/src/extensions/tls.js +46 -0
  43. package/dist/src/extensions/tls.js.map +1 -0
  44. package/dist/tests/driver/link-features.test.js +9 -0
  45. package/dist/tests/driver/link-features.test.js.map +1 -1
  46. package/dist/tests/e2e/fetch.test.js +3 -1
  47. package/dist/tests/e2e/fetch.test.js.map +1 -1
  48. package/dist/tests/e2e/http2.test.d.ts +7 -0
  49. package/dist/tests/e2e/http2.test.js +201 -0
  50. package/dist/tests/e2e/http2.test.js.map +1 -0
  51. package/dist/tests/e2e/net-helpers.d.ts +28 -0
  52. package/dist/tests/e2e/net-helpers.js +59 -0
  53. package/dist/tests/e2e/net-helpers.js.map +1 -0
  54. package/dist/tests/e2e/node-modules.test.js +3 -5
  55. package/dist/tests/e2e/node-modules.test.js.map +1 -1
  56. package/dist/tests/e2e/tls.test.d.ts +10 -0
  57. package/dist/tests/e2e/tls.test.js +197 -0
  58. package/dist/tests/e2e/tls.test.js.map +1 -0
  59. package/dist/tests/extensions/storage.test.js +3 -2
  60. package/dist/tests/extensions/storage.test.js.map +1 -1
  61. package/doc/ai/contributing.md +14 -0
  62. package/doc/ai/extensions.md +5 -3
  63. package/doc/ai/language-support.md +1 -1
  64. package/doc/ai/zh-CN/contributing.md +12 -0
  65. package/doc/ai/zh-CN/extensions.md +4 -2
  66. package/doc/ai/zh-CN/language-support.md +1 -1
  67. package/doc/gui/api.md +1 -1
  68. package/doc/gui/build.md +5 -3
  69. package/doc/gui/rendering.md +1 -1
  70. package/doc/gui.md +1 -1
  71. package/doc/implemented/async.md +1 -1
  72. package/doc/implemented/extensions.md +1 -0
  73. package/doc/implemented/fetch.md +19 -4
  74. package/doc/implemented/node/http2.md +51 -0
  75. package/doc/implemented/node/tls.md +56 -0
  76. package/doc/implemented/node.md +8 -0
  77. package/doc/implemented/storage.md +2 -1
  78. package/doc/implemented.md +2 -2
  79. package/doc/unimplemented/node/modules.md +6 -6
  80. package/doc/unimplemented/toolchain.md +1 -1
  81. package/doc/zh-CN/gui/api.md +1 -1
  82. package/doc/zh-CN/gui/build.md +4 -2
  83. package/doc/zh-CN/gui/rendering.md +1 -1
  84. package/doc/zh-CN/gui.md +1 -1
  85. package/doc/zh-CN/implemented/async.md +1 -1
  86. package/doc/zh-CN/implemented/extensions.md +1 -0
  87. package/doc/zh-CN/implemented/fetch.md +15 -3
  88. package/doc/zh-CN/implemented/node/http2.md +44 -0
  89. package/doc/zh-CN/implemented/node/tls.md +47 -0
  90. package/doc/zh-CN/implemented/node.md +7 -0
  91. package/doc/zh-CN/implemented/storage.md +2 -1
  92. package/doc/zh-CN/implemented.md +2 -2
  93. package/doc/zh-CN/unimplemented/node/modules.md +3 -3
  94. package/doc/zh-CN/unimplemented/toolchain.md +1 -1
  95. package/package.json +16 -8
  96. package/runtime/ext_node/http2/http2.c +25 -11
  97. package/runtime/ext_node/http2/http2_backend.c +48 -0
  98. package/runtime/ext_node/http2/http2_bridge.c +25 -0
  99. package/runtime/ext_node/http2/parts/api.inc +40 -0
  100. package/runtime/ext_node/http2/parts/client.inc +215 -0
  101. package/runtime/ext_node/http2/parts/common.inc +330 -0
  102. package/runtime/ext_node/http2/parts/events.inc +139 -0
  103. package/runtime/ext_node/http2/parts/server.inc +301 -0
  104. package/runtime/ext_node/http2/parts/streams.inc +254 -0
  105. package/runtime/ext_node/tls/parts/api.inc +38 -0
  106. package/runtime/ext_node/tls/parts/connect.inc +107 -0
  107. package/runtime/ext_node/tls/parts/helpers.inc +121 -0
  108. package/runtime/ext_node/tls/parts/server.inc +101 -0
  109. package/runtime/ext_node/tls/parts/socket.inc +171 -0
  110. package/runtime/ext_node/tls/tls.c +21 -13
  111. package/runtime/ext_node/tls/tls_backend.c +50 -0
  112. package/runtime/ext_node/zlib/{miniz/compression_bridge.c → compression_bridge.c} +1 -1
  113. package/runtime/xt_fetch/async.inc +19 -12
  114. package/runtime/xt_fetch/socket.inc +55 -0
  115. package/runtime/xt_fetch.c +3 -0
  116. package/runtime/xt_http2/nghttp2_compat.h +19 -0
  117. package/runtime/xt_http2/nghttp2_static.h +18 -0
  118. package/runtime/xt_http2_api.h +38 -0
  119. package/runtime/xt_node_tls_api.h +37 -0
  120. package/runtime/xt_protocol_registry.c +22 -0
  121. package/runtime/xt_storage/storage_internal.h +3 -3
  122. package/runtime/xt_tls/parts/api.inc +21 -0
  123. package/runtime/xt_tls/parts/client.inc +112 -0
  124. package/runtime/xt_tls/parts/io.inc +157 -0
  125. package/runtime/xt_tls/parts/server.inc +102 -0
  126. package/runtime/xt_tls/parts/setup.inc +146 -0
  127. package/runtime/xt_tls/tls_bridge.c +27 -0
  128. package/runtime/xt_tls/tls_core.c +39 -0
  129. package/runtime/xt_tls/tls_internal.h +73 -0
  130. package/runtime/xt_tls_api.h +73 -0
  131. package/scripts/build-gui.ts +8 -7
  132. package/scripts/build-tls.ts +248 -0
  133. package/scripts/check-file-length.ts +4 -25
  134. package/scripts/fetch-vendored.ts +244 -0
  135. package/scripts/package-release.ts +13 -3
  136. package/src/driver/build-key.ts +7 -1
  137. package/src/driver/fingerprint.ts +24 -0
  138. package/src/driver/link-features.ts +33 -11
  139. package/src/driver/paths.ts +20 -0
  140. package/src/driver/runtime-objects.ts +25 -6
  141. package/src/driver/toolchain.ts +11 -2
  142. package/src/driver/version.ts +1 -1
  143. package/src/extensions/node/http2/feature.ts +33 -0
  144. package/src/extensions/node/http2/index.ts +6 -1
  145. package/src/extensions/node/index.ts +3 -1
  146. package/src/extensions/node/tls/feature.ts +29 -0
  147. package/src/extensions/node/tls/index.ts +5 -1
  148. package/src/extensions/node/zlib/compression.ts +11 -6
  149. package/src/extensions/registry.ts +2 -1
  150. package/src/extensions/storage.ts +4 -3
  151. package/src/extensions/tls.ts +52 -0
  152. package/{runtime/ext_gui → vendor/stb}/stb_image.h +17 -1
  153. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.c +0 -0
  154. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz.h +0 -0
  155. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_common.h +0 -0
  156. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_export.h +0 -0
  157. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.c +0 -0
  158. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tdef.h +0 -0
  159. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.c +0 -0
  160. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_tinfl.h +0 -0
  161. /package/{runtime/ext_node/zlib → vendor}/miniz/miniz_zip.h +0 -0
  162. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvg.h +0 -0
  163. /package/{runtime/ext_gui → vendor/nanosvg}/nanosvgrast.h +0 -0
  164. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.c +0 -0
  165. /package/{runtime/xt_storage → vendor}/sqlite3/sqlite3.h +0 -0
  166. /package/{runtime/ext_gui → vendor/stb}/stb_truetype.h +0 -0
@@ -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`, `runtime/ext_gui/stb_truetype.h`). The optional **`shaping`**
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
 
@@ -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 (no TLS/streaming `fetch`, inert
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.
@@ -12,6 +12,7 @@ Location: `src/extensions/registry.ts`, `src/extensions/node/`, `src/extensions/
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
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`
@@ -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. The blocking socket exchange
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://` URLs only — `https://` rejects with a `TypeError` because
15
- no TLS backend is linked.
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
- Known limits (only `http://`, no TLS, buffered body) are listed in
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.
@@ -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
@@ -4,7 +4,8 @@
4
4
 
5
5
  The three browser storage globals — `localStorage`, `sessionStorage` and
6
6
  `indexedDB` — are always available (they are core globals), backed by a
7
- vendored SQLite (`runtime/xt_storage/sqlite3`). No extension flag is needed.
7
+ vendored SQLite (`vendor/sqlite3`, fetched by `npm run vendor`). No extension
8
+ flag is needed.
8
9
 
9
10
  ## Backend selection
10
11
 
@@ -38,14 +38,14 @@ 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) — 21 Node built-in modules, one page per module
48
+ - [Node extension](./implemented/node.md) — 24 Node built-in modules, one page per module
49
49
  - [Storage extension](./implemented/storage.md) — SQLite-backed `localStorage`, `sessionStorage` and `indexedDB`
50
50
  - [Driver, incremental compilation and toolchain](./implemented/driver.md) — cache, clang/LTO/PGO, config, icons
51
51
  - [CLI and programmatic API](./implemented/cli.md) — commands, flags, embedder API
@@ -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` / `events` / `util` / `querystring` / `readline` / `assert` /
8
- `test` are implemented, and `crypto` / `url` / `child_process` / `zlib` /
9
- `stream/promises` / `worker_threads` are partially implemented; see
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
- | `tls` / `cluster` / `vm` | other core modules not listed |
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`, TLS for `fetch`, and user-visible worker threads (`worker_threads` uses child processes) |
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) |
@@ -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://`、本地 `file://` 与相对路径;不支持 `https://` 与流式响应。见[已实现的 fetch](../../implemented/fetch.md)。 |
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))。 |
@@ -5,7 +5,9 @@
5
5
  > 属于 [GUI 扩展](../gui.md) 的一部分;引擎总览、锁定决策与路线图在那里。
6
6
 
7
7
  - 源码位于 `runtime/ext_gui/`(C/C++),外加 `vendor/` 下的 vendored 库
8
- (被 gitignore;按需获取)。媒体解码位于 `runtime/xt_media/`,单独构建。
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**(`runtime/ext_gui/stb_truetype.h`);
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 关闭引擎从不调用的子系统
@@ -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`、`runtime/ext_gui/stb_truetype.h`)。可选的
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 上
@@ -47,4 +47,4 @@
47
47
  - `fetch` 把每一跳请求/重定向作为 job 执行;`fs/promises` 把每个文件与描述符操作作为 job 执行。两者都不会阻塞定时器、套接字或其他 `await`。
48
48
  - 仍有 job 未完成时事件循环保持存活(`xt_loop_has_work`),线程池空闲后退出。
49
49
 
50
- 异步表面的已知限制(`fetch` 无 TLS/流式、`fs.watch` 不触发、线程池固定 4 个 worker)列在[运行时偏差](../unimplemented/deviations.md)与各 Node 页面。
50
+ 异步表面的已知限制(`fetch` 无流式/abort、`fs.watch` 不触发、线程池固定 4 个 worker)列在[运行时偏差](../unimplemented/deviations.md)与各 Node 页面。
@@ -12,6 +12,7 @@
12
12
  - `resolveLinkFeatures` 应用 `--feature` / `--no-feature`(以及 `all`),展开 `requires`,把自动检测到但不可用的特性报为 warning、把强制开启却不可用的报为 error,并返回要链接的 bridge/归档/参数。
13
13
  - bridge 就是强引用:构造函数安装特性的分发表,其引用迫使链接器取出实现;没有 bridge 时表保持 null,实现成员永不被链接。
14
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)` 是 HTTP/1.1 客户端。阻塞的套接字交换(`getaddrinfo`、connect、send、receive)运行在异步 I/O 工作线程池上,因此进行中的请求**不会**卡住事件循环:定时器、套接字与其他 `await` 继续运行,promise 在 reactor 派发完成结果时 settle。
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
- - 只接受 `http://` URL —— 由于未链接 TLS 后端,`https://` 会以 `TypeError` 拒绝。
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
- 已知限制(仅 `http://`、无 TLS、响应体整体缓冲)列在[运行时偏差](../unimplemented/deviations.md)。
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 的处理函数仍可工作,但不会提前冲刷部分响应。
@@ -0,0 +1,47 @@
1
+ # `tls` 模块
2
+
3
+ > 属于[Node 扩展:已实现](../node.md) · [English](../../../implemented/node/tls.md)
4
+
5
+ 实现位置:`src/extensions/node/tls/`、`runtime/ext_node/tls/`、`runtime/xt_tls/`
6
+
7
+ `node:tls` 由随仓库引入(vendored)的 mbedTLS 实现(TLS 1.2/1.3、X.509 与 PSA crypto)。
8
+ 两个链接特性使它保持可选:
9
+
10
+ - **`tls`**(由核心扩展声明)是 mbedTLS 传输层:`runtime/xt_tls/tls_core.c`
11
+ 被归档进 `tls.{a,lib}`,该特性编译的入口是极小的 `tls_bridge.c`,它的调用会取出
12
+ 后端并完成安装。`fetch` 的 `https://` 请求使用它。出现 `https://` 字面量、使用
13
+ `node:tls` / `node:http2`,或传入 `--feature tls` 时会选中。
14
+ - **`node-tls`**(`requires: ["tls"]`)在 `runtime/ext_node/tls/tls_backend.c`
15
+ 中提供 JavaScript 接口,导入 `tls` / `node:tls` 时选中(导入说明符在打包后是字符串字面量)。
16
+
17
+ `npm run tls` 把固定版本的 mbedTLS 下载到 `vendor/mbedtls`,与 `tls_core.c`
18
+ 一起编译,并写出 `runtime/lib/<os>-<arch>/tls.{a,lib}`。只有 bridge 与后端是受版本控制
19
+ 的源码,因此已安装的 npm 包无需 vendor 头文件即可编译使用 TLS 的程序。缺少归档时模块
20
+ 仍可导入,但调用会抛出明确的运行时错误;显式 `--feature tls` 则会让缺失的归档变成构建错误。
21
+
22
+ | API | 说明 |
23
+ | --- | --- |
24
+ | `tls.connect(options[, callback])` | `options`:`port`、`host`、`servername`、`ca`、`cert`、`key`、`rejectUnauthorized`、`ALPNProtocols`;也支持 `connect(port[, host][, options][, callback])` |
25
+ | `tls.createServer(options[, onSecure])` | `options`:`cert`、`key`、`ca`、`requestCert`、`rejectUnauthorized`、`ALPNProtocols`;`listen` / `address` / `close` 复用 `net.Server` |
26
+ | `tls.TLSSocket` | EventEmitter,含 `write` / `end` / `destroy` / `address` / `setEncoding` / `getPeerCertificate`;触发 `data`、`end`、`close`、`error` |
27
+
28
+ `connect` 同步完成 TCP 连接与 TLS 握手,返回的套接字已经安全。`secureConnect`
29
+ 与回调在零延迟定时器中触发,因此晚于 `const socket = connect(...)` 的赋值,
30
+ 与 Node 的时序一致。套接字的可读事件在 reactor 上解密记录;写入只在一个记录期间阻塞。
31
+
32
+ ## 证书校验
33
+
34
+ - `rejectUnauthorized` 默认为 `true`。传入的 `ca`(PEM 字符串或 Buffer)会替换平台
35
+ 信任库;未传时,Windows 通过 crypt32 读取 `ROOT` 存储,Linux 读取
36
+ `ca-certificates.crt` / `ca-bundle.crt`(或 `/etc/ssl/certs`),macOS/BSD 读取
37
+ `/etc/ssl/cert.pem`。
38
+ - `NODE_EXTRA_CA_CERTS` 指向的 PEM 包会在平台根证书之外**额外**被信任,与 Node 一致。
39
+ `tls` 端到端测试用自签名证书夹具配合它运行。
40
+ - `servername` 默认取 `host`,用于 SNI 与主机名校验。
41
+
42
+ ## 已知限制
43
+
44
+ `createServer` 的外观与 `net.Server` 一致,但在 accept 路径上完成握手(运行时没有独立的
45
+ TLS 线程)。不支持会话恢复、0-RTT,也没有基于已连接 `net` 套接字的 `TLSSocket`
46
+ 构造器:`TLSSocket` 只包裹本模块建立或接受的连接。PEM 输入必须是字符串或 Buffer;
47
+ `key` 与 `cert` 必须同时提供。
@@ -27,6 +27,8 @@ TypeScript 导出与 C 实现一一对应。新增模块不需要改动核心编
27
27
  | `net` | [net](./node/net.md) | TCP 服务端与客户端 |
28
28
  | `dgram` | [dgram](./node/dgram.md) | UDP 套接字 |
29
29
  | `http` | [http](./node/http.md) | 服务端与客户端,`Connection: close` |
30
+ | `tls` | [tls](./node/tls.md) | mbedTLS 客户端/服务端(`node-tls` 链接特性) |
31
+ | `http2` | [http2](./node/http2.md) | nghttp2 h2c 与 TLS/ALPN(`http2` 链接特性) |
30
32
  | `child_process` | [child_process](./node/child-process.md) | `spawnSync` / `spawn` / `execFile` / `execSync` |
31
33
  | `events` | [events](./node/events.md) | `EventEmitter`(全局与具名导出) |
32
34
  | `util` | [util](./node/util.md) | 格式化、inspect 与类型谓词 |
@@ -39,6 +41,11 @@ TypeScript 导出与 C 实现一一对应。新增模块不需要改动核心编
39
41
  | `zlib` | [zlib](./node/zlib.md) | 仅 `createGzip` |
40
42
  | `worker_threads` | [worker_threads](./node/worker-threads.md) | 以子进程模拟 |
41
43
 
44
+ `tls` 与 `http2` 以可选**链接特性**实现,底层是随仓库引入的 mbedTLS 与 nghttp2:
45
+ `npm run tls` 会下载并构建 `runtime/lib/<os>-<arch>/{tls,nghttp2}.{a,lib}`,
46
+ 驱动只在程序可能用到它们时才链接。没有这些归档的检出仍可编译,但在运行
47
+ `npm run tls` 之前调用会返回明确的运行时错误。
48
+
42
49
  ## 改动应该写在哪一页?
43
50
 
44
51
  Node 模块改动通常涉及 `src/extensions/node/<module>/` 与 `runtime/ext_node/<module>/`;
@@ -3,7 +3,8 @@
3
3
  > 属于[已实现语法与功能](../implemented.md) · [English](../../implemented/storage.md)
4
4
 
5
5
  三个浏览器存储全局变量 —— `localStorage`、`sessionStorage` 与 `indexedDB` —— **始终可用**
6
- (它们是核心全局),由内置的 SQLite(`runtime/xt_storage/sqlite3`)支撑。无需任何扩展开关。
6
+ (它们是核心全局),由内置的 SQLite(`vendor/sqlite3`,由 `npm run vendor` 获取)支撑。
7
+ 无需任何扩展开关。
7
8
 
8
9
  ## 后端选择
9
10
 
@@ -32,14 +32,14 @@
32
32
  - [集合](./implemented/collections.md) —— Map、Set、WeakMap、WeakSet、WeakRef、迭代
33
33
  - [类型化数组与二进制数据](./implemented/typed-arrays.md) —— 类型化数组、ArrayBuffer、DataView
34
34
  - [异步、Promise 与生成器](./implemented/async.md) —— async/await、异步生成器、Promise、定时器
35
- - [fetch](./implemented/fetch.md) —— 由 reactor 驱动的 HTTP/1.1 客户端与 Headers
35
+ - [fetch](./implemented/fetch.md) —— 由 reactor 驱动的 HTTP/1.1 客户端(HTTP 与 HTTPS)与 Headers
36
36
  - [WebAssembly](./implemented/wasm.md) —— `WebAssembly` 命名空间表面(字节码执行尚未实现)
37
37
 
38
38
  ### 模块与工具
39
39
 
40
40
  - [模块系统](./implemented/modules.md) —— import/export、打包、`node_modules`、`import.meta`
41
41
  - [扩展机制](./implemented/extensions.md) —— 注册表、`node` 扩展、原生 C++/Rust 扩展
42
- - [Node 扩展](./implemented/node.md) —— 21 个 Node 内置模块,每个模块一页
42
+ - [Node 扩展](./implemented/node.md) —— 24 个 Node 内置模块,每个模块一页
43
43
  - [Storage 扩展](./implemented/storage.md) —— 基于 SQLite 的 `localStorage`、`sessionStorage` 与 `indexedDB`
44
44
  - [驱动、增量编译与工具链](./implemented/driver.md) —— 缓存、clang/LTO/PGO、配置、图标
45
45
  - [CLI 与编程接口](./implemented/cli.md) —— 命令、参数、嵌入式 API
@@ -2,12 +2,12 @@
2
2
 
3
3
  > 属于[Node 扩展:未实现](../node.md) · [English](../../../unimplemented/node/modules.md)
4
4
 
5
- 以下 Node 内置模块没有任何对应扩展 / 内置函数(`fs` / `fs/promises` / `path` / `os` / `process` / `buffer` / `stream` / `dgram` / `http` / `events` / `util` / `querystring` / `readline` / `assert` / `test` 已实现,`crypto` / `url` / `child_process` / `zlib` / `stream/promises` / `worker_threads` 部分实现,见[已实现:Node 扩展](../../implemented/node.md)):
5
+ 以下 Node 内置模块没有任何对应扩展 / 内置函数(`fs` / `fs/promises` / `path` / `os` / `process` / `buffer` / `stream` / `dgram` / `http` / `tls` / `http2` / `events` / `util` / `querystring` / `readline` / `assert` / `test` 已实现,`crypto` / `url` / `child_process` / `zlib` / `stream/promises` / `worker_threads` 部分实现,见[已实现:Node 扩展](../../implemented/node.md)):
6
6
 
7
7
  | 模块 | 说明 |
8
8
  | --- | --- |
9
- | `https` | TLS 版 HTTP |
10
- | `tls` / `cluster` / `vm` | 其余未列出的核心模块 |
9
+ | `https` | TLS 版 HTTP;可直接使用 `http2` / `tls`,或对 `https://` 使用 `fetch` |
10
+ | `cluster` / `vm` | 其余未列出的核心模块 |
11
11
 
12
12
  > `crypto`(仅 `createHash`,现支持流式 API)、`url`(仅 `pathToFileURL` / `fileURLToPath`)、
13
13
  > `child_process`(仅 `spawnSync` / `spawn` / `execFile` / `execSync`)、
@@ -9,6 +9,6 @@
9
9
  | 类型检查器 | 部分:默认[语义检查](../implemented/checker.md)会报告未定义名、重复声明、实参个数、属性是否存在与确定的可赋值性错误,支持结构化接口/类、简单泛型与基础流收窄;没有完整推断与 strict-null |
10
10
  | 完整标准库 | 部分:Math / JSON / Date / Map / Set / RegExp / `Error` / `BigInt` / `Symbol` / `structuredClone` 已实现;String.normalize 缺失 |
11
11
  | 多文件模块打包 | 部分:相对路径 `.ts` 打包、ESM `node_modules` 包、命名空间导入、裸说明符扩展模块导入已实现;CommonJS 仅在 `node_modules` 内处理;循环依赖 / 实时绑定未实现 |
12
- | 异步运行时 | ✓ `async`/`await` 在 `select(2)` reactor 上对 pending promise 挂起:定时器、TCP 套接字、offload 的文件/HTTP 工作与 promise 回调都能恢复协程。仍缺:真正的 OS 级文件监听、非阻塞 `net.connect`、`fetch` 的 TLS,以及用户可见的 worker 线程(`worker_threads` 仍用子进程) |
12
+ | 异步运行时 | ✓ `async`/`await` 在 `select(2)` reactor 上对 pending promise 挂起:定时器、TCP 套接字、offload 的文件/HTTP 工作与 promise 回调都能恢复协程。仍缺:真正的 OS 级文件监听、非阻塞 `net.connect`,以及用户可见的 worker 线程(`worker_threads` 仍用子进程) |
13
13
  | Windows 二进制产物验证 | 构建层已适配(`.exe` 后缀、链接参数分支),并在 CI 中验证 |
14
14
  | 精确的 ECMAScript 数值 / 字符串 / 比较语义 | 部分,见[运行时偏差](./deviations.md) |