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
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `http2` link feature: nghttp2-backed `node:http2`.
|
|
3
|
+
*
|
|
4
|
+
* HTTP/2 framing and HPACK come from the vendored nghttp2 archive; TLS (and
|
|
5
|
+
* therefore ALPN) comes from the `tls` feature, and the JavaScript object
|
|
6
|
+
* surface reuses `node-tls`'s server wrapper for `createSecureServer`. The
|
|
7
|
+
* always-linked `http2` module forwards to the dispatch table this feature
|
|
8
|
+
* installs, so a checkout without the archive still compiles and reports a
|
|
9
|
+
* clear runtime error instead of failing to link.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { LinkFeature, ProgramUsage } from "../../link-feature.js";
|
|
13
|
+
import { resolveFrom } from "../module.js";
|
|
14
|
+
import { requireRuntimeLibrary } from "../../tls.js";
|
|
15
|
+
|
|
16
|
+
/** True when the bundled program imports `http2` or uses its server API. */
|
|
17
|
+
export function mentionsHttp2(usage: ProgramUsage): boolean {
|
|
18
|
+
return (
|
|
19
|
+
usage.strings.includes("http2") ||
|
|
20
|
+
usage.strings.includes("node:http2") ||
|
|
21
|
+
usage.identifiers.has("createSecureServer") ||
|
|
22
|
+
usage.identifiers.has("Http2Session")
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const http2Feature: LinkFeature = {
|
|
27
|
+
name: "http2",
|
|
28
|
+
description: "node:http2 client and server using nghttp2 over TLS or cleartext",
|
|
29
|
+
requires: ["tls", "node-tls"],
|
|
30
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/http2/http2_bridge.c")],
|
|
31
|
+
nativeObjects: () => [requireRuntimeLibrary("nghttp2", "npm run tls")],
|
|
32
|
+
used: mentionsHttp2,
|
|
33
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node's `http2` module —
|
|
2
|
+
* Node's `http2` module — importable bindings.
|
|
3
|
+
*
|
|
4
|
+
* The implementation is the optional `http2` link feature (nghttp2 over
|
|
5
|
+
* cleartext h2c or TLS/ALPN `h2`); this module keeps the import surface stable
|
|
6
|
+
* and forwards to it. See `feature.ts` for the feature selection.
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
9
|
import type { NodeModule } from "../module.js";
|
|
@@ -10,6 +14,7 @@ const exports: ModuleExports = {
|
|
|
10
14
|
connect: { symbol: "xt_http2_connect" },
|
|
11
15
|
createServer: { symbol: "xt_http2_create_server" },
|
|
12
16
|
createSecureServer: { symbol: "xt_http2_create_secure_server" },
|
|
17
|
+
constants: { valueSymbol: "xt_http2_constants" },
|
|
13
18
|
};
|
|
14
19
|
|
|
15
20
|
export const http2Module: NodeModule = {
|
|
@@ -52,6 +52,8 @@ import { sqliteModule } from "./sqlite/index.js";
|
|
|
52
52
|
import { streamWebModule } from "./stream-web/index.js";
|
|
53
53
|
import { tlsModule } from "./tls/index.js";
|
|
54
54
|
import { http2Module } from "./http2/index.js";
|
|
55
|
+
import { nodeTlsFeature } from "./tls/feature.js";
|
|
56
|
+
import { http2Feature } from "./http2/feature.js";
|
|
55
57
|
|
|
56
58
|
/** Every Node module the extension currently provides. */
|
|
57
59
|
const modules: readonly NodeModule[] = [
|
|
@@ -118,5 +120,5 @@ export const nodeExtension: Extension = {
|
|
|
118
120
|
}
|
|
119
121
|
return exposed;
|
|
120
122
|
},
|
|
121
|
-
linkFeatures: () => [compressionFeature],
|
|
123
|
+
linkFeatures: () => [compressionFeature, nodeTlsFeature, http2Feature],
|
|
122
124
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `node-tls` link feature: the JavaScript surface of `node:tls`.
|
|
3
|
+
*
|
|
4
|
+
* The always-linked `tls` module keeps the importable bindings and reports a
|
|
5
|
+
* clear runtime error when the feature is absent. When a program imports
|
|
6
|
+
* `node:tls`, this feature compiles the backend that builds `TLSSocket`
|
|
7
|
+
* objects on top of the `tls` feature's mbedTLS transport.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { LinkFeature, ProgramUsage } from "../../link-feature.js";
|
|
11
|
+
import { resolveFrom } from "../module.js";
|
|
12
|
+
|
|
13
|
+
/** True when the bundled program imports `tls` or names its main class. */
|
|
14
|
+
export function mentionsNodeTls(usage: ProgramUsage): boolean {
|
|
15
|
+
return (
|
|
16
|
+
usage.strings.includes("tls") ||
|
|
17
|
+
usage.strings.includes("node:tls") ||
|
|
18
|
+
usage.identifiers.has("TLSSocket") ||
|
|
19
|
+
usage.identifiers.has("createSecureServer")
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const nodeTlsFeature: LinkFeature = {
|
|
24
|
+
name: "node-tls",
|
|
25
|
+
description: "node:tls TLSSocket/client/server on top of mbedTLS",
|
|
26
|
+
requires: ["tls"],
|
|
27
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/tls/tls_backend.c")],
|
|
28
|
+
used: mentionsNodeTls,
|
|
29
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Node's `tls` module —
|
|
2
|
+
* Node's `tls` module — importable bindings.
|
|
3
|
+
*
|
|
4
|
+
* The implementation is the optional `node-tls` link feature (mbedTLS-backed
|
|
5
|
+
* `TLSSocket`, `connect` and `createServer`); this module keeps the import
|
|
6
|
+
* surface stable and forwards to it. See `feature.ts` for feature selection.
|
|
3
7
|
*/
|
|
4
8
|
|
|
5
9
|
import type { NodeModule } from "../module.js";
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
* and installs its raw-DEFLATE backend into the `zlib` module.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { join } from "node:path";
|
|
10
11
|
import type { LinkFeature, ProgramUsage } from "../../link-feature.js";
|
|
12
|
+
import { findVendorDir } from "../../../driver/paths.js";
|
|
11
13
|
import { resolveFrom } from "../module.js";
|
|
12
14
|
|
|
13
15
|
const COMPRESSION_IDENTIFIERS: ReadonlySet<string> = new Set([
|
|
@@ -37,12 +39,15 @@ const COMPRESSION_IDENTIFIERS: ReadonlySet<string> = new Set([
|
|
|
37
39
|
export const compressionFeature: LinkFeature = {
|
|
38
40
|
name: "compression",
|
|
39
41
|
description: "miniz DEFLATE compression/decompression for node:zlib",
|
|
40
|
-
runtimeSources: () =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
runtimeSources: () => {
|
|
43
|
+
const miniz = join(findVendorDir(), "miniz");
|
|
44
|
+
return [
|
|
45
|
+
join(miniz, "miniz.c"),
|
|
46
|
+
join(miniz, "miniz_tdef.c"),
|
|
47
|
+
join(miniz, "miniz_tinfl.c"),
|
|
48
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/zlib/compression_bridge.c"),
|
|
49
|
+
];
|
|
50
|
+
},
|
|
46
51
|
used: (usage: ProgramUsage): boolean =>
|
|
47
52
|
[...usage.identifiers].some((name) => COMPRESSION_IDENTIFIERS.has(name)),
|
|
48
53
|
};
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import type { LinkFeature } from "./link-feature.js";
|
|
15
|
+
import { storageGlobals, storageLinkFeatures } from "./storage.js";
|
|
16
|
+
import { tlsFeature } from "./tls.js";
|
|
15
17
|
|
|
16
18
|
export interface BuiltinFunction {
|
|
17
19
|
/** Exported C symbol, called as `xt_value symbol(int32_t argc, xt_value *argv)`. */
|
|
@@ -342,14 +344,19 @@ export class ExtensionRegistry {
|
|
|
342
344
|
|
|
343
345
|
/**
|
|
344
346
|
* A built-in extension that exposes the runtime's own console/IO helpers. It is
|
|
345
|
-
* always present so `console.log` works even without a platform extension
|
|
347
|
+
* always present so `console.log` works even without a platform extension, and
|
|
348
|
+
* it also contributes the SQLite-backed Web Storage/IndexedDB globals as a link
|
|
349
|
+
* feature (see `./storage.js`) so `localStorage`/`sessionStorage`/`indexedDB`
|
|
350
|
+
* are always reachable while SQLite is linked only when used.
|
|
346
351
|
*/
|
|
347
352
|
export const coreExtension: Extension = {
|
|
348
353
|
name: "core",
|
|
349
|
-
description: "Core runtime helpers (console, print)",
|
|
354
|
+
description: "Core runtime helpers (console, print, Web Storage and IndexedDB)",
|
|
350
355
|
builtins: () => ({
|
|
351
356
|
print: { symbol: "xt_println" },
|
|
352
357
|
}),
|
|
358
|
+
globalValues: () => storageGlobals,
|
|
359
|
+
linkFeatures: () => [...storageLinkFeatures, tlsFeature],
|
|
353
360
|
};
|
|
354
361
|
|
|
355
362
|
export function createDefaultRegistry(): ExtensionRegistry {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite-backed Web Storage and IndexedDB, contributed as a *link feature*.
|
|
3
|
+
*
|
|
4
|
+
* `localStorage`, `sessionStorage` and `indexedDB` are browser globals made
|
|
5
|
+
* available by the always-on `core` extension (`src/extensions/registry.ts`).
|
|
6
|
+
* The SQLite implementation behind them is heavy, so it is a **link feature**:
|
|
7
|
+
* the driver scans the bundled AST and links it only when the program may
|
|
8
|
+
* actually reach one of the three globals — a program that never touches
|
|
9
|
+
* storage pays nothing for SQLite.
|
|
10
|
+
*
|
|
11
|
+
* The backend is selected at build time from `storage` in
|
|
12
|
+
* `xbintsc.config.json` (default: in-memory; `sessionStorage` is always
|
|
13
|
+
* in-memory). `--feature storage` forces the backend on (for storage reached
|
|
14
|
+
* through names the scan cannot see) and `--no-feature storage` keeps it out.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { join } from "node:path";
|
|
18
|
+
import type { GlobalValue } from "./registry.js";
|
|
19
|
+
import type { LinkFeature, ProgramUsage } from "./link-feature.js";
|
|
20
|
+
import { findRuntimeDir, findVendorDir } from "../driver/paths.js";
|
|
21
|
+
|
|
22
|
+
/** The browser storage globals resolved by the core extension. */
|
|
23
|
+
export const storageGlobals: Readonly<Record<string, GlobalValue>> = {
|
|
24
|
+
localStorage: { symbol: "xt_storage_local" },
|
|
25
|
+
sessionStorage: { symbol: "xt_storage_session" },
|
|
26
|
+
indexedDB: { symbol: "xt_storage_indexed_db" },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** True when the bundled program may reach a Web Storage or IndexedDB global. */
|
|
30
|
+
export function hasStorageUsage(usage: ProgramUsage): boolean {
|
|
31
|
+
return (
|
|
32
|
+
usage.identifiers.has("localStorage") ||
|
|
33
|
+
usage.identifiers.has("sessionStorage") ||
|
|
34
|
+
usage.identifiers.has("indexedDB")
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const storageLinkFeatures: readonly LinkFeature[] = [
|
|
39
|
+
{
|
|
40
|
+
name: "storage",
|
|
41
|
+
description: "SQLite-backed localStorage, sessionStorage and indexedDB",
|
|
42
|
+
/**
|
|
43
|
+
* The full implementation lives here, not in the extension's runtime
|
|
44
|
+
* sources, so it is compiled and linked only when the feature is active.
|
|
45
|
+
* `storage.c` defines the `xt_storage_local` / `xt_storage_session` globals
|
|
46
|
+
* the code generator reaches for, and `indexed_db.c` / `indexed_db_store.c`
|
|
47
|
+
* define `xt_storage_indexed_db`; all three reference the vendored SQLite
|
|
48
|
+
* fetched into `vendor/sqlite3` (see `npm run vendor`).
|
|
49
|
+
*/
|
|
50
|
+
runtimeSources: () => [
|
|
51
|
+
join(findVendorDir(), "sqlite3", "sqlite3.c"),
|
|
52
|
+
join(findRuntimeDir(), "xt_storage", "storage.c"),
|
|
53
|
+
join(findRuntimeDir(), "xt_storage", "indexed_db.c"),
|
|
54
|
+
join(findRuntimeDir(), "xt_storage", "indexed_db_store.c"),
|
|
55
|
+
],
|
|
56
|
+
used: hasStorageUsage,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `tls` link feature: mbedTLS, used by `fetch` for `https://` URLs.
|
|
3
|
+
*
|
|
4
|
+
* TLS is heavy (~200 KiB of mbedTLS code) and most programs never make an
|
|
5
|
+
* HTTPS request, so it is an optional feature of the always-on `core`
|
|
6
|
+
* extension. The driver scans the bundled program for an `https://` literal and
|
|
7
|
+
* only then compiles `runtime/xt_tls/tls_bridge.c` and links the mbedTLS
|
|
8
|
+
* archive (which contains `tls_core.c`); the always-linked runtime reaches the
|
|
9
|
+
* backend through the `xt_tls_core_api` dispatch table, which stays NULL
|
|
10
|
+
* otherwise.
|
|
11
|
+
*
|
|
12
|
+
* `node:tls` and `node:http2` declare their own features that `requires` this
|
|
13
|
+
* one, and `--feature tls` forces it for a URL the scan cannot see. The archive
|
|
14
|
+
* is produced by `npm run tls`; without it the feature is reported unavailable
|
|
15
|
+
* and HTTPS requests reject with a clear runtime error.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { resolve } from "node:path";
|
|
19
|
+
import { findRuntimeDir } from "../driver/paths.js";
|
|
20
|
+
import { findRuntimeLibrary } from "../driver/runtime-lib.js";
|
|
21
|
+
import type { LinkFeature, ProgramUsage } from "./link-feature.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a prebuilt third-party archive, or throw with the command that builds
|
|
25
|
+
* it. `resolveLinkFeatures` turns the throw into a warning for an auto-detected
|
|
26
|
+
* feature and into an error for an explicitly forced one.
|
|
27
|
+
*/
|
|
28
|
+
export function requireRuntimeLibrary(name: string, buildCommand: string): string {
|
|
29
|
+
const archive = findRuntimeLibrary(name);
|
|
30
|
+
if (archive === undefined) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`the '${name}' archive is not built; run \`${buildCommand}\` to fetch and build it`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
return archive;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** True when a string literal names an HTTPS URL. */
|
|
39
|
+
export function mentionsHttps(usage: ProgramUsage): boolean {
|
|
40
|
+
return usage.strings.some((text) => /^https:\/\//i.test(text));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const tlsFeature: LinkFeature = {
|
|
44
|
+
name: "tls",
|
|
45
|
+
description: "mbedTLS TLS transport used by fetch() for https:// URLs and node:tls",
|
|
46
|
+
runtimeSources: () => [resolve(findRuntimeDir(), "xt_tls", "tls_bridge.c")],
|
|
47
|
+
nativeObjects: () => [requireRuntimeLibrary("tls", "npm run tls")],
|
|
48
|
+
// Windows reads its root certificate store through crypt32; the Win32 socket
|
|
49
|
+
// and bcrypt libraries are already linked by the driver.
|
|
50
|
+
linkerFlags: () => (process.platform === "win32" ? ["-lcrypt32"] : []),
|
|
51
|
+
used: (usage: ProgramUsage): boolean => mentionsHttps(usage) || usage.identifiers.has("TLSSocket"),
|
|
52
|
+
};
|