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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Function values and their `.prototype` objects.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `objects.inc` to keep both files inside the repository's
|
|
5
|
+
* length budget; included before it because `xt_object_get` resolves
|
|
6
|
+
* `fn.prototype` through `xt_function_prototype_object`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* The `.prototype` object of a function value, created on first use with a
|
|
10
|
+
* `constructor` back-reference. `xt_new` and `fn.prototype` must agree on it so
|
|
11
|
+
* the ES5 pattern `function Foo() {}; Foo.prototype.bar = ...` keeps working.
|
|
12
|
+
*
|
|
13
|
+
* Every reference to a declared function builds a fresh closure value (`Foo`
|
|
14
|
+
* inside `Foo.prototype` is not the same value as the `Foo` used by `new`), so
|
|
15
|
+
* the prototype is keyed by the compiled code pointer and shared by all
|
|
16
|
+
* closures of that declaration. Without this, `new Foo()` had a different
|
|
17
|
+
* prototype than `Foo.prototype` and instance methods were invisible. */
|
|
18
|
+
typedef struct xt_function_proto_slot {
|
|
19
|
+
xt_code_fn code;
|
|
20
|
+
xt_value proto;
|
|
21
|
+
struct xt_function_proto_slot *next;
|
|
22
|
+
} xt_function_proto_slot;
|
|
23
|
+
|
|
24
|
+
static xt_function_proto_slot *xt_function_proto_slots = NULL;
|
|
25
|
+
static int xt_function_proto_registered = 0;
|
|
26
|
+
|
|
27
|
+
static void xt_function_proto_roots(void) {
|
|
28
|
+
for (xt_function_proto_slot *slot = xt_function_proto_slots; slot; slot = slot->next) {
|
|
29
|
+
xt_gc_mark_value(slot->proto);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
xt_value xt_function_prototype_object(xt_value value) {
|
|
34
|
+
if (!XT_IS_FUNCTION(value)) return XT_UNDEFINED;
|
|
35
|
+
xt_function *function = (xt_function *)XT_GET_PTR(value);
|
|
36
|
+
if (function->prototype != XT_UNDEFINED) return function->prototype;
|
|
37
|
+
if (!xt_function_proto_registered) {
|
|
38
|
+
xt_function_proto_registered = 1;
|
|
39
|
+
xt_gc_register_root_provider(xt_function_proto_roots);
|
|
40
|
+
}
|
|
41
|
+
for (xt_function_proto_slot *slot = xt_function_proto_slots; slot; slot = slot->next) {
|
|
42
|
+
if (slot->code == function->code) {
|
|
43
|
+
function->prototype = slot->proto;
|
|
44
|
+
return slot->proto;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
xt_value proto = xt_object_new();
|
|
48
|
+
xt_object_set(proto, xt_string_from_cstr("constructor"), value);
|
|
49
|
+
xt_function_proto_slot *slot = (xt_function_proto_slot *)malloc(sizeof(xt_function_proto_slot));
|
|
50
|
+
if (slot) {
|
|
51
|
+
slot->code = function->code;
|
|
52
|
+
slot->proto = proto;
|
|
53
|
+
slot->next = xt_function_proto_slots;
|
|
54
|
+
xt_function_proto_slots = slot;
|
|
55
|
+
}
|
|
56
|
+
function->prototype = proto;
|
|
57
|
+
return proto;
|
|
58
|
+
}
|
|
@@ -125,6 +125,13 @@ xt_value xt_function_prototype(void) {
|
|
|
125
125
|
xt_function_proto_ready = 1;
|
|
126
126
|
xt_function_proto_root = xt_object_new_with_proto(xt_object_prototype());
|
|
127
127
|
xt_gc_add_root(&xt_function_proto_root);
|
|
128
|
+
/* `Function.prototype.call` / `.apply` / `.bind` / `.toString` are values
|
|
129
|
+
* libraries uncurry (`Function.call.bind(...)`), and
|
|
130
|
+
* `Function.prototype[Symbol.hasInstance]` must be present for the same
|
|
131
|
+
* reason. */
|
|
132
|
+
xt_install_proto_methods(xt_function_proto_root, "Function");
|
|
133
|
+
xt_object_set(xt_function_proto_root, xt_symbol_well_known("hasInstance"),
|
|
134
|
+
xt_function_has_instance_method());
|
|
128
135
|
/* `Array.constructor === Function` (every function inherits from here). The
|
|
129
136
|
* factory sees the ready flag, so this does not recurse. */
|
|
130
137
|
xt_value constructor = xt_builtin_constructor(xt_string_from_cstr("Function"));
|
|
@@ -282,9 +289,12 @@ static int xt_key_is_prototype(xt_value key) {
|
|
|
282
289
|
xt_value xt_object_get(xt_value value, xt_value key) {
|
|
283
290
|
/* A function's `.prototype` lives in a dedicated field (set by
|
|
284
291
|
`xt_function_set_prototype`), not in its property bag. Expose it as a
|
|
285
|
-
normal property so `Class.prototype` returns the object instances use.
|
|
292
|
+
normal property so `Class.prototype` returns the object instances use.
|
|
293
|
+
A plain function declaration starts without one — ES5 code assigns
|
|
294
|
+
`Foo.prototype.bar = ...` right after declaring `Foo`, so materialise it on
|
|
295
|
+
first read, like the specification's [[Construct]]-able function. */
|
|
286
296
|
if (XT_IS_FUNCTION(value) && xt_key_is_prototype(key)) {
|
|
287
|
-
return (
|
|
297
|
+
return xt_function_prototype_object(value);
|
|
288
298
|
}
|
|
289
299
|
xt_object *obj = xt_as_object(value);
|
|
290
300
|
if (!obj) return XT_UNDEFINED;
|
|
@@ -523,6 +533,12 @@ xt_value xt_object_keys(xt_value value) {
|
|
|
523
533
|
}
|
|
524
534
|
if (XT_IS_OBJECT(value)) {
|
|
525
535
|
xt_object *obj = (xt_object *)XT_GET_PTR(value);
|
|
536
|
+
/* Map/Set/Date/RegExp/Promise/Symbol use their own layout and have no
|
|
537
|
+
* property bag; reading `obj->count` there walked off the end of the
|
|
538
|
+
* allocation (`Object.getOwnPropertyNames(new Map())` crashed). */
|
|
539
|
+
if (obj->header.kind != XT_OBJECT_KIND_OBJECT && obj->header.kind != XT_OBJECT_KIND_ERROR) {
|
|
540
|
+
return result;
|
|
541
|
+
}
|
|
526
542
|
for (uint32_t i = 0; i < obj->count; i++) {
|
|
527
543
|
if (XT_IS_STRING(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
|
|
528
544
|
}
|
package/runtime/xt_containers.c
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — program termination.
|
|
3
|
+
*
|
|
4
|
+
* The generated `main` runs the module body, drains microtasks, pumps the
|
|
5
|
+
* reactor and then calls `xt_finish()`, which gives the host one last chance to
|
|
6
|
+
* run JavaScript before the process ends: the Node extension registers a hook
|
|
7
|
+
* that fires the `process` "exit" listeners there. `xt_finish` also returns the
|
|
8
|
+
* status the program asked for, because the generated `main` no longer returns a
|
|
9
|
+
* constant — `process.exitCode = 1` (and `process.exit(1)`, which ends up in the
|
|
10
|
+
* same place) reaches the parent process.
|
|
11
|
+
*
|
|
12
|
+
* The hook runs at most once: `process.exit()` calls `xt_finish()` itself before
|
|
13
|
+
* `exit()`, so the terminating call cannot fire the listeners a second time.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include "rt.h"
|
|
17
|
+
|
|
18
|
+
static int xt_exit_status_value = 0;
|
|
19
|
+
static xt_exit_hook xt_exit_hook_value = NULL;
|
|
20
|
+
static int xt_exit_hook_done = 0;
|
|
21
|
+
|
|
22
|
+
void xt_set_exit_status(int status) { xt_exit_status_value = status; }
|
|
23
|
+
|
|
24
|
+
int xt_get_exit_status(void) { return xt_exit_status_value; }
|
|
25
|
+
|
|
26
|
+
void xt_at_exit(xt_exit_hook hook) { xt_exit_hook_value = hook; }
|
|
27
|
+
|
|
28
|
+
int xt_finish(void) {
|
|
29
|
+
if (!xt_exit_hook_done) {
|
|
30
|
+
xt_exit_hook_done = 1;
|
|
31
|
+
if (xt_exit_hook_value) xt_exit_hook_value();
|
|
32
|
+
}
|
|
33
|
+
return xt_exit_status_value;
|
|
34
|
+
}
|
|
@@ -206,6 +206,7 @@ static xt_value xt_headers_method_to_string(xt_value thisValue, xt_value env, in
|
|
|
206
206
|
|
|
207
207
|
static xt_value xt_headers_new(void) {
|
|
208
208
|
xt_value headers = xt_object_new();
|
|
209
|
+
xt_object_set_prototype(headers, xt_web_headers_proto());
|
|
209
210
|
xt_object_set(headers, xt_string_from_cstr("__map"), xt_object_new());
|
|
210
211
|
xt_fetch_set_method(headers, "get", (void *)xt_headers_method_get);
|
|
211
212
|
xt_fetch_set_method(headers, "has", (void *)xt_headers_method_has);
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* though the value is already available.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
/* Typed-array constructor (xt_typed_array.c); `bytes()` wraps the body buffer. */
|
|
12
|
+
xt_value xt_ta_u8_ctor(int32_t argc, xt_value *argv);
|
|
13
|
+
|
|
11
14
|
static void *xt_response_method_impl(xt_value name);
|
|
12
15
|
static xt_value xt_method_value_for_response(xt_value name);
|
|
13
16
|
|
|
@@ -31,19 +34,34 @@ static xt_value xt_response_method_json(xt_value thisValue, xt_value env, int32_
|
|
|
31
34
|
return xt_promise_resolve(xt_json_parse(1, &body));
|
|
32
35
|
}
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(void)argv;
|
|
37
|
+
/* The body as a real `ArrayBuffer` (the platform type), built from the buffered
|
|
38
|
+
* bytes. `bytes()` wraps the same buffer in a `Uint8Array`. */
|
|
39
|
+
static xt_value xt_response_body_buffer(xt_value thisValue) {
|
|
38
40
|
xt_value body = xt_response_body(thisValue);
|
|
39
41
|
const char *data = xt_string_data(body);
|
|
40
42
|
int32_t length = xt_string_length_value(body);
|
|
41
43
|
if (!data || length < 0) length = 0;
|
|
42
|
-
xt_value
|
|
44
|
+
xt_value lengthValue = xt_number((double)length);
|
|
45
|
+
xt_value buffer = xt_array_buffer_ctor(1, &lengthValue);
|
|
43
46
|
for (int32_t i = 0; i < length; i++) {
|
|
44
|
-
|
|
47
|
+
xt_array_buffer_set_byte(buffer, (uint32_t)i, (uint8_t)data[i]);
|
|
45
48
|
}
|
|
46
|
-
return
|
|
49
|
+
return buffer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static xt_value xt_response_method_array_buffer(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
53
|
+
(void)env;
|
|
54
|
+
(void)argc;
|
|
55
|
+
(void)argv;
|
|
56
|
+
return xt_promise_resolve(xt_response_body_buffer(thisValue));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static xt_value xt_response_method_bytes(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
60
|
+
(void)env;
|
|
61
|
+
(void)argc;
|
|
62
|
+
(void)argv;
|
|
63
|
+
xt_value buffer = xt_response_body_buffer(thisValue);
|
|
64
|
+
return xt_promise_resolve(xt_ta_u8_ctor(1, &buffer));
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
static xt_value xt_response_method_clone(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
@@ -51,6 +69,7 @@ static xt_value xt_response_method_clone(xt_value thisValue, xt_value env, int32
|
|
|
51
69
|
(void)argc;
|
|
52
70
|
(void)argv;
|
|
53
71
|
xt_value clone = xt_object_new();
|
|
72
|
+
xt_object_set_prototype(clone, xt_web_response_proto());
|
|
54
73
|
xt_value keys = xt_object_keys(thisValue);
|
|
55
74
|
int32_t count = (int32_t)xt_to_number(xt_array_length(keys));
|
|
56
75
|
for (int32_t i = 0; i < count; i++) {
|
|
@@ -101,7 +120,8 @@ static xt_value xt_response_new(xt_value headers, int status, const char *status
|
|
|
101
120
|
xt_fetch_set_method(response, "text", (void *)xt_response_method_text);
|
|
102
121
|
xt_fetch_set_method(response, "json", (void *)xt_response_method_json);
|
|
103
122
|
xt_fetch_set_method(response, "arrayBuffer", (void *)xt_response_method_array_buffer);
|
|
104
|
-
xt_fetch_set_method(response, "bytes", (void *)
|
|
123
|
+
xt_fetch_set_method(response, "bytes", (void *)xt_response_method_bytes);
|
|
105
124
|
xt_fetch_set_method(response, "clone", (void *)xt_response_method_clone);
|
|
125
|
+
xt_object_set_prototype(response, xt_web_response_proto());
|
|
106
126
|
return response;
|
|
107
127
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — the `Headers` and `Response` globals.
|
|
3
|
+
*
|
|
4
|
+
* `fetch` builds both as ordinary objects with own method closures; these
|
|
5
|
+
* constructors reuse the same builders and chain the objects onto a shared
|
|
6
|
+
* prototype, so `new Headers(...)` / `new Response(...)` work, the platform
|
|
7
|
+
* methods are reachable through the prototype, and `instanceof` holds for
|
|
8
|
+
* fetch's own objects too.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* -- Headers -------------------------------------------------------------- */
|
|
12
|
+
|
|
13
|
+
xt_value xt_web_headers_proto(void) {
|
|
14
|
+
static xt_value proto = XT_UNDEFINED;
|
|
15
|
+
if (proto != XT_UNDEFINED) return proto;
|
|
16
|
+
proto = xt_object_new();
|
|
17
|
+
xt_gc_add_root(&proto);
|
|
18
|
+
xt_fetch_set_method(proto, "get", (void *)xt_headers_method_get);
|
|
19
|
+
xt_fetch_set_method(proto, "has", (void *)xt_headers_method_has);
|
|
20
|
+
xt_fetch_set_method(proto, "set", (void *)xt_headers_method_set);
|
|
21
|
+
xt_fetch_set_method(proto, "append", (void *)xt_headers_method_append);
|
|
22
|
+
xt_fetch_set_method(proto, "delete", (void *)xt_headers_method_delete);
|
|
23
|
+
xt_fetch_set_method(proto, "forEach", (void *)xt_headers_method_forEach);
|
|
24
|
+
xt_fetch_set_method(proto, "keys", (void *)xt_headers_method_keys);
|
|
25
|
+
xt_fetch_set_method(proto, "values", (void *)xt_headers_method_values);
|
|
26
|
+
xt_fetch_set_method(proto, "entries", (void *)xt_headers_method_entries);
|
|
27
|
+
xt_fetch_set_method(proto, "getSetCookie", (void *)xt_headers_method_get_set_cookie);
|
|
28
|
+
xt_fetch_set_method(proto, "toString", (void *)xt_headers_method_to_string);
|
|
29
|
+
return proto;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
xt_value xt_headers_ctor(int32_t argc, xt_value *argv) {
|
|
33
|
+
xt_value headers = xt_headers_from_source(xt_arg(argc, argv, 0));
|
|
34
|
+
xt_object_set_prototype(headers, xt_web_headers_proto());
|
|
35
|
+
return headers;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* -- Response ------------------------------------------------------------- */
|
|
39
|
+
|
|
40
|
+
xt_value xt_web_response_proto(void) {
|
|
41
|
+
static xt_value proto = XT_UNDEFINED;
|
|
42
|
+
if (proto != XT_UNDEFINED) return proto;
|
|
43
|
+
proto = xt_object_new();
|
|
44
|
+
xt_gc_add_root(&proto);
|
|
45
|
+
xt_fetch_set_method(proto, "text", (void *)xt_response_method_text);
|
|
46
|
+
xt_fetch_set_method(proto, "json", (void *)xt_response_method_json);
|
|
47
|
+
xt_fetch_set_method(proto, "arrayBuffer", (void *)xt_response_method_array_buffer);
|
|
48
|
+
xt_fetch_set_method(proto, "bytes", (void *)xt_response_method_bytes);
|
|
49
|
+
xt_fetch_set_method(proto, "clone", (void *)xt_response_method_clone);
|
|
50
|
+
return proto;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* The body bytes of a `BodyInit`: strings keep their bytes, anything else goes
|
|
54
|
+
* through the ordinary string conversion (Blob / FormData bodies are not
|
|
55
|
+
* modelled yet). */
|
|
56
|
+
static void xt_web_body_bytes(xt_value body, const char **data, size_t *length) {
|
|
57
|
+
*data = "";
|
|
58
|
+
*length = 0;
|
|
59
|
+
if (body == XT_UNDEFINED || body == XT_NULL) return;
|
|
60
|
+
xt_value text = XT_IS_STRING(body) ? body : xt_to_string(body);
|
|
61
|
+
*data = xt_string_data(text);
|
|
62
|
+
*length = (size_t)xt_string_length_value(text);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
xt_value xt_response_ctor(int32_t argc, xt_value *argv) {
|
|
66
|
+
xt_value body = xt_arg(argc, argv, 0);
|
|
67
|
+
xt_value init = xt_arg(argc, argv, 1);
|
|
68
|
+
int status = 200;
|
|
69
|
+
const char *statusText = "";
|
|
70
|
+
xt_value headers = XT_UNDEFINED;
|
|
71
|
+
if (XT_IS_OBJECT(init)) {
|
|
72
|
+
headers = xt_object_get_cstr(init, "headers");
|
|
73
|
+
xt_value statusValue = xt_object_get_cstr(init, "status");
|
|
74
|
+
if (XT_IS_NUMBER(statusValue)) status = (int)xt_to_number(statusValue);
|
|
75
|
+
xt_value textValue = xt_object_get_cstr(init, "statusText");
|
|
76
|
+
if (XT_IS_STRING(textValue)) statusText = xt_string_data(textValue);
|
|
77
|
+
}
|
|
78
|
+
const char *data = "";
|
|
79
|
+
size_t length = 0;
|
|
80
|
+
xt_web_body_bytes(body, &data, &length);
|
|
81
|
+
return xt_response_new(xt_headers_from_source(headers), status, statusText, "", data, length);
|
|
82
|
+
}
|
package/runtime/xt_fetch.c
CHANGED
|
@@ -35,6 +35,10 @@ typedef socklen_t xt_fetch_socklen_t;
|
|
|
35
35
|
#define xt_fetch_close_socket close
|
|
36
36
|
#endif
|
|
37
37
|
|
|
38
|
+
/* Prototypes of the `Headers` / `Response` globals (defined in webapi.inc). */
|
|
39
|
+
xt_value xt_web_headers_proto(void);
|
|
40
|
+
xt_value xt_web_response_proto(void);
|
|
41
|
+
|
|
38
42
|
#include "xt_fetch/buffer.inc"
|
|
39
43
|
#include "xt_fetch/url.inc"
|
|
40
44
|
#include "xt_fetch/socket.inc"
|
|
@@ -42,3 +46,4 @@ typedef socklen_t xt_fetch_socklen_t;
|
|
|
42
46
|
#include "xt_fetch/response.inc"
|
|
43
47
|
#include "xt_fetch/request.inc"
|
|
44
48
|
#include "xt_fetch/async.inc"
|
|
49
|
+
#include "xt_fetch/webapi.inc"
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* `XT_GC_VERIFY=1`: check that the collector keeps every object a live object
|
|
3
|
+
* points at.
|
|
4
|
+
*
|
|
5
|
+
* After the mark phase and *before* the sweep, walk every marked object's
|
|
6
|
+
* payload conservatively (the same way the collector scans the stack) and
|
|
7
|
+
* report each heap block it references that is not marked. A hit means either
|
|
8
|
+
* the tracer for that object kind skips a field, or the referenced block was
|
|
9
|
+
* never reachable from a root — both are the class of bug that ends in a
|
|
10
|
+
* use-after-free far away from the collection.
|
|
11
|
+
*
|
|
12
|
+
* Debug-only: the walk is O(live objects × payload) and allocates nothing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
#include "rt_internal.h"
|
|
16
|
+
|
|
17
|
+
#include <stdio.h>
|
|
18
|
+
#include <stdlib.h>
|
|
19
|
+
#include <string.h>
|
|
20
|
+
|
|
21
|
+
/** Lookup a raw address in the collector's table (xt_alloc.c). */
|
|
22
|
+
xt_header *xt_gc_lookup_raw(uintptr_t address);
|
|
23
|
+
|
|
24
|
+
static const char *xt_gc_kind_name(uint8_t kind) {
|
|
25
|
+
switch (kind) {
|
|
26
|
+
case XT_OBJECT_KIND_STRING: return "string";
|
|
27
|
+
case XT_OBJECT_KIND_OBJECT: return "object";
|
|
28
|
+
case XT_OBJECT_KIND_ARRAY: return "array";
|
|
29
|
+
case XT_OBJECT_KIND_FUNCTION: return "function";
|
|
30
|
+
case XT_OBJECT_KIND_PROMISE: return "promise";
|
|
31
|
+
case XT_OBJECT_KIND_MAP: return "map";
|
|
32
|
+
case XT_OBJECT_KIND_SET: return "set";
|
|
33
|
+
case XT_OBJECT_KIND_DATE: return "date";
|
|
34
|
+
case XT_OBJECT_KIND_REGEXP: return "regexp";
|
|
35
|
+
case XT_OBJECT_KIND_SYMBOL: return "symbol";
|
|
36
|
+
case XT_OBJECT_KIND_BIGINT: return "bigint";
|
|
37
|
+
case XT_OBJECT_KIND_ERROR: return "error";
|
|
38
|
+
case XT_OBJECT_KIND_GENERATOR: return "generator";
|
|
39
|
+
case XT_OBJECT_KIND_ITERATOR: return "iterator";
|
|
40
|
+
case XT_OBJECT_KIND_ASYNC: return "async";
|
|
41
|
+
case XT_OBJECT_KIND_ASYNC_ITERATOR: return "async-iterator";
|
|
42
|
+
case XT_OBJECT_KIND_WEAK_MAP: return "weakmap";
|
|
43
|
+
case XT_OBJECT_KIND_WEAK_SET: return "weakset";
|
|
44
|
+
case XT_OBJECT_KIND_WEAK_REF: return "weakref";
|
|
45
|
+
default: return "?";
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Does `word` name a heap block (raw pointer or NaN-boxed value)? */
|
|
50
|
+
static xt_header *xt_gc_verify_word(uint64_t word) {
|
|
51
|
+
if (XT_IS_STRING(word) || XT_IS_OBJECT(word) || XT_IS_ARRAY(word) || XT_IS_FUNCTION(word) ||
|
|
52
|
+
XT_IS_BIGINT(word)) {
|
|
53
|
+
return xt_gc_lookup_raw((uintptr_t)XT_GET_PTR(word));
|
|
54
|
+
}
|
|
55
|
+
return xt_gc_lookup_raw((uintptr_t)word);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
void xt_gc_verify_payloads(void) {
|
|
59
|
+
size_t misses = 0;
|
|
60
|
+
for (xt_header *header = xt_gc_heap_head(); header != NULL; header = header->gc_next) {
|
|
61
|
+
if ((header->flags & XT_GC_MARK) == 0) continue;
|
|
62
|
+
if (header->size <= sizeof(xt_header)) continue;
|
|
63
|
+
const uint64_t *words = (const uint64_t *)((const char *)header + sizeof(xt_header));
|
|
64
|
+
size_t count = (header->size - sizeof(xt_header)) / sizeof(uint64_t);
|
|
65
|
+
for (size_t i = 0; i < count; i++) {
|
|
66
|
+
xt_header *target = xt_gc_verify_word(words[i]);
|
|
67
|
+
if (target == NULL || (target->flags & XT_GC_MARK) != 0) continue;
|
|
68
|
+
fprintf(stderr,
|
|
69
|
+
"xbintsc: gc verify: %s(%u bytes) at word %zu references unmarked %s(%u bytes)\n",
|
|
70
|
+
xt_gc_kind_name(header->kind), (unsigned)header->size, i,
|
|
71
|
+
xt_gc_kind_name(target->kind), (unsigned)target->size);
|
|
72
|
+
if (++misses >= 8) {
|
|
73
|
+
fprintf(stderr, "xbintsc: gc verify: stopping after 8 reports\n");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (misses == 0) fprintf(stderr, "xbintsc: gc verify: ok\n");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* -- freed-block ring, for crash triage ----------------------------------- */
|
|
82
|
+
|
|
83
|
+
/* Every block the sweep releases is recorded here: a crash handler that knows
|
|
84
|
+
* the faulting address can say whether it was inside a freed block. */
|
|
85
|
+
|
|
86
|
+
typedef struct {
|
|
87
|
+
uintptr_t address;
|
|
88
|
+
size_t size;
|
|
89
|
+
uint8_t kind;
|
|
90
|
+
} xt_gc_freed_entry;
|
|
91
|
+
|
|
92
|
+
#define XT_GC_FREED_RING 512
|
|
93
|
+
static xt_gc_freed_entry g_freed[XT_GC_FREED_RING];
|
|
94
|
+
static size_t g_freed_count = 0;
|
|
95
|
+
|
|
96
|
+
void xt_gc_debug_record_free(uintptr_t address, size_t size, int kind) {
|
|
97
|
+
xt_gc_freed_entry *entry = &g_freed[g_freed_count % XT_GC_FREED_RING];
|
|
98
|
+
entry->address = address;
|
|
99
|
+
entry->size = size;
|
|
100
|
+
entry->kind = (uint8_t)kind;
|
|
101
|
+
g_freed_count++;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Describe `address` if it falls inside a block the sweep released. */
|
|
105
|
+
int xt_gc_debug_describe(uintptr_t address, char *out, size_t capacity) {
|
|
106
|
+
size_t live = g_freed_count < XT_GC_FREED_RING ? g_freed_count : XT_GC_FREED_RING;
|
|
107
|
+
{
|
|
108
|
+
xt_header *live_block = xt_gc_lookup_raw(address);
|
|
109
|
+
snprintf(out, capacity,
|
|
110
|
+
" fault address 0x%llx (%zu frees recorded)%s\n",
|
|
111
|
+
(unsigned long long)address, g_freed_count,
|
|
112
|
+
live_block ? ", inside a LIVE block" : ", not in the live heap");
|
|
113
|
+
if (live_block) return 1;
|
|
114
|
+
}
|
|
115
|
+
for (size_t i = 0; i < live; i++) {
|
|
116
|
+
const xt_gc_freed_entry *entry = &g_freed[i];
|
|
117
|
+
if (address < entry->address || address >= entry->address + entry->size) continue;
|
|
118
|
+
snprintf(out, capacity,
|
|
119
|
+
" fault address 0x%llx is +0x%llx inside a %s block of %u bytes that the "
|
|
120
|
+
"collector freed (%zu frees ago)\n",
|
|
121
|
+
(unsigned long long)address, (unsigned long long)(address - entry->address),
|
|
122
|
+
xt_gc_kind_name(entry->kind), (unsigned)entry->size, i);
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
return 0;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** A typed pointer that is not a live block: name it under `XT_GC_VERIFY=1`. */
|
|
129
|
+
void xt_gc_verify_rejected(uintptr_t address) {
|
|
130
|
+
static int reported = 0;
|
|
131
|
+
if (getenv("XT_GC_VERIFY") == NULL) return;
|
|
132
|
+
if (reported++ >= 8) return;
|
|
133
|
+
fprintf(stderr, "xbintsc: gc verify: skipped stale typed pointer 0x%llx\n",
|
|
134
|
+
(unsigned long long)address);
|
|
135
|
+
}
|