xbintsc 0.6.24 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/dist/src/binder/declarations.d.ts +1 -0
- package/dist/src/binder/declarations.js +37 -0
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/binder/references.js +12 -0
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/globals.js +1 -0
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-system.d.ts +5 -0
- package/dist/src/checker/type-system.js +22 -3
- package/dist/src/checker/type-system.js.map +1 -1
- package/dist/src/cli/extensions.js +11 -3
- package/dist/src/cli/extensions.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/calls/access.js +25 -0
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +13 -0
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls/super.js +3 -4
- package/dist/src/codegen/generator/calls/super.js.map +1 -1
- package/dist/src/codegen/generator/calls/unwrap.d.ts +18 -0
- package/dist/src/codegen/generator/calls/unwrap.js +45 -0
- package/dist/src/codegen/generator/calls/unwrap.js.map +1 -0
- package/dist/src/codegen/generator/expressions/assignment.js +14 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/module-values.d.ts +6 -0
- package/dist/src/codegen/generator/expressions/module-values.js +51 -17
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.js +9 -5
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/lookup-tables.d.ts +22 -0
- package/dist/src/codegen/generator/lookup-tables.js +48 -0
- package/dist/src/codegen/generator/lookup-tables.js.map +1 -0
- package/dist/src/codegen/generator/module.js +38 -7
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +24 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +2 -6
- package/dist/src/codegen/generator/tables.js +37 -13
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.d.ts +9 -2
- package/dist/src/driver/bundler/commonjs.js +11 -4
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +20 -0
- package/dist/src/driver/bundler/concatenate.js +68 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +29 -1
- package/dist/src/driver/bundler/deferred.js +114 -5
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +6 -0
- package/dist/src/driver/bundler/dynamic-import.js +59 -3
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -1
- package/dist/src/driver/bundler/graph.d.ts +13 -0
- package/dist/src/driver/bundler/graph.js +11 -7
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +32 -8
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-object.d.ts +11 -0
- package/dist/src/driver/bundler/namespace-object.js +32 -0
- package/dist/src/driver/bundler/namespace-object.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +8 -2
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +14 -1
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/fingerprint.d.ts +2 -2
- package/dist/src/driver/fingerprint.js +3 -3
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/link-features.js +1 -1
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/options.d.ts +1 -4
- package/dist/src/driver/paths.js +8 -4
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-lib.d.ts +27 -0
- package/dist/src/driver/runtime-lib.js +78 -2
- package/dist/src/driver/runtime-lib.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +37 -6
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/driver/version.js.map +1 -1
- package/dist/src/extensions/catalog.js +5 -1
- package/dist/src/extensions/catalog.js.map +1 -1
- package/dist/src/extensions/gui/index.js +0 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/link-feature.d.ts +8 -0
- package/dist/src/extensions/node/buffer/index.d.ts +5 -4
- package/dist/src/extensions/node/buffer/index.js +5 -4
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/events/index.js +8 -1
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/fs/callbacks.d.ts +9 -0
- package/dist/src/extensions/node/fs/callbacks.js +42 -0
- package/dist/src/extensions/node/fs/callbacks.js.map +1 -0
- package/dist/src/extensions/node/fs/index.d.ts +2 -3
- package/dist/src/extensions/node/fs/index.js +11 -4
- package/dist/src/extensions/node/fs/index.js.map +1 -1
- package/dist/src/extensions/node/process/index.d.ts +10 -3
- package/dist/src/extensions/node/process/index.js +30 -5
- package/dist/src/extensions/node/process/index.js.map +1 -1
- package/dist/src/extensions/node/stream-web/index.d.ts +6 -1
- package/dist/src/extensions/node/stream-web/index.js +59 -4
- package/dist/src/extensions/node/stream-web/index.js.map +1 -1
- package/dist/src/extensions/node/worker_threads/index.d.ts +14 -4
- package/dist/src/extensions/node/worker_threads/index.js +24 -11
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +16 -1
- package/dist/src/extensions/registry.js +17 -5
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/wasm-asset.d.ts +16 -0
- package/dist/src/extensions/wasm-asset.js +28 -0
- package/dist/src/extensions/wasm-asset.js.map +1 -0
- package/dist/src/extensions/wasm.d.ts +17 -0
- package/dist/src/extensions/wasm.js +68 -0
- package/dist/src/extensions/wasm.js.map +1 -0
- package/dist/src/extensions/webworker/index.d.ts +24 -0
- package/dist/src/extensions/webworker/index.js +54 -0
- package/dist/src/extensions/webworker/index.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/lexer/scanner.d.ts +7 -1
- package/dist/src/lexer/scanner.js +15 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/parser/context.d.ts +10 -0
- package/dist/src/parser/context.js +42 -3
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/literals.js +6 -2
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/binder/binder.test.js +43 -0
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +15 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/driver/bundler-resolve.test.js +12 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/commonjs-prelude.test.d.ts +11 -0
- package/dist/tests/driver/commonjs-prelude.test.js +69 -0
- package/dist/tests/driver/commonjs-prelude.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.js +42 -1
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/html-deferred-cycles.test.d.ts +10 -0
- package/dist/tests/driver/html-deferred-cycles.test.js +75 -0
- package/dist/tests/driver/html-deferred-cycles.test.js.map +1 -0
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/namespace-type-exports.test.d.ts +9 -0
- package/dist/tests/driver/namespace-type-exports.test.js +59 -0
- package/dist/tests/driver/namespace-type-exports.test.js.map +1 -0
- package/dist/tests/driver/runtime-lib.test.js +49 -1
- package/dist/tests/driver/runtime-lib.test.js.map +1 -1
- package/dist/tests/e2e/async-fs.test.js +44 -0
- package/dist/tests/e2e/async-fs.test.js.map +1 -1
- package/dist/tests/e2e/compile-basics.test.js +53 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- package/dist/tests/e2e/compile-deferred-marker.test.d.ts +14 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js +68 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js.map +1 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.d.ts +12 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js +89 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js.map +1 -0
- package/dist/tests/e2e/compile-error-module.test.d.ts +9 -0
- package/dist/tests/e2e/compile-error-module.test.js +29 -0
- package/dist/tests/e2e/compile-error-module.test.js.map +1 -0
- package/dist/tests/e2e/compile-gc-promises.test.d.ts +11 -0
- package/dist/tests/e2e/compile-gc-promises.test.js +52 -0
- package/dist/tests/e2e/compile-gc-promises.test.js.map +1 -0
- package/dist/tests/e2e/compile-modules.test.js +40 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node-fs-callbacks.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js +46 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-inheritance.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js +48 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-require.test.d.ts +9 -0
- package/dist/tests/e2e/compile-node-require.test.js +29 -0
- package/dist/tests/e2e/compile-node-require.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-stats.test.d.ts +8 -0
- package/dist/tests/e2e/compile-node-stats.test.js +26 -0
- package/dist/tests/e2e/compile-node-stats.test.js.map +1 -0
- package/dist/tests/e2e/compile-proxy.test.d.ts +6 -0
- package/dist/tests/e2e/compile-proxy.test.js +66 -0
- package/dist/tests/e2e/compile-proxy.test.js.map +1 -0
- package/dist/tests/e2e/compile-web-globals.test.d.ts +6 -0
- package/dist/tests/e2e/compile-web-globals.test.js +94 -0
- package/dist/tests/e2e/compile-web-globals.test.js.map +1 -0
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gui-script-import-order.test.js +24 -0
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +6 -0
- package/dist/tests/e2e/harness.js +13 -1
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/json-stringify-to-json.test.d.ts +10 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js +61 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js.map +1 -0
- package/dist/tests/e2e/node-crypto-random.test.d.ts +8 -0
- package/dist/tests/e2e/node-crypto-random.test.js +148 -0
- package/dist/tests/e2e/node-crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +1 -1
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/node-process.test.d.ts +7 -0
- package/dist/tests/e2e/node-process.test.js +50 -0
- package/dist/tests/e2e/node-process.test.js.map +1 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js +31 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.d.ts +8 -0
- package/dist/tests/e2e/web-streams.test.js +289 -0
- package/dist/tests/e2e/web-streams.test.js.map +1 -0
- package/dist/tests/e2e/web-worker.test.d.ts +7 -0
- package/dist/tests/e2e/web-worker.test.js +74 -0
- package/dist/tests/e2e/web-worker.test.js.map +1 -0
- package/dist/tests/e2e/webassembly.test.d.ts +8 -0
- package/dist/tests/e2e/webassembly.test.js +113 -0
- package/dist/tests/e2e/webassembly.test.js.map +1 -0
- package/dist/tests/e2e/worker-api.test.d.ts +14 -0
- package/dist/tests/e2e/worker-api.test.js +460 -0
- package/dist/tests/e2e/worker-api.test.js.map +1 -0
- package/dist/tests/e2e/worker-threads.test.d.ts +8 -0
- package/dist/tests/e2e/worker-threads.test.js +160 -0
- package/dist/tests/e2e/worker-threads.test.js.map +1 -0
- package/dist/tests/extensions/wasm.test.d.ts +1 -0
- package/dist/tests/extensions/wasm.test.js +53 -0
- package/dist/tests/extensions/wasm.test.js.map +1 -0
- package/dist/tests/parser/literals.test.js +19 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/statements.test.js +13 -0
- package/dist/tests/parser/statements.test.js.map +1 -1
- package/doc/ai/cli.md +2 -1
- package/doc/ai/contributing.md +11 -4
- package/doc/ai/extensions.md +25 -2
- package/doc/ai/language-support.md +14 -2
- package/doc/ai/zh-CN/cli.md +2 -1
- package/doc/ai/zh-CN/contributing.md +8 -3
- package/doc/ai/zh-CN/extensions.md +23 -2
- package/doc/ai/zh-CN/language-support.md +13 -2
- package/doc/gui/api.md +1 -1
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +5 -0
- package/doc/implemented/cli.md +1 -1
- package/doc/implemented/extensions.md +6 -5
- package/doc/implemented/lexer.md +1 -1
- package/doc/implemented/modules.md +23 -1
- package/doc/implemented/node/buffer.md +18 -5
- package/doc/implemented/node/fs.md +22 -1
- package/doc/implemented/node/process.md +65 -5
- package/doc/implemented/node/stream-web.md +31 -0
- package/doc/implemented/node/worker-threads.md +88 -5
- package/doc/implemented/node.md +9 -2
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +1 -1
- package/doc/implemented/runtime-core.md +6 -2
- package/doc/implemented/stdlib.md +69 -2
- package/doc/implemented/streams.md +82 -0
- package/doc/implemented/wasm.md +80 -18
- package/doc/implemented/web-worker.md +84 -0
- package/doc/implemented.md +6 -2
- package/doc/unimplemented/classes.md +1 -0
- package/doc/unimplemented/deviations.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/node/worker-threads.md +23 -0
- package/doc/unimplemented/node.md +1 -0
- package/doc/unimplemented/stdlib.md +3 -1
- package/doc/unimplemented/wasm.md +21 -9
- package/doc/unimplemented.md +1 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +3 -0
- package/doc/zh-CN/implemented/cli.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +7 -6
- package/doc/zh-CN/implemented/lexer.md +1 -1
- package/doc/zh-CN/implemented/modules.md +17 -1
- package/doc/zh-CN/implemented/node/buffer.md +3 -1
- package/doc/zh-CN/implemented/node/fs.md +19 -1
- package/doc/zh-CN/implemented/node/process.md +59 -5
- package/doc/zh-CN/implemented/node/stream-web.md +24 -0
- package/doc/zh-CN/implemented/node/worker-threads.md +77 -4
- package/doc/zh-CN/implemented/node.md +3 -2
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +1 -1
- package/doc/zh-CN/implemented/runtime-core.md +3 -2
- package/doc/zh-CN/implemented/stdlib.md +58 -2
- package/doc/zh-CN/implemented/streams.md +60 -0
- package/doc/zh-CN/implemented/wasm.md +73 -16
- package/doc/zh-CN/implemented/web-worker.md +79 -0
- package/doc/zh-CN/implemented.md +6 -2
- package/doc/zh-CN/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/deviations.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/node/worker-threads.md +20 -0
- package/doc/zh-CN/unimplemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +3 -1
- package/doc/zh-CN/unimplemented/wasm.md +16 -8
- package/doc/zh-CN/unimplemented.md +1 -1
- package/llms.txt +2 -0
- package/package.json +8 -7
- package/runtime/ext_gui/browser.cpp +1 -1
- package/runtime/ext_node/buffer/buffer.c +5 -4
- package/runtime/ext_node/buffer/parts/byte-access.inc +115 -11
- package/runtime/ext_node/buffer/parts/prototype.inc +4 -1
- package/runtime/ext_node/events/events.c +9 -0
- package/runtime/ext_node/fs/callbacks.c +138 -0
- package/runtime/ext_node/fs/fs_ops.c +28 -15
- package/runtime/ext_node/module/module.c +18 -9
- package/runtime/ext_node/process/process.c +117 -32
- package/runtime/ext_node/process/streams.c +370 -0
- package/runtime/ext_node/process/streams.h +20 -0
- package/runtime/ext_node/stream_web/stream_web.c +20 -6
- package/runtime/rt.h +36 -0
- package/runtime/rt_internal.h +10 -10
- package/runtime/worker/worker_api.c +422 -0
- package/runtime/worker/worker_codec.c +489 -0
- package/runtime/worker/worker_core.c +445 -0
- package/runtime/worker/worker_internal.h +223 -0
- package/runtime/worker/worker_platform.c +344 -0
- package/runtime/worker/worker_ports.c +203 -0
- package/runtime/worker/worker_transport.c +464 -0
- package/runtime/worker/worker_wire.c +150 -0
- package/runtime/xt_alloc.c +67 -49
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +41 -23
- package/runtime/xt_constructors.c +148 -2
- package/runtime/xt_containers/access.inc +29 -1
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/objects.inc +18 -2
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_exit.c +34 -0
- package/runtime/xt_fetch/headers.inc +1 -0
- package/runtime/xt_fetch/response.inc +28 -8
- package/runtime/xt_fetch/webapi.inc +82 -0
- package/runtime/xt_fetch.c +5 -0
- package/runtime/xt_gc_verify.c +135 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/exception.inc +40 -1
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +98 -9
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/error.inc +4 -0
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +70 -53
- package/runtime/xt_streams/common.inc +232 -0
- package/runtime/xt_streams/constructors.inc +232 -0
- package/runtime/xt_streams/encoding.inc +124 -0
- package/runtime/xt_streams/readable-extra.inc +372 -0
- package/runtime/xt_streams/readable.inc +415 -0
- package/runtime/xt_streams/transform.inc +195 -0
- package/runtime/xt_streams/writable.inc +542 -0
- package/runtime/xt_streams.c +30 -0
- package/runtime/xt_wasm/wasm.h +148 -0
- package/runtime/xt_wasm/wasm_api.c +357 -0
- package/runtime/xt_wasm/wasm_api.h +37 -0
- package/runtime/xt_wasm/wasm_bridge.c +30 -0
- package/runtime/xt_wasm/wasm_instance.c +591 -0
- package/runtime/xt_wasm/wasm_module.c +270 -0
- package/runtime/xt_wasm/wasm_values.c +177 -0
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/runtime/xt_webassembly.c +15 -4
- package/scripts/build-runtime.ts +8 -0
- package/scripts/fetch-vendored.ts +187 -20
- package/scripts/package-release.ts +3 -2
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/extensions.ts +11 -3
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/calls/access.ts +23 -0
- package/src/codegen/generator/calls/invocation.ts +12 -0
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/expressions/assignment.ts +15 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +9 -9
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +24 -0
- package/src/codegen/generator/tables.ts +37 -13
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +84 -7
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +11 -7
- package/src/driver/bundler/merge.ts +31 -5
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +12 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/config.ts +1 -1
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- package/src/driver/options.ts +1 -4
- package/src/driver/paths.ts +8 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +37 -6
- package/src/driver/version.ts +1 -1
- package/src/extensions/catalog.ts +5 -1
- package/src/extensions/gui/index.ts +0 -1
- package/src/extensions/link-feature.ts +8 -0
- package/src/extensions/node/buffer/index.ts +5 -4
- package/src/extensions/node/events/index.ts +8 -1
- package/src/extensions/node/fs/callbacks.ts +45 -0
- package/src/extensions/node/fs/index.ts +11 -4
- package/src/extensions/node/process/index.ts +30 -5
- package/src/extensions/node/stream-web/index.ts +59 -4
- package/src/extensions/node/worker_threads/index.ts +24 -11
- package/src/extensions/registry.ts +34 -6
- package/src/extensions/wasm-asset.ts +32 -0
- package/src/extensions/wasm.ts +74 -0
- package/src/extensions/webworker/index.ts +58 -0
- package/src/index.ts +1 -0
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/literals.ts +6 -2
- package/vendor/wasm3/.pin +1 -0
- package/vendor/wasm3/LICENSE +21 -0
- package/vendor/wasm3/m3_api_libc.c +265 -0
- package/vendor/wasm3/m3_api_libc.h +19 -0
- package/vendor/wasm3/m3_api_meta_wasi.c +1107 -0
- package/vendor/wasm3/m3_api_tracer.c +173 -0
- package/vendor/wasm3/m3_api_tracer.h +19 -0
- package/vendor/wasm3/m3_api_uvwasi.c +1290 -0
- package/vendor/wasm3/m3_api_wasi.c +1207 -0
- package/vendor/wasm3/m3_api_wasi.h +74 -0
- package/vendor/wasm3/m3_api_wasi_host.h +137 -0
- package/vendor/wasm3/m3_api_wasi_posix.h +979 -0
- package/vendor/wasm3/m3_api_wasi_win32.h +1093 -0
- package/vendor/wasm3/m3_atomic.h +114 -0
- package/vendor/wasm3/m3_bind.c +174 -0
- package/vendor/wasm3/m3_bind.h +20 -0
- package/vendor/wasm3/m3_code.c +232 -0
- package/vendor/wasm3/m3_code.h +74 -0
- package/vendor/wasm3/m3_compile.c +6603 -0
- package/vendor/wasm3/m3_compile.h +354 -0
- package/vendor/wasm3/m3_config.h +448 -0
- package/vendor/wasm3/m3_config_platforms.h +345 -0
- package/vendor/wasm3/m3_core.c +1034 -0
- package/vendor/wasm3/m3_core.h +526 -0
- package/vendor/wasm3/m3_deterministic.c +65 -0
- package/vendor/wasm3/m3_deterministic.h +59 -0
- package/vendor/wasm3/m3_env.c +3146 -0
- package/vendor/wasm3/m3_env.h +748 -0
- package/vendor/wasm3/m3_exception.h +33 -0
- package/vendor/wasm3/m3_exec.c +8 -0
- package/vendor/wasm3/m3_exec.h +4110 -0
- package/vendor/wasm3/m3_exec_atomic.h +146 -0
- package/vendor/wasm3/m3_exec_defs.h +76 -0
- package/vendor/wasm3/m3_function.c +278 -0
- package/vendor/wasm3/m3_function.h +244 -0
- package/vendor/wasm3/m3_host.h +226 -0
- package/vendor/wasm3/m3_host_none.h +76 -0
- package/vendor/wasm3/m3_host_posix.h +543 -0
- package/vendor/wasm3/m3_host_win32.h +253 -0
- package/vendor/wasm3/m3_info.c +616 -0
- package/vendor/wasm3/m3_info.h +38 -0
- package/vendor/wasm3/m3_math_utils.h +560 -0
- package/vendor/wasm3/m3_module.c +431 -0
- package/vendor/wasm3/m3_parse.c +1549 -0
- package/vendor/wasm3/m3_snapshot.c +3825 -0
- package/vendor/wasm3/m3_validate.c +1770 -0
- package/vendor/wasm3/m3_validate.h +25 -0
- package/vendor/wasm3/m3_wasi.h +10 -0
- package/vendor/wasm3/m3_xxh64.c +211 -0
- package/vendor/wasm3/wasm3.h +684 -0
- package/vendor/wasm3/wasm3_defs.h +350 -0
- package/runtime/ext_node/worker_threads/worker_threads.c +0 -214
|
@@ -4,11 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
Location: `src/extensions/node/buffer/index.ts`, `runtime/ext_node/buffer/buffer.c`
|
|
6
6
|
|
|
7
|
-
xbintsc has no native binary value type, so `Buffer` is
|
|
8
|
-
|
|
9
|
-
property, sharing the `xt_buffer_proto()` prototype that provides
|
|
10
|
-
methods. `
|
|
11
|
-
bytes
|
|
7
|
+
xbintsc has no native binary value type, so a `Buffer` is an ordinary object
|
|
8
|
+
that keeps its bytes in an `ArrayBuffer` under a private symbol, plus a
|
|
9
|
+
`length` property, sharing the `xt_buffer_proto()` prototype that provides
|
|
10
|
+
instance methods. Dynamic-property hooks answer `buf[i]` and `buf[i] = 65` from
|
|
11
|
+
that store, so index access behaves like a real Buffer while the bytes stay out
|
|
12
|
+
of the property table: building one is a single bulk copy instead of one
|
|
13
|
+
property insert per byte (which was quadratic and stalled on multi-kilobyte
|
|
14
|
+
decodes). `xt_node_is_buffer` / `xt_node_buffer_bytes` let other modules access
|
|
15
|
+
bytes across modules; `xt_node_buffer_bytes` copies through
|
|
16
|
+
`xt_array_buffer_copy_bytes_out`, so the fs module does not pay one lookup per
|
|
17
|
+
byte.
|
|
12
18
|
|
|
13
19
|
| Static method | Notes |
|
|
14
20
|
| --- | --- |
|
|
@@ -24,6 +30,13 @@ bytes across modules.
|
|
|
24
30
|
|
|
25
31
|
Instance methods: `toString([encoding])`, `toJSON()`, `slice(start, end)`, `subarray(...)`, `equals(other)`, `compare(other)`, `copy(target[, targetStart, sourceStart, sourceEnd])`, `write(string[, offset[, length[, encoding]]])`, `fill(value)`, `reverse()`, `indexOf(value)`, `lastIndexOf(value)`, `includes(value)`, `keys()`, `values()`, plus `readUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`, `writeUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`.
|
|
26
32
|
|
|
33
|
+
Index access works through the object hooks: `buf[0]` reads a byte, `buf[0] =
|
|
34
|
+
65` writes one (out-of-range writes are dropped and cannot grow the buffer),
|
|
35
|
+
`0 in buf` is true inside the range, and `Object.keys(buf)` lists the indices
|
|
36
|
+
after the real properties. The store is an `ArrayBuffer`, so each byte costs
|
|
37
|
+
one `xt_value` slot (the representation `ArrayBuffer` already uses) in exchange
|
|
38
|
+
for garbage collection without a finalizer.
|
|
39
|
+
|
|
27
40
|
```ts
|
|
28
41
|
const buf = Buffer.from("hello");
|
|
29
42
|
console.log(buf.toString(), buf.length); // hello 5
|
|
@@ -4,6 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
Location: `src/extensions/node/fs/*.ts`, `runtime/ext_node/fs/*.c`
|
|
6
6
|
|
|
7
|
+
## Callback forms
|
|
8
|
+
|
|
9
|
+
Every operation below also has Node's callback form, running on the
|
|
10
|
+
asynchronous I/O pool: `readFile(path[, options], callback)`,
|
|
11
|
+
`writeFile`, `appendFile`, `stat`, `lstat`, `statfs`, `realpath`, `access`,
|
|
12
|
+
`mkdir`, `mkdtemp`, `readdir`, `rm`, `rmdir`, `unlink`, `rename`, `copyFile`,
|
|
13
|
+
`cp`, `open`, `chmod`, `lchmod`, `chown`, `lchown`, `truncate`, `utimes`,
|
|
14
|
+
`lutimes`, `link`, `symlink`, `readlink`, `opendir` and `glob`. The callback
|
|
15
|
+
receives `(error, value)` — `error` is `null` on success and a Node-shaped
|
|
16
|
+
`Error` (`code`, `errno`, `syscall`, `path`) on failure. `exists(path, cb)` is
|
|
17
|
+
the exception: `cb(boolean)` with no error argument.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { readFile } from "node:fs";
|
|
21
|
+
|
|
22
|
+
readFile("package.json", "utf8", (error, text) => {
|
|
23
|
+
if (error) throw error;
|
|
24
|
+
console.log(text.length);
|
|
25
|
+
});
|
|
26
|
+
```
|
|
27
|
+
|
|
7
28
|
## Available functions (imported from `fs`)
|
|
8
29
|
|
|
9
30
|
| Imported function | Runtime symbol | Notes |
|
|
@@ -22,7 +43,7 @@ Location: `src/extensions/node/fs/*.ts`, `runtime/ext_node/fs/*.c`
|
|
|
22
43
|
| `copyFileSync(src, dest[, flags])` | `xt_node_copy_file` | copy a file; honours `COPYFILE_EXCL` |
|
|
23
44
|
| `cpSync(src, dest[, options])` | `xt_node_cp` | recursive copy; `recursive`, `force`, `errorOnExist`, `dereference`, `preserveTimestamps` |
|
|
24
45
|
| `realpathSync(path)` | `xt_node_realpath` | resolve to an absolute path |
|
|
25
|
-
| `statSync(path)` | `xt_node_stat` | file metadata object (follows symlinks) |
|
|
46
|
+
| `statSync(path)` | `xt_node_stat` | file metadata object (follows symlinks); `mtime` / `atime` / `ctime` / `birthtime` are `Date`s, with the matching `*Ms` numbers |
|
|
26
47
|
| `lstatSync(path)` | `xt_node_lstat` | file metadata object (does not follow symlinks) |
|
|
27
48
|
| `statfsSync(path)` | `xt_node_statfs` | filesystem statistics (`bsize`, `blocks`, `bfree`, …) |
|
|
28
49
|
| `accessSync(path[, mode])` | `xt_node_access` | check accessibility |
|
|
@@ -2,22 +2,82 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/process.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/extensions/node/process/index.ts`, `runtime/ext_node/process/process.c
|
|
5
|
+
Location: `src/extensions/node/process/index.ts`, `runtime/ext_node/process/process.c`,
|
|
6
|
+
`runtime/ext_node/process/streams.c`
|
|
6
7
|
|
|
7
|
-
Method calls lower to `xt_process_call(<name>, argc, argv)`, property
|
|
8
|
-
|
|
8
|
+
Method calls lower to `xt_process_call(<name>, argc, argv)`, property reads to
|
|
9
|
+
`xt_process_get(<name>)` and property writes to `xt_process_set(<name>, value)`
|
|
10
|
+
(see `NAMESPACE_STATICS` / `NAMESPACE_PROPERTIES` / `NAMESPACE_PROPERTY_SETTERS`
|
|
11
|
+
in `src/codegen/generator/tables.ts`). Import the object
|
|
12
|
+
(`import process from "process"`) to reach these.
|
|
9
13
|
|
|
10
14
|
| Method / property | Notes |
|
|
11
15
|
| --- | --- |
|
|
12
16
|
| `process.cwd()` | current working directory |
|
|
13
|
-
| `process.exit([code])` |
|
|
17
|
+
| `process.exit([code])` | run the "exit" listeners, then exit with `code` |
|
|
14
18
|
| `process.uptime()` | process uptime (seconds) |
|
|
15
19
|
| `process.hrtime()` | `[seconds, nanoseconds]` array |
|
|
16
20
|
| `process.getuid()` | user ID (returns 0 on Windows) |
|
|
21
|
+
| `process.on` / `once` / `addListener` / `prependListener` | register an event listener |
|
|
22
|
+
| `process.off` / `removeListener` / `removeAllListeners` | remove listeners |
|
|
23
|
+
| `process.emit(event, ...args)` | fire an event by hand |
|
|
24
|
+
| `process.nextTick(fn, ...args)` | queue on the microtask queue |
|
|
25
|
+
| `process.exitCode` | read **and** write; becomes the program's exit status |
|
|
26
|
+
| `process.versions` | `{ node: "0.0.0" }` — no `bun` key, so `process.versions.bun` is `undefined` |
|
|
17
27
|
| `process.platform` / `process.arch` | platform / architecture |
|
|
18
28
|
| `process.pid` / `process.ppid` | process ID / parent process ID |
|
|
19
29
|
| `process.argv` | argument array (`argv[0]` is the executable) |
|
|
20
30
|
| `process.env` | environment variable object |
|
|
21
|
-
| `process.
|
|
31
|
+
| `process.execPath` | path of the running binary |
|
|
32
|
+
| `process.version` / `process.title` | placeholder version string / writable title |
|
|
33
|
+
| `process.stdin` / `process.stdout` / `process.stderr` | standard streams, see below |
|
|
22
34
|
|
|
23
35
|
> `argv` is captured by the generated `main` via `xt_set_program_args` and provided to the runtime.
|
|
36
|
+
|
|
37
|
+
## Termination and the exit status
|
|
38
|
+
|
|
39
|
+
The generated `main` ends with `xt_finish()`: it runs the "exit" listeners once
|
|
40
|
+
and returns the status the program asked for, so `process.exitCode = 1` and
|
|
41
|
+
`process.exit(1)` both reach the parent process. `process.exit(code)` runs the
|
|
42
|
+
listeners before leaving, which means a listener sees the final code as its
|
|
43
|
+
argument.
|
|
44
|
+
|
|
45
|
+
## Standard streams
|
|
46
|
+
|
|
47
|
+
`process.stdout` and `process.stderr` are cached EventEmitter objects with
|
|
48
|
+
`write(text)`, `end()`, `destroy()`, `fd`, `isTTY`, `columns` and `rows`.
|
|
49
|
+
`columns`/`rows` come from the console window (Windows) or `TIOCGWINSZ` (POSIX),
|
|
50
|
+
falling back to `COLUMNS`/`LINES` and then 80x24; they are read once when the
|
|
51
|
+
object is created.
|
|
52
|
+
|
|
53
|
+
`process.stdin` is a cached EventEmitter:
|
|
54
|
+
|
|
55
|
+
| Member | Notes |
|
|
56
|
+
| --- | --- |
|
|
57
|
+
| `on("data", fn)` / `once` / `off` | attaching a "data" listener switches the stream to flowing mode |
|
|
58
|
+
| `resume()` / `pause()` | start or stop the read loop |
|
|
59
|
+
| `setEncoding(name)` | records `encoding`; chunks are always UTF-8 strings |
|
|
60
|
+
| `setRawMode(bool)` | console/terminal raw mode, see below |
|
|
61
|
+
| `destroy()` | stops reading |
|
|
62
|
+
| `isTTY` / `isRaw` / `fd` / `readable` | stream state |
|
|
63
|
+
|
|
64
|
+
A blocking read runs on the async I/O worker pool (the reactor's `select(2)`
|
|
65
|
+
cannot watch a console or a pipe on Windows), and its completion — which runs on
|
|
66
|
+
the main thread — decodes the bytes and emits `data` with a string chunk of at
|
|
67
|
+
most 4096 bytes. End of input emits `end` and then `close`.
|
|
68
|
+
|
|
69
|
+
Raw mode flips the console into `ENABLE_VIRTUAL_TERMINAL_INPUT` (Windows) or a
|
|
70
|
+
`termios` raw mode (POSIX) so a TUI receives escape sequences per keystroke
|
|
71
|
+
instead of line-buffered text. An `atexit` handler restores the previous mode, so
|
|
72
|
+
a program that exits without calling `setRawMode(false)` leaves the terminal
|
|
73
|
+
usable.
|
|
74
|
+
|
|
75
|
+
Known limits:
|
|
76
|
+
|
|
77
|
+
- No `resize` events: `stdout.on("resize", fn)` registers but never fires.
|
|
78
|
+
- No signal events: `process.on("SIGINT", fn)` never fires. In raw mode the
|
|
79
|
+
terminal delivers Ctrl+C as input (`"\u0003"`), which is what a TUI wants; a
|
|
80
|
+
line-buffered program terminates through the OS default.
|
|
81
|
+
- Chunks are strings, not `Buffer`s, and there is no `read(size)` pull API.
|
|
82
|
+
- `process.on` listeners are stored on the emitter object; `prependListener`
|
|
83
|
+
appends like `on` (order is registration order).
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# `stream/web`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/stream-web.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/stream-web/index.ts`,
|
|
6
|
+
`runtime/ext_node/stream_web/stream_web.c`.
|
|
7
|
+
|
|
8
|
+
Node's `stream/web` subpath re-exports the WHATWG stream classes. The
|
|
9
|
+
implementations live in the core runtime (see [Web Streams](../streams.md)), so
|
|
10
|
+
a compiled program can use the same classes as browser globals or import them by
|
|
11
|
+
name:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { ReadableStream, TransformStream } from "node:stream/web";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
| Export | Notes |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `ReadableStream`, `ReadableStreamDefaultReader`, `ReadableStreamDefaultController` | full implementation |
|
|
20
|
+
| `WritableStream`, `WritableStreamDefaultWriter`, `WritableStreamDefaultController` | full implementation |
|
|
21
|
+
| `TransformStream`, `TransformStreamDefaultController` | full implementation |
|
|
22
|
+
| `TextEncoderStream`, `TextDecoderStream` | UTF-8 text transform streams |
|
|
23
|
+
| `CountQueuingStrategy`, `ByteLengthQueuingStrategy` | queuing strategies |
|
|
24
|
+
| `ReadableStreamBYOBReader`, `ReadableStreamBYOBRequest` | exported; constructors throw (no byte streams) |
|
|
25
|
+
| `CompressionStream`, `DecompressionStream` | exported; constructors throw (no compression streams) |
|
|
26
|
+
| `ReadableStreamTee` | `undefined`, so undici's `ReadableStreamTee?.(...) ?? body.stream.tee()` falls back to the body's own `tee` |
|
|
27
|
+
|
|
28
|
+
The constructors are first-class values: `const RS = ReadableStream`,
|
|
29
|
+
`new RS(...)`, `stream instanceof ReadableStream` and `ReadableStream.from(...)`
|
|
30
|
+
all work. See [Web Streams](../streams.md) for the async model, the supported
|
|
31
|
+
methods and the remaining limits (BYOB and compression streams).
|
|
@@ -2,9 +2,92 @@
|
|
|
2
2
|
|
|
3
3
|
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/worker-threads.md)
|
|
4
4
|
|
|
5
|
-
Location: `src/extensions/node/worker_threads/index.ts`, `runtime/
|
|
5
|
+
Location: `src/extensions/node/worker_threads/index.ts`, `runtime/worker/`
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
xbintsc has no threads (the value model, the collector and the event loop are
|
|
8
|
+
single-threaded), so a worker is a **second process** running the same
|
|
9
|
+
executable. The worker entry is therefore the current program: pass
|
|
10
|
+
`import.meta.filename` and branch on `isMainThread`.
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { Worker, isMainThread, parentPort, workerData } from "node:worker_threads";
|
|
14
|
+
|
|
15
|
+
if (isMainThread) {
|
|
16
|
+
const worker = new Worker(import.meta.filename, { workerData: { n: 2 } });
|
|
17
|
+
worker.on("message", (reply) => {
|
|
18
|
+
console.log(reply.total);
|
|
19
|
+
worker.terminate();
|
|
20
|
+
});
|
|
21
|
+
worker.postMessage({ values: [1, 2, 3] });
|
|
22
|
+
} else {
|
|
23
|
+
parentPort.on("message", (message) => {
|
|
24
|
+
const values: number[] = message.values;
|
|
25
|
+
parentPort.postMessage({ total: values[0] + values[1] + values[2] });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Surface
|
|
31
|
+
|
|
32
|
+
- `Worker(script, options?)` — `options.workerData` (structured-cloned),
|
|
33
|
+
`options.name`; `script` must name this executable or the constructor throws
|
|
34
|
+
an actionable error. `options.env`, `argv`, `execArgv`, `resourceLimits`,
|
|
35
|
+
`stdin`/`stdout`/`stderr` are accepted but ignored.
|
|
36
|
+
- `worker.postMessage(value, transferList?)` — the value is structured-cloned;
|
|
37
|
+
the transfer list is accepted but copies. Sending a function, symbol,
|
|
38
|
+
promise, `WeakMap`/`WeakSet`/`WeakRef`, generator or `MessagePort` throws
|
|
39
|
+
`... could not be cloned.`
|
|
40
|
+
- `worker.on("message", ...)` / `worker.once` / `off` / `removeAllListeners` —
|
|
41
|
+
`message` delivers the raw value.
|
|
42
|
+
- `worker.on("online" | "error" | "exit", ...)` — `online` after the control
|
|
43
|
+
channel is accepted, `exit` with the process exit code (a terminated worker
|
|
44
|
+
reports `1`). `messageerror` is emitted when a frame cannot be decoded.
|
|
45
|
+
- `worker.terminate(): Promise<number>` — kills the process, resolves with the
|
|
46
|
+
exit code; `ref()`/`unref()` are accepted as no-ops.
|
|
47
|
+
- `worker.threadId` — a per-process worker id.
|
|
48
|
+
- `isMainThread`, `workerData` (null on the main thread), `parentPort` (null on
|
|
49
|
+
the main thread) with `postMessage`, `on("message")`, `close()`, `start()`,
|
|
50
|
+
`ref()`/`unref()`.
|
|
51
|
+
- `new MessageChannel()` / `MessagePort` — a local channel: `port1.postMessage`
|
|
52
|
+
is delivered to `port2` on a zero-delay timer, and either port accepts
|
|
53
|
+
`on("message")` (raw value) or `onmessage` / `addEventListener` (a
|
|
54
|
+
`MessageEvent`). `receiveMessageOnPort` exists but a local port already
|
|
55
|
+
delivers on a timer, so it returns `undefined`.
|
|
56
|
+
- `markAsUncloneable(value)` — accepted; the codec already rejects streams and
|
|
57
|
+
host handles.
|
|
58
|
+
|
|
59
|
+
## Message data
|
|
60
|
+
|
|
61
|
+
Messages and `workerData` use the structured-clone codec in
|
|
62
|
+
`runtime/worker/worker_codec.c`: `undefined`, booleans, numbers (including
|
|
63
|
+
`NaN`, `±Infinity`, `-0`), strings, `BigInt`, arrays, plain objects, `Map`,
|
|
64
|
+
`Set`, `Date`, `RegExp`, `ArrayBuffer`, typed arrays, shared references and
|
|
65
|
+
cycles. Classes arrive as plain objects; functions and symbols are rejected.
|
|
66
|
+
|
|
67
|
+
## Lifetime and errors
|
|
68
|
+
|
|
69
|
+
The parent stays alive while a worker runs. A worker stays alive while it has a
|
|
70
|
+
`message` listener (or other event-loop work); a worker that posts once and
|
|
71
|
+
returns exits on its own, so `worker.on("message")` plus `terminate()` is the
|
|
72
|
+
usual pattern for a long-lived worker. A worker that returns closes its control
|
|
73
|
+
channel before the process ends, so a message posted just before exit is still
|
|
74
|
+
delivered. An uncaught exception in the worker is printed by that process on
|
|
75
|
+
stderr and ends it with a non-zero code; the parent observes `exit`, not
|
|
76
|
+
`error`. Closing the parent's last handle ends the worker through the socket
|
|
77
|
+
EOF.
|
|
78
|
+
|
|
79
|
+
## Platform notes
|
|
80
|
+
|
|
81
|
+
The transport is a loopback TCP socket (Windows `select(2)` only accepts
|
|
82
|
+
sockets, so pipes would need a second implementation). POSIX uses
|
|
83
|
+
`fork`/`execvp` and `waitpid(WNOHANG)`; Windows uses `_spawnvp(_P_NOWAIT)` and
|
|
84
|
+
`WaitForSingleObject` on the process handle. The port and a random handshake
|
|
85
|
+
token travel through the environment, which caps `workerData` at 32 KiB on
|
|
86
|
+
Windows.
|
|
87
|
+
|
|
88
|
+
## Limitations
|
|
89
|
+
|
|
90
|
+
`MessagePort` transfer between processes, `BroadcastChannel`,
|
|
91
|
+
`setEnvironmentData`/`getEnvironmentData`, `SHARE_ENV` and real thread
|
|
92
|
+
parallelism are not implemented — see
|
|
93
|
+
[Node extension: unimplemented](../../unimplemented/node.md).
|
package/doc/implemented/node.md
CHANGED
|
@@ -23,9 +23,10 @@ work on another. Missing or different behaviour is recorded under
|
|
|
23
23
|
| `path` | [path](./node/path.md) | `path.<name>(...)` namespace calls |
|
|
24
24
|
| `os` | [os](./node/os.md) | `os.<name>(...)` namespace calls |
|
|
25
25
|
| `process` | [process](./node/process.md) | object: methods and properties |
|
|
26
|
-
| `buffer` | [buffer](./node/buffer.md) | `Buffer`
|
|
26
|
+
| `buffer` | [buffer](./node/buffer.md) | `Buffer` keeps its bytes in an `ArrayBuffer` store, not in properties |
|
|
27
27
|
| `stream` | [stream](./node/stream.md) | `Readable` / `Writable` / `Duplex` / `Transform` / `PassThrough` |
|
|
28
28
|
| `stream/promises` | [stream/promises](./node/stream-promises.md) | `pipeline` only |
|
|
29
|
+
| `stream/web` | [stream/web](./node/stream-web.md) | WHATWG streams, re-exported from the core runtime |
|
|
29
30
|
| `net` | [net](./node/net.md) | TCP server and client |
|
|
30
31
|
| `dgram` | [dgram](./node/dgram.md) | UDP sockets |
|
|
31
32
|
| `http` | [http](./node/http.md) | server and client, `Connection: close` |
|
|
@@ -41,7 +42,7 @@ work on another. Missing or different behaviour is recorded under
|
|
|
41
42
|
| `crypto` | [crypto](./node/crypto.md) | `createHash` (SHA-1 / SHA-256) |
|
|
42
43
|
| `url` | [url](./node/url.md) | `pathToFileURL` / `fileURLToPath` |
|
|
43
44
|
| `zlib` | [zlib](./node/zlib.md) | `createGzip` only |
|
|
44
|
-
| `worker_threads` | [worker_threads](./node/worker-threads.md) |
|
|
45
|
+
| `worker_threads` | [worker_threads](./node/worker-threads.md) | process-isolated workers: two-way messaging, `MessageChannel`, structured clone |
|
|
45
46
|
|
|
46
47
|
Additional small modules are provided with their core surface: `timers`
|
|
47
48
|
(`setTimeout`/`setInterval`/`setImmediate`), `timers/promises`, `console`
|
|
@@ -50,6 +51,12 @@ Additional small modules are provided with their core surface: `timers`
|
|
|
50
51
|
(`StringDecoder`), `diagnostics_channel` (`channel`/`tracingChannel`), and
|
|
51
52
|
`util/types` (the type predicates).
|
|
52
53
|
|
|
54
|
+
`createRequire(url)` returns a `require` that resolves the modules linked into
|
|
55
|
+
the binary: `require("fs")` / `require("node:fs")` answer the same namespace a
|
|
56
|
+
static import would. A specifier that names nothing linked (an arbitrary file or
|
|
57
|
+
an npm package the program never imported) throws — a compiled binary has no
|
|
58
|
+
module loader.
|
|
59
|
+
|
|
53
60
|
`tls` and `http2` are implemented as optional **link features** backed by the
|
|
54
61
|
vendored mbedTLS and nghttp2 libraries: `npm run tls` fetches and builds
|
|
55
62
|
`runtime/lib/<os>-<arch>/{tls,nghttp2}.{a,lib}`, and the driver links them only
|
|
@@ -32,7 +32,9 @@ Location: `src/codegen/llvm.ts` (`BINARY_RUNTIME`, `emitPrefix`, `emitPostfix`,
|
|
|
32
32
|
|
|
33
33
|
- Comma expression `,` (lowers to a `SequenceExpression`: every operand is
|
|
34
34
|
evaluated left to right and the value of the last one is the result)
|
|
35
|
-
- `in` operator (`key in obj`, mapped to `xt_in`)
|
|
35
|
+
- `in` operator (`key in obj`, mapped to `xt_in`): own properties, built-in
|
|
36
|
+
methods and the whole prototype chain, so `"map" in []` and `"slice" in "abc"`
|
|
37
|
+
behave like JavaScript
|
|
36
38
|
- `delete obj.key` / `delete obj[key]` (mapped to `xt_delete`)
|
|
37
39
|
- `instanceof` (mapped to `xt_instance_of`, walking the prototype chain)
|
|
38
40
|
|
|
@@ -29,7 +29,7 @@ Module syntax (`import` / `export`, import attributes) and the driver-level bund
|
|
|
29
29
|
- Conditional (ternary) expressions `a ? b : c`
|
|
30
30
|
- Comma / sequence expressions `a, b, c` (in `for` headers, parenthesized groups and expression statements)
|
|
31
31
|
- Arrow functions `() => expr` / `() => { ... }` (including type parameters and return type annotations)
|
|
32
|
-
- Function expressions `function () {}` and named function expressions `function g() {}` (also `async function` expressions)
|
|
32
|
+
- Function expressions `function () {}` and named function expressions `function g() {}` (also `async function` expressions); the name may be a contextual keyword (`function get() {}`, `function constructor() {}`), like a class expression name
|
|
33
33
|
- Call expressions `f(...)`, member access `a.b`, element access `a[i]`
|
|
34
34
|
- Array literals `[1, 2]`, sparse array elision, spread `[...a]` (also over strings, `Map` and `Set`)
|
|
35
35
|
- Object literals `{ a: 1 }`, shorthand properties `{ a }`, method shorthand `{ m() {} }`, getter / setter shorthand `{ get x() {} }` / `{ set x(v) {} }`, computed keys `{ [expr]: 1 }`, object spread `{ ...obj }`
|
|
@@ -16,7 +16,10 @@ standard-library surface have their own pages:
|
|
|
16
16
|
- [Async, promises and generators](./async.md)
|
|
17
17
|
- [fetch](./fetch.md)
|
|
18
18
|
|
|
19
|
-
- Allocator: non-moving mark-sweep collector behind `xt_alloc` (explicit roots, subsystem root providers and a conservative C-stack scan).
|
|
19
|
+
- Allocator: non-moving mark-sweep collector behind `xt_alloc` (explicit roots, subsystem root providers and a conservative C-stack scan). Collection is deferred while a bundle's module bodies run (`xt_gc_begin_startup` raises the threshold to 512 MiB until `xt_gc_end_startup`): a large module graph is built entirely inside one generated function, and collecting in the middle of it has corrupted live objects. `XT_GC_THRESHOLD` still overrides both values. Two environment switches exist for this class of bug: `XT_GC_VERIFY=1` re-scans
|
|
20
|
+
every marked object's payload before the sweep and prints any block it
|
|
21
|
+
references that stayed unmarked (a tracer or root gap), and the crash report
|
|
22
|
+
names a fault address that falls inside a block the collector freed. I/O worker threads allocate result values but never collect (`xt_gc_worker_thread`): the collector scans the main stack region and is not thread-safe, and a block born during a collection is marked so the sweep keeps it.
|
|
20
23
|
- Value construction: `xt_undefined/xt_null/xt_bool/xt_number/xt_string_new/xt_string_from_cstr`.
|
|
21
24
|
- Type conversion: `xt_truthy`, `xt_to_number`, `xt_to_string`, `xt_typeof`.
|
|
22
25
|
- Arithmetic: `add/sub/mul/div/mod/pow/neg/pos`.
|
|
@@ -28,5 +31,6 @@ standard-library surface have their own pages:
|
|
|
28
31
|
- Operator helpers: `xt_in` (`in`), `xt_delete` (`delete`), `xt_rest_args` (rest parameters / `arguments`).
|
|
29
32
|
- Box: `box_new/get/set` (for closure-captured variables).
|
|
30
33
|
- Functions and closures: `arg`, `closure_new/call/env/arity`.
|
|
31
|
-
- Exceptions: `xt_try_enter` / `xt_try_exception` / `xt_try_leave` maintain the `_setjmp` frame stack; `xt_throw` long-jumps to the nearest `try` when a frame exists, otherwise prints `Uncaught ...` and exits. A promise rejection nobody observes is fatal too: `xt_promise_report_unhandled` runs once the event loop drains, prints `Unhandled promise rejection` plus the reason and exits with status 1 (see [Async](./async.md)). Codegen also maintains a shadow call stack (function name, source file and line) that `Error.stack` captures (see [Standard library](./stdlib.md)), and a fatal-signal handler dumps the same frames on a native crash. `--debug` additionally emits `!DICompileUnit` / `!DISubprogram` / `!DILocation` metadata and compiles with `-g -fno-omit-frame-pointer`, so gdb/lldb/WinDbg map instructions back to source lines.
|
|
34
|
+
- Exceptions: `xt_try_enter` / `xt_try_exception` / `xt_try_leave` maintain the `_setjmp` frame stack; `xt_throw` long-jumps to the nearest `try` when a frame exists, otherwise prints `Uncaught ...` and exits. A promise rejection nobody observes is fatal too: `xt_promise_report_unhandled` runs once the event loop drains, prints `Unhandled promise rejection` plus the reason and exits with status 1 (see [Async](./async.md)). Codegen also maintains a shadow call stack (function name, source file and line) that `Error.stack` captures (see [Standard library](./stdlib.md)), and a fatal-signal handler dumps the same frames on a native crash. While a bundle's module bodies run, the stack names the module being initialised (` module: <path>` above the frames): every module shares one generated function, so its frames alone all carry the entry file's coordinates. `--debug` additionally emits `!DICompileUnit` / `!DISubprogram` / `!DILocation` metadata and compiles with `-g -fno-omit-frame-pointer`, so gdb/lldb/WinDbg map instructions back to source lines.
|
|
35
|
+
- Typed pointers that the collector follows from inside a struct (a promise's reaction list, an active coroutine frame, a string's rope children) are validated against the heap table before marking, so a stale one is skipped instead of dereferenced (`XT_GC_VERIFY=1` reports it).
|
|
32
36
|
- Objects / functions: `xt_object` with a prototype chain, `xt_function` with a property bag (static members and `prototype`); `xt_new` (instantiation), `xt_instance_of` (prototype chain), `xt_object_freeze/is_frozen/from_entries`; `xt_constructors.c` holds the first-class constructor cache, constructor prototypes and static-value dispatch.
|
|
@@ -19,6 +19,31 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
19
19
|
- `Object.freeze` / `is_frozen` / `from_entries`, `Object.getPrototypeOf`.
|
|
20
20
|
- `Object.prototype`: `hasOwnProperty` / `toString` / `valueOf` / `isPrototypeOf` / `propertyIsEnumerable` / `__proto__`; `Object.getPrototypeOf({}) === Object.prototype`.
|
|
21
21
|
- First-class built-in constructors (`const A = Array`, `new A(...)`, `A.isArray`, `x instanceof A`) are covered in [Codegen](./codegen.md#llvm-ir-code-generation-codegen).
|
|
22
|
+
- A function value's `.prototype` is created on first read (with a
|
|
23
|
+
`constructor` back-reference) and shared by every closure of one declaration, so
|
|
24
|
+
the ES5 pattern `function Foo() {}; Foo.prototype.bar = ...; new Foo().bar()`
|
|
25
|
+
works. Function *values* are still fresh per reference (`Foo === Foo` is false).
|
|
26
|
+
- `Object.getOwnPropertyNames` / `Object.keys` report no own string keys for
|
|
27
|
+
`Map` / `Set` / `Date` / `RegExp` / `Promise` / `Symbol` instead of reading past
|
|
28
|
+
their allocation.
|
|
29
|
+
|
|
30
|
+
## `globalThis` and `Intl`
|
|
31
|
+
|
|
32
|
+
- `globalThis.x` / `global.x` read a *known* global as the bare name
|
|
33
|
+
(`globalThis.fetch`, `globalThis.Deno`); any other property is an ordinary
|
|
34
|
+
read on the global object, so `globalThis.missing` is `undefined` and
|
|
35
|
+
`global[key] = v` round-trips.
|
|
36
|
+
- `globalThis` (and Node's alias `global`) is a value: one plain property bag
|
|
37
|
+
shared by both spellings, so `const g = globalThis`, `globalThis.x = 1` and
|
|
38
|
+
publishing state under a symbol key on `global` all work. It is not the
|
|
39
|
+
runtime's scope object — a name the compiler does not resolve is `undefined`
|
|
40
|
+
even when a library wrote it with `global.foo = ...`.
|
|
41
|
+
- `Intl.Segmenter` with `granularity: "grapheme" | "word"`; `segment(text)`
|
|
42
|
+
returns an **array** of `{ segment, index, isWordLike }`. It is a documented
|
|
43
|
+
approximation of UAX #29 (no ICU): graphemes are code points plus combining
|
|
44
|
+
marks, variation selectors, emoji modifiers, ZWJ sequences and regional
|
|
45
|
+
indicator pairs; words are runs of whitespace, word characters and punctuation.
|
|
46
|
+
`resolvedOptions()` reports `{ locale: "en", granularity }`.
|
|
22
47
|
|
|
23
48
|
## Arrays
|
|
24
49
|
|
|
@@ -38,12 +63,12 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
38
63
|
## JSON
|
|
39
64
|
|
|
40
65
|
- `JSON.parse` with a `reviver`; malformed input (bad numbers/strings, trailing text, missing separators) throws a catchable `SyntaxError` instead of returning `undefined`.
|
|
41
|
-
- `JSON.stringify` with a function or array `replacer`, `toJSON`, and `space` (number or string, clamped to 10). `undefined` / function / symbol values follow the standard omission rules.
|
|
66
|
+
- `JSON.stringify` with a function or array `replacer`, `toJSON`, and `space` (number or string, clamped to 10). `toJSON` runs for every object and receives the property key (`""` at the top level, the index for an array element), before the value is inspected, so a value whose `toJSON` returns `undefined` is omitted from an object and becomes `null` in an array. `undefined` / function / symbol values follow the standard omission rules.
|
|
42
67
|
- Object keys are emitted in insertion order, with integer keys ordered numerically; circular references throw.
|
|
43
68
|
|
|
44
69
|
## Date
|
|
45
70
|
|
|
46
|
-
- `Date` backed by `gmtime_r`; ISO 8601 parsing through `Date.parse` / `new Date(string)`.
|
|
71
|
+
- `Date` backed by `gmtime_r`; ISO 8601 parsing through `Date.parse` / `new Date(string)`. `toJSON` returns `null` for an invalid (NaN) time instead of throwing.
|
|
47
72
|
- `toLocaleDateString` / `toLocaleTimeString` / `toLocaleString` format the local time (`M/D/YYYY`, `h:mm:ss AM`); a small options subset (`weekday`/`year`/`month`/`day`/`hour`/`minute`/`second`/`hour12`) is honoured. `toDateString` / `toTimeString` / `toUTCString` are available too, and an invalid date formats as `Invalid Date`.
|
|
48
73
|
|
|
49
74
|
## RegExp
|
|
@@ -102,3 +127,45 @@ own pages: [Collections](./collections.md), [Typed arrays and binary data](./typ
|
|
|
102
127
|
- `crypto.getRandomValues(typedArray)` fills an integer typed array (up to 65 536 bytes) from the OS CSPRNG and returns it; `crypto.randomUUID()` returns a v4 UUID string. `crypto` is also a first-class object and the methods can be detached (`const uuid = crypto.randomUUID`).
|
|
103
128
|
- `Math.random` draws from a xoshiro256** stream seeded from the OS CSPRNG (53 random bits), not from the C `rand()`.
|
|
104
129
|
- Node's `crypto.randomBytes` / `randomInt` / `randomFillSync` / `pbkdf2Sync` surface is documented in [node/crypto](../implemented/node/crypto.md).
|
|
130
|
+
|
|
131
|
+
## Proxy
|
|
132
|
+
|
|
133
|
+
`new Proxy(target, handler)` is implemented as a host view (`runtime/xt_proxy.c`):
|
|
134
|
+
the proxy is an object whose own property bag stays empty, so every string-keyed
|
|
135
|
+
lookup misses and reaches the handler.
|
|
136
|
+
|
|
137
|
+
- Traps: `get(target, key, receiver)`, `set(target, key, value, receiver)`,
|
|
138
|
+
`has(target, key)`, `deleteProperty(target, key)` and `ownKeys(target)`.
|
|
139
|
+
An absent trap forwards the operation to the target, so `new Proxy(obj, {})`
|
|
140
|
+
behaves like `obj` (writes and deletes included).
|
|
141
|
+
- `Object.keys` / `JSON.stringify` / `for...in` use the `ownKeys` result; reads
|
|
142
|
+
of those keys go through `get`. `typeof` is `"object"`, and the proxy inherits
|
|
143
|
+
the target's prototype, so inherited methods and `instanceof` work.
|
|
144
|
+
- Not modelled: function targets (`apply` / `construct` traps), `Proxy.revocable`,
|
|
145
|
+
the prototype and property-descriptor traps (`getPrototypeOf`,
|
|
146
|
+
`setPrototypeOf`, `getOwnPropertyDescriptor`, `defineProperty`,
|
|
147
|
+
`isExtensible`, …), and invariant checking (a trap may report a key the target
|
|
148
|
+
does not have). The target and handler are stored as hidden symbol-keyed
|
|
149
|
+
properties, so `Object.getOwnPropertySymbols(proxy)` reports them.
|
|
150
|
+
|
|
151
|
+
## Web platform globals
|
|
152
|
+
|
|
153
|
+
Implemented in `runtime/xt_web_abort.c` (aborts) and `runtime/xt_fetch/webapi.inc`
|
|
154
|
+
(`Headers` / `Response`, built on the `fetch` implementation):
|
|
155
|
+
|
|
156
|
+
- `AbortController` / `AbortSignal`: `abort(reason?)`, the `aborted` / `reason` /
|
|
157
|
+
`onabort` accessors, `addEventListener("abort", fn[, { once }])` /
|
|
158
|
+
`removeEventListener`, `throwIfAborted()`, and the statics `AbortSignal.abort()`,
|
|
159
|
+
`AbortSignal.timeout(ms)` and `AbortSignal.any([...])`. The default reasons are
|
|
160
|
+
`AbortError` / `TimeoutError` errors (`error.name`). `fetch` does not consume a
|
|
161
|
+
signal yet, so aborting does not cancel an in-flight request.
|
|
162
|
+
- `Headers`: the case-insensitive map `get` / `has` / `set` / `append` / `delete`
|
|
163
|
+
/ `forEach` / `keys` / `values` / `entries` / `getSetCookie`, constructible from
|
|
164
|
+
a plain object, an array of pairs or another `Headers`. `fetch` hands out
|
|
165
|
+
`Headers` instances (`instanceof` holds).
|
|
166
|
+
- `Response`: `new Response(body?, init?)` with `status` / `statusText` /
|
|
167
|
+
`headers`, and `text()` / `json()` / `arrayBuffer()` / `bytes()` / `clone()`.
|
|
168
|
+
`arrayBuffer()` resolves to a real `ArrayBuffer`, `bytes()` to a `Uint8Array`.
|
|
169
|
+
- `JSON`, `ArrayBuffer` and `DataView` are values too (`const s = JSON.stringify`,
|
|
170
|
+
`ArrayBuffer.prototype`, `new DataView(buffer)`); `JSON` keeps its dedicated
|
|
171
|
+
call lowering and also works when read as an object.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Web Streams
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/streams.md)
|
|
4
|
+
|
|
5
|
+
Location: `runtime/xt_streams.c` and `runtime/xt_streams/`. The classes are core
|
|
6
|
+
runtime globals, so they are available without any extension flag; Node's
|
|
7
|
+
`stream/web` module re-exports the same constructors (see
|
|
8
|
+
[stream/web](./node/stream-web.md)).
|
|
9
|
+
|
|
10
|
+
## Classes
|
|
11
|
+
|
|
12
|
+
| Class | Notes |
|
|
13
|
+
| --- | --- |
|
|
14
|
+
| `ReadableStream` | underlying source `start` / `pull` / `cancel`; `getReader`, `cancel`, `tee`, `pipeTo`, `pipeThrough`, `values`, `[Symbol.asyncIterator]`, `locked` |
|
|
15
|
+
| `ReadableStreamDefaultReader` | `read`, `cancel`, `releaseLock`, `closed` |
|
|
16
|
+
| `ReadableStreamDefaultController` | `enqueue`, `close`, `error`, `desiredSize` |
|
|
17
|
+
| `WritableStream` | underlying sink `start` / `write` / `close` / `abort`; `getWriter`, `close`, `abort`, `locked` |
|
|
18
|
+
| `WritableStreamDefaultWriter` | `write`, `close`, `abort`, `releaseLock`, `closed`, `ready`, `desiredSize` |
|
|
19
|
+
| `WritableStreamDefaultController` | `error` |
|
|
20
|
+
| `TransformStream` | transformer `start` / `transform` / `flush`; `readable`, `writable` |
|
|
21
|
+
| `TransformStreamDefaultController` | `enqueue`, `error`, `terminate`, `desiredSize` |
|
|
22
|
+
| `TextEncoderStream` | string chunks in, UTF-8 `Uint8Array` chunks out |
|
|
23
|
+
| `TextDecoderStream` | `Uint8Array` chunks in, string chunks out |
|
|
24
|
+
| `CountQueuingStrategy` / `ByteLengthQueuingStrategy` | `highWaterMark` and `size(chunk)` |
|
|
25
|
+
|
|
26
|
+
`ReadableStream.from(iterable)` builds a readable stream from an array, string
|
|
27
|
+
or any synchronous or asynchronous iterable. The constructors are first-class
|
|
28
|
+
values, so
|
|
29
|
+
`const RS = ReadableStream; new RS(...)`, `ReadableStream.from(...)` and
|
|
30
|
+
`stream instanceof ReadableStream` all work.
|
|
31
|
+
|
|
32
|
+
### Example
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
async function main(): Promise<void> {
|
|
36
|
+
const transform = new TransformStream<string, string>({
|
|
37
|
+
transform(chunk, controller) {
|
|
38
|
+
controller.enqueue(chunk.toUpperCase());
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const writer = transform.writable.getWriter();
|
|
42
|
+
const reader = transform.readable.getReader();
|
|
43
|
+
|
|
44
|
+
const first = reader.read();
|
|
45
|
+
await writer.write("hello");
|
|
46
|
+
console.log(JSON.stringify(await first)); // {"value":"HELLO","done":false}
|
|
47
|
+
const done = reader.read();
|
|
48
|
+
await writer.close();
|
|
49
|
+
console.log(JSON.stringify(await done)); // {"done":true}
|
|
50
|
+
}
|
|
51
|
+
main();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Async model
|
|
55
|
+
|
|
56
|
+
`start`, `pull`, `write`, `close`, `abort`, `cancel`, `transform` and `flush`
|
|
57
|
+
may return a promise. The stream machinery chains it through the runtime promise
|
|
58
|
+
queue, so a `pull` that waits for a timer or socket keeps the event loop alive
|
|
59
|
+
and a slow sink serialises writes without blocking it. Reader and writer methods
|
|
60
|
+
return promises; `reader.read()` on an empty stream stays pending until `pull`
|
|
61
|
+
(or another producer) enqueues a chunk.
|
|
62
|
+
|
|
63
|
+
Backpressure is honoured through `desiredSize` and `writer.ready`: `pull` is
|
|
64
|
+
called while a reader has demand and the readable queue is below its
|
|
65
|
+
high-water mark, and `writer.ready` stays pending while the writable queue is
|
|
66
|
+
full.
|
|
67
|
+
|
|
68
|
+
## Limits
|
|
69
|
+
|
|
70
|
+
- **No byte streams / BYOB.** `getReader({ mode: "byob" })` throws
|
|
71
|
+
`TypeError`; `ReadableStreamBYOBReader` and `ReadableStreamBYOBRequest` exist
|
|
72
|
+
as names but their constructors throw.
|
|
73
|
+
- **No compression streams.** `CompressionStream` and `DecompressionStream` are
|
|
74
|
+
exported by `node:stream/web` but their constructors throw a clear error.
|
|
75
|
+
- `TextDecoderStream` decodes each chunk independently, so a UTF-8 sequence
|
|
76
|
+
split across two chunks is not reassembled.
|
|
77
|
+
- `tee` buffers into the two branches without independent backpressure; for an
|
|
78
|
+
unbounded source the slower branch accumulates chunks.
|
|
79
|
+
- `pipeTo` ignores `preventClose` / `preventAbort` / `signal` options.
|
|
80
|
+
- The classes are ordinary runtime objects; the Web IDL brand checks, transfer
|
|
81
|
+
(`postMessage`) and `ReadableStream` ownership in `fetch` responses are not
|
|
82
|
+
implemented.
|