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,224 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — the `Intl` global object.
|
|
3
|
+
*
|
|
4
|
+
* Only `Intl.Segmenter` is provided: the TUI subdivides strings into grapheme
|
|
5
|
+
* clusters (terminal width, truncation) and words (cursor movement), and both
|
|
6
|
+
* segmenters are constructed at module load. ICU is not linked, so the
|
|
7
|
+
* segmentation is a documented approximation of UAX #29:
|
|
8
|
+
*
|
|
9
|
+
* - grapheme: a code point plus the marks, variation selectors, emoji
|
|
10
|
+
* modifiers and ZWJ sequences that attach to it, and paired regional
|
|
11
|
+
* indicators (flags);
|
|
12
|
+
* - word: runs of whitespace, word characters and punctuation.
|
|
13
|
+
*
|
|
14
|
+
* `segment(text)` returns an **array** of `{ segment, index, isWordLike }`.
|
|
15
|
+
* Node returns an iterable of the same records; every consumer in the
|
|
16
|
+
* ecosystem spreads or iterates it, so the array is a compatible subset.
|
|
17
|
+
*
|
|
18
|
+
* Locale arguments are ignored, and `resolvedOptions()` reports `en`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include "rt_internal.h"
|
|
22
|
+
|
|
23
|
+
#include <stdio.h>
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
|
|
27
|
+
static xt_value xt_intl_object_value = 0;
|
|
28
|
+
|
|
29
|
+
/* -- code point classification -------------------------------------------- */
|
|
30
|
+
|
|
31
|
+
#define XT_CP_ZWJ 0x200D
|
|
32
|
+
|
|
33
|
+
static int xt_cp_is_mark(int32_t cp) {
|
|
34
|
+
return (cp >= 0x0300 && cp <= 0x036f) || (cp >= 0x1ab0 && cp <= 0x1aff) ||
|
|
35
|
+
(cp >= 0x1dc0 && cp <= 0x1dff) || (cp >= 0x20d0 && cp <= 0x20ff) ||
|
|
36
|
+
(cp >= 0xfe20 && cp <= 0xfe2f) || (cp >= 0x0900 && cp <= 0x0903) ||
|
|
37
|
+
(cp >= 0x093a && cp <= 0x094f) || (cp >= 0x0e31 && cp <= 0x0e3a) ||
|
|
38
|
+
(cp >= 0x0e47 && cp <= 0x0e4e) || (cp >= 0x3099 && cp <= 0x309a);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static int xt_cp_is_variation_selector(int32_t cp) {
|
|
42
|
+
return (cp >= 0xfe00 && cp <= 0xfe0f) || (cp >= 0xe0100 && cp <= 0xe01ef);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static int xt_cp_is_emoji_modifier(int32_t cp) { return cp >= 0x1f3fb && cp <= 0x1f3ff; }
|
|
46
|
+
|
|
47
|
+
static int xt_cp_is_regional_indicator(int32_t cp) { return cp >= 0x1f1e6 && cp <= 0x1f1ff; }
|
|
48
|
+
|
|
49
|
+
static int xt_cp_is_whitespace(int32_t cp) {
|
|
50
|
+
return cp == 0x20 || (cp >= 0x09 && cp <= 0x0d) || cp == 0xa0 || cp == 0x1680 ||
|
|
51
|
+
(cp >= 0x2000 && cp <= 0x200a) || cp == 0x2028 || cp == 0x2029 || cp == 0x202f ||
|
|
52
|
+
cp == 0x205f || cp == 0x3000;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static int xt_cp_is_ascii_word(int32_t cp) {
|
|
56
|
+
return (cp >= '0' && cp <= '9') || (cp >= 'a' && cp <= 'z') || (cp >= 'A' && cp <= 'Z') || cp == '_';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* Non-ASCII letters are word characters for segmentation purposes; CJK,
|
|
60
|
+
* Cyrillic, Greek and accents all land here. Ranges that are clearly symbols
|
|
61
|
+
* (arrows, emoji, box drawing) are not. */
|
|
62
|
+
static int xt_cp_is_word(int32_t cp) {
|
|
63
|
+
if (xt_cp_is_ascii_word(cp)) return 1;
|
|
64
|
+
if (cp < 0x80) return 0;
|
|
65
|
+
if (xt_cp_is_whitespace(cp) || xt_cp_is_mark(cp)) return 0;
|
|
66
|
+
if (cp >= 0x1f000) return 0;
|
|
67
|
+
if (cp >= 0x2190 && cp <= 0x2bff) return 0;
|
|
68
|
+
if (cp >= 0x2500 && cp <= 0x259f) return 0;
|
|
69
|
+
if (cp >= 0x3000 && cp <= 0x303f) return 0;
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* -- segment extraction ---------------------------------------------------- */
|
|
74
|
+
|
|
75
|
+
/** The text of `[start, end)` (UTF-16 units) as a JavaScript string. */
|
|
76
|
+
static xt_value xt_segment_text(xt_string *text, int32_t start, int32_t end) {
|
|
77
|
+
size_t capacity = (size_t)(end - start + 1) * 4;
|
|
78
|
+
char *buffer = (char *)malloc(capacity);
|
|
79
|
+
if (!buffer) return xt_string_from_cstr("");
|
|
80
|
+
size_t length = 0;
|
|
81
|
+
for (int32_t index = start; index < end;) {
|
|
82
|
+
int32_t code = xt_string_code_point_at(text, index);
|
|
83
|
+
if (code < 0) break;
|
|
84
|
+
index += code > 0xffff ? 2 : 1;
|
|
85
|
+
length += xt_utf8_encode((uint32_t)code, buffer + length);
|
|
86
|
+
}
|
|
87
|
+
xt_value segment = xt_string_new(buffer, length);
|
|
88
|
+
free(buffer);
|
|
89
|
+
return segment;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static void xt_segment_push(xt_value array, xt_string *text, int32_t start, int32_t end, int word_like) {
|
|
93
|
+
if (end <= start) return;
|
|
94
|
+
xt_value record = xt_object_new();
|
|
95
|
+
xt_object_set(record, xt_string_from_cstr("segment"), xt_segment_text(text, start, end));
|
|
96
|
+
xt_object_set(record, xt_string_from_cstr("index"), xt_number((double)start));
|
|
97
|
+
xt_object_set(record, xt_string_from_cstr("isWordLike"), xt_bool(word_like));
|
|
98
|
+
xt_array_push(array, record);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* True when `code` attaches to the preceding cluster instead of starting one. */
|
|
102
|
+
static int xt_cp_extends_cluster(int32_t code) {
|
|
103
|
+
return xt_cp_is_mark(code) || xt_cp_is_variation_selector(code) || xt_cp_is_emoji_modifier(code) ||
|
|
104
|
+
code == XT_CP_ZWJ;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static xt_value xt_segment_graphemes(xt_string *text) {
|
|
108
|
+
xt_value array = xt_array_new(0, NULL);
|
|
109
|
+
int32_t units = (int32_t)xt_string_utf16_length(text);
|
|
110
|
+
int32_t start = 0;
|
|
111
|
+
int32_t index = 0;
|
|
112
|
+
int32_t cluster_codepoints = 0;
|
|
113
|
+
int32_t last_code = 0;
|
|
114
|
+
while (index < units) {
|
|
115
|
+
int32_t code = xt_string_code_point_at(text, index);
|
|
116
|
+
if (code < 0) break;
|
|
117
|
+
int32_t width = code > 0xffff ? 2 : 1;
|
|
118
|
+
int extends = index > start && xt_cp_extends_cluster(code);
|
|
119
|
+
/* A pair of regional indicators is one flag. */
|
|
120
|
+
if (!extends && index > start && xt_cp_is_regional_indicator(code) &&
|
|
121
|
+
xt_cp_is_regional_indicator(last_code) && cluster_codepoints == 1) {
|
|
122
|
+
extends = 1;
|
|
123
|
+
}
|
|
124
|
+
/* A ZWJ consumes the code point that follows it (emoji sequences). */
|
|
125
|
+
if (!extends && index > start && last_code == XT_CP_ZWJ) extends = 1;
|
|
126
|
+
if (!extends && index > start) {
|
|
127
|
+
xt_segment_push(array, text, start, index, 0);
|
|
128
|
+
start = index;
|
|
129
|
+
cluster_codepoints = 0;
|
|
130
|
+
}
|
|
131
|
+
cluster_codepoints++;
|
|
132
|
+
last_code = code;
|
|
133
|
+
index += width;
|
|
134
|
+
}
|
|
135
|
+
xt_segment_push(array, text, start, units, 0);
|
|
136
|
+
return array;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static xt_value xt_segment_words(xt_string *text) {
|
|
140
|
+
xt_value array = xt_array_new(0, NULL);
|
|
141
|
+
int32_t units = (int32_t)xt_string_utf16_length(text);
|
|
142
|
+
int32_t start = 0;
|
|
143
|
+
int32_t index = 0;
|
|
144
|
+
int class_of_run = -1; /* 0 punctuation, 1 word, 2 whitespace */
|
|
145
|
+
while (index < units) {
|
|
146
|
+
int32_t code = xt_string_code_point_at(text, index);
|
|
147
|
+
if (code < 0) break;
|
|
148
|
+
int32_t width = code > 0xffff ? 2 : 1;
|
|
149
|
+
int kind = xt_cp_is_whitespace(code) ? 2 : (xt_cp_is_word(code) ? 1 : 0);
|
|
150
|
+
/* Marks continue whatever run they land in. */
|
|
151
|
+
if (xt_cp_is_mark(code) && class_of_run >= 0) kind = class_of_run;
|
|
152
|
+
if (class_of_run >= 0 && kind != class_of_run) {
|
|
153
|
+
xt_segment_push(array, text, start, index, class_of_run == 1);
|
|
154
|
+
start = index;
|
|
155
|
+
}
|
|
156
|
+
class_of_run = kind;
|
|
157
|
+
index += width;
|
|
158
|
+
}
|
|
159
|
+
xt_segment_push(array, text, start, units, class_of_run == 1);
|
|
160
|
+
return array;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/* -- segmenter objects ---------------------------------------------------- */
|
|
164
|
+
|
|
165
|
+
static const char *xt_segmenter_granularity(xt_value segmenter) {
|
|
166
|
+
xt_value value = xt_object_get_cstr(segmenter, "__granularity");
|
|
167
|
+
const char *granularity = XT_IS_STRING(value) ? xt_string_data(value) : NULL;
|
|
168
|
+
return granularity ? granularity : "grapheme";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static xt_value xt_intl_segment(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
172
|
+
(void)env;
|
|
173
|
+
const char *granularity = xt_segmenter_granularity(thisValue);
|
|
174
|
+
xt_value input = xt_arg(argc, argv, 0);
|
|
175
|
+
xt_string *text = xt_as_string(xt_to_string(input));
|
|
176
|
+
if (!text) return xt_array_new(0, NULL);
|
|
177
|
+
if (strcmp(granularity, "word") == 0) return xt_segment_words(text);
|
|
178
|
+
if (strcmp(granularity, "sentence") == 0) return xt_segment_words(text);
|
|
179
|
+
return xt_segment_graphemes(text);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
static xt_value xt_intl_resolved_options(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
183
|
+
(void)env;
|
|
184
|
+
(void)argc;
|
|
185
|
+
(void)argv;
|
|
186
|
+
xt_value options = xt_object_new();
|
|
187
|
+
xt_object_set(options, xt_string_from_cstr("locale"), xt_string_from_cstr("en"));
|
|
188
|
+
xt_object_set(options, xt_string_from_cstr("granularity"),
|
|
189
|
+
xt_string_from_cstr(xt_segmenter_granularity(thisValue)));
|
|
190
|
+
return options;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* `new Intl.Segmenter(locale, { granularity })` returns the segmenter object
|
|
194
|
+
* itself; `xt_new` keeps it because a constructor that returns an object wins. */
|
|
195
|
+
static xt_value xt_intl_segmenter_ctor(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
196
|
+
(void)thisValue;
|
|
197
|
+
(void)env;
|
|
198
|
+
const char *granularity = "grapheme";
|
|
199
|
+
xt_value options = xt_arg(argc, argv, 1);
|
|
200
|
+
if (XT_IS_OBJECT(options)) {
|
|
201
|
+
xt_value requested = xt_object_get_cstr(options, "granularity");
|
|
202
|
+
if (XT_IS_STRING(requested)) granularity = xt_string_data(requested);
|
|
203
|
+
}
|
|
204
|
+
xt_value segmenter = xt_object_new();
|
|
205
|
+
xt_object_set(segmenter, xt_string_from_cstr("__granularity"), xt_string_from_cstr(granularity));
|
|
206
|
+
xt_value segment = xt_closure_new((void *)xt_intl_segment, 0, NULL);
|
|
207
|
+
xt_function_set_metadata(segment, xt_string_from_cstr("segment"), 1);
|
|
208
|
+
xt_object_set(segmenter, xt_string_from_cstr("segment"), segment);
|
|
209
|
+
xt_value resolved = xt_closure_new((void *)xt_intl_resolved_options, 0, NULL);
|
|
210
|
+
xt_function_set_metadata(resolved, xt_string_from_cstr("resolvedOptions"), 0);
|
|
211
|
+
xt_object_set(segmenter, xt_string_from_cstr("resolvedOptions"), resolved);
|
|
212
|
+
return segmenter;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
xt_value xt_intl_object(void) {
|
|
216
|
+
xt_gc_add_root(&xt_intl_object_value);
|
|
217
|
+
if (xt_intl_object_value) return xt_intl_object_value;
|
|
218
|
+
xt_value intl = xt_object_new();
|
|
219
|
+
xt_value segmenter = xt_closure_new((void *)xt_intl_segmenter_ctor, 0, NULL);
|
|
220
|
+
xt_function_set_metadata(segmenter, xt_string_from_cstr("Segmenter"), 0);
|
|
221
|
+
xt_object_set(intl, xt_string_from_cstr("Segmenter"), segmenter);
|
|
222
|
+
xt_intl_object_value = intl;
|
|
223
|
+
return xt_intl_object_value;
|
|
224
|
+
}
|
|
@@ -64,6 +64,15 @@ void xt_stack_trim(int32_t depth) {
|
|
|
64
64
|
if (depth < g_stack_depth) g_stack_depth = depth;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/* The module whose top-level code is running. Every module of a bundle shares
|
|
68
|
+
* one generated function, so a crash inside a module body would otherwise be
|
|
69
|
+
* reported at the entry file's offsets. Codegen emits one call per module
|
|
70
|
+
* boundary. */
|
|
71
|
+
static const char *g_current_module = NULL;
|
|
72
|
+
|
|
73
|
+
void xt_stack_set_module(const char *name) { g_current_module = name; }
|
|
74
|
+
|
|
75
|
+
|
|
67
76
|
static void xt_stack_append(char **buffer, size_t *length, size_t *capacity, const char *text) {
|
|
68
77
|
size_t count = strlen(text);
|
|
69
78
|
if (*length + count + 1 > *capacity) {
|
|
@@ -90,6 +99,11 @@ xt_value xt_stack_capture(const char *name, const char *message) {
|
|
|
90
99
|
xt_stack_append(&buffer, &length, &capacity, message);
|
|
91
100
|
}
|
|
92
101
|
xt_stack_append(&buffer, &length, &capacity, "\n");
|
|
102
|
+
if (g_current_module != NULL) {
|
|
103
|
+
xt_stack_append(&buffer, &length, &capacity, " module: ");
|
|
104
|
+
xt_stack_append(&buffer, &length, &capacity, g_current_module);
|
|
105
|
+
xt_stack_append(&buffer, &length, &capacity, "\n");
|
|
106
|
+
}
|
|
93
107
|
for (int32_t index = g_stack_depth - 1; index >= 0; index--) {
|
|
94
108
|
const xt_stack_entry *entry = &g_stack[index];
|
|
95
109
|
char line[24];
|
|
@@ -123,6 +137,13 @@ static char g_crash_report[16384];
|
|
|
123
137
|
|
|
124
138
|
static int xt_format_stack(char *out, size_t size) {
|
|
125
139
|
int written = 0;
|
|
140
|
+
/* While a bundle's module bodies run, name the module whose top-level code is
|
|
141
|
+
* executing: every module shares one generated function, so its frames all
|
|
142
|
+
* carry the entry file's coordinates. */
|
|
143
|
+
if (g_current_module != NULL) {
|
|
144
|
+
int count = snprintf(out, size, " module: %s\n", g_current_module);
|
|
145
|
+
if (count > 0) written = count;
|
|
146
|
+
}
|
|
126
147
|
for (int32_t index = g_stack_depth - 1; index >= 0 && written < (int)size; index--) {
|
|
127
148
|
const xt_stack_entry *entry = &g_stack[index];
|
|
128
149
|
int count = snprintf(out + written, size - (size_t)written, " at %s (%s:%d)\n",
|
|
@@ -139,7 +160,24 @@ static int xt_format_stack(char *out, size_t size) {
|
|
|
139
160
|
static LONG WINAPI xt_fatal_exception(EXCEPTION_POINTERS *info) {
|
|
140
161
|
unsigned long code =
|
|
141
162
|
info && info->ExceptionRecord ? (unsigned long)info->ExceptionRecord->ExceptionCode : 0UL;
|
|
142
|
-
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal exception 0x%08lx\n",
|
|
163
|
+
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal exception 0x%08lx\n",
|
|
164
|
+
code);
|
|
165
|
+
written += snprintf(g_crash_report + written, sizeof(g_crash_report) - (size_t)written,
|
|
166
|
+
" thread: %s\n", xt_gc_worker_thread ? "I/O worker" : "main");
|
|
167
|
+
/* A fault inside a block the collector already released is a
|
|
168
|
+
* use-after-free; naming the block turns a mystery crash into a lead. */
|
|
169
|
+
if (info && info->ExceptionRecord) {
|
|
170
|
+
unsigned long parameters = (unsigned long)info->ExceptionRecord->NumberParameters;
|
|
171
|
+
uintptr_t access = (uintptr_t)info->ExceptionRecord->ExceptionInformation[0];
|
|
172
|
+
uintptr_t address = (uintptr_t)info->ExceptionRecord->ExceptionInformation[1];
|
|
173
|
+
written += snprintf(g_crash_report + written, sizeof(g_crash_report) - (size_t)written,
|
|
174
|
+
" detail: %lu parameters, access 0x%llx, address 0x%llx\n", parameters,
|
|
175
|
+
(unsigned long long)access, (unsigned long long)address);
|
|
176
|
+
if (address != 0) {
|
|
177
|
+
written += xt_gc_debug_describe(address, g_crash_report + written,
|
|
178
|
+
sizeof(g_crash_report) - (size_t)written);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
143
181
|
written += xt_format_stack(g_crash_report + written, sizeof(g_crash_report) - (size_t)written);
|
|
144
182
|
_write(2, g_crash_report, (unsigned int)written);
|
|
145
183
|
_exit(1);
|
|
@@ -152,6 +190,7 @@ void xt_install_crash_handler(void) { SetUnhandledExceptionFilter(xt_fatal_excep
|
|
|
152
190
|
|
|
153
191
|
static void xt_fatal_signal(int sig) {
|
|
154
192
|
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal signal %d\n", sig);
|
|
193
|
+
|
|
155
194
|
written += xt_format_stack(g_crash_report + written, sizeof(g_crash_report) - (size_t)written);
|
|
156
195
|
ssize_t ignored = write(STDERR_FILENO, g_crash_report, (size_t)written);
|
|
157
196
|
(void)ignored;
|
|
@@ -27,3 +27,85 @@ xt_value xt_method_trampoline(xt_value thisValue, xt_value env, int32_t argc, xt
|
|
|
27
27
|
(xt_value (*)(xt_value, int32_t, xt_value *))(uintptr_t)raw;
|
|
28
28
|
return dispatcher(name, argc, argv);
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
/* `import(<expression>)` in a compiled binary.
|
|
32
|
+
*
|
|
33
|
+
* The build links a fixed set of modules; `table` maps every enabled extension
|
|
34
|
+
* module name — bare and with the `node:` prefix — to its namespace object. A
|
|
35
|
+
* specifier that names one of them resolves to that namespace (this is how
|
|
36
|
+
* `import("node:" + "fs")`, the common "load Node built-ins lazily" idiom,
|
|
37
|
+
* works); anything else rejects with a message that names it. */
|
|
38
|
+
xt_value xt_dynamic_import(xt_value table, xt_value specifier) {
|
|
39
|
+
if (XT_IS_STRING(specifier)) {
|
|
40
|
+
xt_value found = xt_get(table, specifier);
|
|
41
|
+
if (found != XT_UNDEFINED && found != XT_NULL) return xt_promise_resolve(found);
|
|
42
|
+
}
|
|
43
|
+
xt_value message = xt_add(
|
|
44
|
+
xt_string_from_cstr("dynamic import of '"),
|
|
45
|
+
xt_add(xt_to_string(specifier),
|
|
46
|
+
xt_string_from_cstr("' is not supported in compiled binaries: "
|
|
47
|
+
"only modules linked into this build can be loaded")));
|
|
48
|
+
xt_value arguments[1];
|
|
49
|
+
arguments[0] = message;
|
|
50
|
+
return xt_promise_reject(xt_error_ctor_by_name(xt_string_from_cstr("Error"), 1, arguments));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Like `xt_fnptr_trampoline`, for a binding declared `void` (the console
|
|
54
|
+
* output methods): call it for its effect and answer `undefined`. */
|
|
55
|
+
xt_value xt_voidptr_trampoline(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
56
|
+
(void)thisValue;
|
|
57
|
+
xt_value raw = xt_closure_env(env, 0);
|
|
58
|
+
void (*fn)(int32_t, xt_value *) = (void (*)(int32_t, xt_value *))(uintptr_t)raw;
|
|
59
|
+
fn(argc, argv);
|
|
60
|
+
return XT_UNDEFINED;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* `__xt_defer(id, init)`: evaluate `init` once and return its exports.
|
|
64
|
+
*
|
|
65
|
+
* The bundler wraps a module that is only reached through a dynamic import in
|
|
66
|
+
* such a function, so the body runs on the first `import(...)` instead of at
|
|
67
|
+
* startup. The placeholder is published before `init` runs, so a cycle among
|
|
68
|
+
* deferred modules sees the same object rather than recursing. */
|
|
69
|
+
xt_value xt_defer_module(int32_t argc, xt_value *argv) {
|
|
70
|
+
if (argc < 1) return XT_UNDEFINED;
|
|
71
|
+
static xt_value registry = 0;
|
|
72
|
+
if (registry == 0) {
|
|
73
|
+
registry = xt_object_new();
|
|
74
|
+
xt_gc_add_root(®istry);
|
|
75
|
+
}
|
|
76
|
+
xt_value key = xt_to_string(xt_arg(argc, argv, 0));
|
|
77
|
+
|
|
78
|
+
xt_value found = xt_object_get(registry, key);
|
|
79
|
+
if (found != XT_UNDEFINED) return found;
|
|
80
|
+
xt_value exports = xt_object_new();
|
|
81
|
+
xt_object_set(registry, key, exports);
|
|
82
|
+
xt_value init = xt_arg(argc, argv, 1);
|
|
83
|
+
if (XT_IS_FUNCTION(init)) {
|
|
84
|
+
exports = xt_call_with_this(init, XT_UNDEFINED, 0, NULL);
|
|
85
|
+
xt_object_set(registry, key, exports);
|
|
86
|
+
}
|
|
87
|
+
return exports;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* -- linked-module registry ------------------------------------------------ *
|
|
91
|
+
*
|
|
92
|
+
* A compiled program has no module loader, but the modules linked into it are
|
|
93
|
+
* known: the code generator builds a table mapping every enabled extension
|
|
94
|
+
* module name (bare and `node:`-prefixed) to its namespace object and registers
|
|
95
|
+
* it before the first `createRequire(...)` / computed `import(...)` runs. Both
|
|
96
|
+
* entry points answer from that table instead of failing outright. */
|
|
97
|
+
static xt_value g_module_registry = 0;
|
|
98
|
+
static int g_module_registry_rooted = 0;
|
|
99
|
+
|
|
100
|
+
void xt_module_registry_set(xt_value table) {
|
|
101
|
+
g_module_registry = table;
|
|
102
|
+
if (!g_module_registry_rooted) {
|
|
103
|
+
xt_gc_add_root(&g_module_registry);
|
|
104
|
+
g_module_registry_rooted = 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
xt_value xt_module_registry_lookup(xt_value specifier) {
|
|
109
|
+
if (g_module_registry == 0 || !XT_IS_STRING(specifier)) return XT_UNDEFINED;
|
|
110
|
+
return xt_object_get(g_module_registry, specifier);
|
|
111
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — a subset of `Proxy`.
|
|
3
|
+
*
|
|
4
|
+
* A proxy is an ordinary host view (`xt_object` with hooks): its target and
|
|
5
|
+
* handler live in hidden symbol-keyed properties, so the collector traces them
|
|
6
|
+
* like any other property, and the existing hook dispatch in `xt_object_get`,
|
|
7
|
+
* `xt_object_set`, `xt_object_has`, `xt_delete` and `xt_object_keys` runs the
|
|
8
|
+
* traps. Own and prototype lookups on the proxy object itself stay empty, so
|
|
9
|
+
* every string-keyed read and write misses and reaches the hooks.
|
|
10
|
+
*
|
|
11
|
+
* Supported traps: `get`, `set`, `has`, `deleteProperty`, `ownKeys`. Without a
|
|
12
|
+
* trap the operation is forwarded to the target. Not supported (and documented
|
|
13
|
+
* in doc/unimplemented/expressions.md): function targets (`apply`/`construct`),
|
|
14
|
+
* `Object.getPrototypeOf`/`setPrototypeOf` traps, property-descriptor traps
|
|
15
|
+
* (`getOwnPropertyDescriptor`, `defineProperty`, `isExtensible`, …) and
|
|
16
|
+
* `Proxy.revocable`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "rt_internal.h"
|
|
20
|
+
|
|
21
|
+
#include <string.h>
|
|
22
|
+
|
|
23
|
+
/* Hidden own properties; symbol keys keep them out of `Object.keys`, JSON and
|
|
24
|
+
* ordinary string-keyed reads. */
|
|
25
|
+
static xt_value xt_proxy_target_key = XT_UNDEFINED;
|
|
26
|
+
static xt_value xt_proxy_handler_key = XT_UNDEFINED;
|
|
27
|
+
|
|
28
|
+
static xt_value xt_proxy_state_key(const char *name, xt_value *slot) {
|
|
29
|
+
if (!xt_is_symbol(*slot)) {
|
|
30
|
+
*slot = xt_symbol_new(xt_string_from_cstr(name));
|
|
31
|
+
xt_gc_add_root(slot);
|
|
32
|
+
}
|
|
33
|
+
return *slot;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static xt_value xt_proxy_target(xt_value proxy) {
|
|
37
|
+
return xt_object_get(proxy, xt_proxy_state_key("__xt_proxy_target", &xt_proxy_target_key));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static xt_value xt_proxy_handler(xt_value proxy) {
|
|
41
|
+
return xt_object_get(proxy, xt_proxy_state_key("__xt_proxy_handler", &xt_proxy_handler_key));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* The handler's function for `name`, or 0 when the trap is absent. */
|
|
45
|
+
static int xt_proxy_trap(xt_value proxy, const char *name, xt_value *trap) {
|
|
46
|
+
xt_value handler = xt_proxy_handler(proxy);
|
|
47
|
+
if (!XT_IS_OBJECT(handler)) return 0;
|
|
48
|
+
xt_value value = xt_object_get(handler, xt_string_from_cstr(name));
|
|
49
|
+
if (!XT_IS_FUNCTION(value)) return 0;
|
|
50
|
+
*trap = value;
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* -- hooks ---------------------------------------------------------------- */
|
|
55
|
+
|
|
56
|
+
static xt_value xt_proxy_hook_get(xt_value self, xt_value key, void *data) {
|
|
57
|
+
(void)data;
|
|
58
|
+
xt_value target = xt_proxy_target(self);
|
|
59
|
+
xt_value trap;
|
|
60
|
+
if (!xt_proxy_trap(self, "get", &trap)) return xt_object_get(target, key);
|
|
61
|
+
xt_value arguments[3] = {target, key, self};
|
|
62
|
+
return xt_call_with_this(trap, xt_proxy_handler(self), 3, arguments);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static int xt_proxy_hook_set(xt_value self, xt_value key, xt_value value, void *data) {
|
|
66
|
+
(void)data;
|
|
67
|
+
xt_value target = xt_proxy_target(self);
|
|
68
|
+
xt_value trap;
|
|
69
|
+
if (!xt_proxy_trap(self, "set", &trap)) {
|
|
70
|
+
xt_object_set(target, key, value);
|
|
71
|
+
return 1;
|
|
72
|
+
}
|
|
73
|
+
xt_value arguments[4] = {target, key, value, self};
|
|
74
|
+
xt_call_with_this(trap, xt_proxy_handler(self), 4, arguments);
|
|
75
|
+
/* A falsy trap result would fail the assignment in strict mode; the runtime
|
|
76
|
+
* has no strict/sloppy distinction, so a handled write always succeeds. */
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static int xt_proxy_hook_has(xt_value self, xt_value key, void *data) {
|
|
81
|
+
(void)data;
|
|
82
|
+
xt_value target = xt_proxy_target(self);
|
|
83
|
+
xt_value trap;
|
|
84
|
+
if (!xt_proxy_trap(self, "has", &trap)) return xt_truthy(xt_object_has(target, key)) ? 1 : 0;
|
|
85
|
+
xt_value arguments[2] = {target, key};
|
|
86
|
+
return xt_truthy(xt_call_with_this(trap, xt_proxy_handler(self), 2, arguments)) ? 1 : 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static int xt_proxy_hook_remove(xt_value self, xt_value key, void *data) {
|
|
90
|
+
(void)data;
|
|
91
|
+
xt_value target = xt_proxy_target(self);
|
|
92
|
+
xt_value trap;
|
|
93
|
+
if (!xt_proxy_trap(self, "deleteProperty", &trap)) {
|
|
94
|
+
xt_delete(target, key);
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
xt_value arguments[2] = {target, key};
|
|
98
|
+
xt_call_with_this(trap, xt_proxy_handler(self), 2, arguments);
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static xt_value xt_proxy_hook_keys(xt_value self, void *data) {
|
|
103
|
+
(void)data;
|
|
104
|
+
xt_value target = xt_proxy_target(self);
|
|
105
|
+
xt_value trap;
|
|
106
|
+
if (!xt_proxy_trap(self, "ownKeys", &trap)) return xt_object_keys(target);
|
|
107
|
+
xt_value arguments[1] = {target};
|
|
108
|
+
return xt_call_with_this(trap, xt_proxy_handler(self), 1, arguments);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static const xt_object_hooks xt_proxy_hooks = {
|
|
112
|
+
xt_proxy_hook_get,
|
|
113
|
+
xt_proxy_hook_set,
|
|
114
|
+
xt_proxy_hook_has,
|
|
115
|
+
xt_proxy_hook_remove,
|
|
116
|
+
xt_proxy_hook_keys,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/* -- construction --------------------------------------------------------- */
|
|
120
|
+
|
|
121
|
+
xt_value xt_proxy_ctor(int32_t argc, xt_value *argv) {
|
|
122
|
+
xt_value target = xt_arg(argc, argv, 0);
|
|
123
|
+
xt_value handler = xt_arg(argc, argv, 1);
|
|
124
|
+
if (!XT_IS_OBJECT(target) && !XT_IS_FUNCTION(target)) {
|
|
125
|
+
xt_throw(xt_error_from_message("TypeError: Cannot create proxy with a non-object as target"));
|
|
126
|
+
return XT_UNDEFINED;
|
|
127
|
+
}
|
|
128
|
+
if (!XT_IS_OBJECT(handler)) {
|
|
129
|
+
xt_throw(xt_error_from_message("TypeError: Cannot create proxy with a non-object as handler"));
|
|
130
|
+
return XT_UNDEFINED;
|
|
131
|
+
}
|
|
132
|
+
xt_value proxy = xt_object_new();
|
|
133
|
+
/* The proxy inherits the target's prototype: `instanceof` and inherited
|
|
134
|
+
* methods behave like the target's. A `getPrototypeOf` trap is not modelled. */
|
|
135
|
+
xt_object_set_prototype(proxy, xt_object_get_prototype(target));
|
|
136
|
+
xt_object_set(proxy, xt_proxy_state_key("__xt_proxy_target", &xt_proxy_target_key), target);
|
|
137
|
+
xt_object_set(proxy, xt_proxy_state_key("__xt_proxy_handler", &xt_proxy_handler_key), handler);
|
|
138
|
+
xt_object_set_hooks(proxy, &xt_proxy_hooks, NULL);
|
|
139
|
+
return proxy;
|
|
140
|
+
}
|
|
@@ -266,6 +266,92 @@ xt_value xt_method_value(xt_value target, xt_value name) {
|
|
|
266
266
|
return closure;
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
/* -- prototype method values ---------------------------------------------- */
|
|
270
|
+
|
|
271
|
+
/*
|
|
272
|
+
* `Map.prototype.get`, `String.prototype.slice`, `Promise.prototype.then` are
|
|
273
|
+
* ordinary values in JavaScript, and libraries uncurry them:
|
|
274
|
+
*
|
|
275
|
+
* const get = Map.prototype.get.bind(cache);
|
|
276
|
+
* const toLower = Function.call.bind(String.prototype.toLowerCase);
|
|
277
|
+
*
|
|
278
|
+
* Instances already expose their methods through `xt_method_value` (keyed by
|
|
279
|
+
* the receiver's kind), but a prototype object is a plain object, so the lookup
|
|
280
|
+
* found nothing and `.bind` was read from `undefined`. Install the same table
|
|
281
|
+
* on the prototype as unbound closures; the receiver then arrives through
|
|
282
|
+
* `this`, exactly like the specification.
|
|
283
|
+
*
|
|
284
|
+
* `kind` is the constructor name the prototype belongs to.
|
|
285
|
+
*/
|
|
286
|
+
static const xt_method_spec *xt_proto_method_specs(const char *kind, size_t *count) {
|
|
287
|
+
if (!kind) return NULL;
|
|
288
|
+
#define XT_PROTO_SPECS(name, table) \
|
|
289
|
+
if (strcmp(kind, name) == 0) { \
|
|
290
|
+
*count = XT_NAME_COUNT(table); \
|
|
291
|
+
return table; \
|
|
292
|
+
}
|
|
293
|
+
XT_PROTO_SPECS("Array", XT_ARRAY_METHODS)
|
|
294
|
+
XT_PROTO_SPECS("String", XT_STRING_METHODS)
|
|
295
|
+
XT_PROTO_SPECS("Function", XT_FUNCTION_METHODS)
|
|
296
|
+
XT_PROTO_SPECS("BigInt", XT_BIGINT_METHODS)
|
|
297
|
+
XT_PROTO_SPECS("Number", XT_NUMBER_METHODS)
|
|
298
|
+
XT_PROTO_SPECS("Boolean", XT_BOOLEAN_METHODS)
|
|
299
|
+
XT_PROTO_SPECS("Date", XT_DATE_METHODS)
|
|
300
|
+
XT_PROTO_SPECS("Map", XT_MAP_METHODS)
|
|
301
|
+
XT_PROTO_SPECS("Set", XT_SET_METHODS)
|
|
302
|
+
XT_PROTO_SPECS("WeakMap", XT_WEAKMAP_METHODS)
|
|
303
|
+
XT_PROTO_SPECS("WeakSet", XT_WEAKSET_METHODS)
|
|
304
|
+
XT_PROTO_SPECS("WeakRef", XT_WEAKREF_METHODS)
|
|
305
|
+
XT_PROTO_SPECS("RegExp", XT_REGEXP_METHODS)
|
|
306
|
+
XT_PROTO_SPECS("Promise", XT_PROMISE_METHODS)
|
|
307
|
+
XT_PROTO_SPECS("Error", XT_ERROR_METHODS)
|
|
308
|
+
XT_PROTO_SPECS("Symbol", XT_SYMBOL_METHODS)
|
|
309
|
+
XT_PROTO_SPECS("Generator", XT_GENERATOR_METHODS)
|
|
310
|
+
#undef XT_PROTO_SPECS
|
|
311
|
+
return NULL;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
void xt_install_proto_methods(xt_value proto, const char *kind) {
|
|
315
|
+
size_t count = 0;
|
|
316
|
+
const xt_method_spec *specs = xt_proto_method_specs(kind, &count);
|
|
317
|
+
if (!specs || !XT_IS_OBJECT(proto)) return;
|
|
318
|
+
for (size_t i = 0; i < count; i++) {
|
|
319
|
+
xt_value name = xt_string_from_cstr(specs[i].name);
|
|
320
|
+
xt_value closure = xt_closure_new((void *)xt_method_value_invoke, 1, &name);
|
|
321
|
+
xt_function_set_metadata(closure, name, specs[i].arity);
|
|
322
|
+
xt_object_set(proto, name, closure);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/* `Function.prototype[Symbol.hasInstance]`: `ctor[Symbol.hasInstance](value)`
|
|
327
|
+
* and `value instanceof ctor` share one implementation. */
|
|
328
|
+
static xt_value xt_function_has_instance(xt_value thisValue, xt_value env, int32_t argc,
|
|
329
|
+
xt_value *argv) {
|
|
330
|
+
(void)env;
|
|
331
|
+
if (argc < 1) return xt_bool(0);
|
|
332
|
+
return xt_instance_of(argv[0], thisValue);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
xt_value xt_function_has_instance_method(void) {
|
|
336
|
+
static xt_value cached = 0;
|
|
337
|
+
if (cached == 0) {
|
|
338
|
+
cached = xt_closure_new((void *)xt_function_has_instance, 0, NULL);
|
|
339
|
+
xt_function_set_metadata(cached, xt_string_from_cstr("[Symbol.hasInstance]"), 1);
|
|
340
|
+
xt_gc_add_root(&cached);
|
|
341
|
+
}
|
|
342
|
+
return cached;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/* Source text is not retained, so a function's `toString()` reports a
|
|
346
|
+
* native-style representation of its name. */
|
|
347
|
+
static xt_value xt_function_source_text(xt_value target) {
|
|
348
|
+
xt_function *self = (xt_function *)XT_GET_PTR(target);
|
|
349
|
+
const char *selfName = self->name ? xt_string_bytes(self->name) : "";
|
|
350
|
+
char buffer[256];
|
|
351
|
+
snprintf(buffer, sizeof(buffer), "function %s() { [native code] }", selfName);
|
|
352
|
+
return xt_string_from_cstr(buffer);
|
|
353
|
+
}
|
|
354
|
+
|
|
269
355
|
xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *argv) {
|
|
270
356
|
/* A symbol-named method (`obj[Symbol.iterator]()`) is never a built-in, so
|
|
271
357
|
* resolve it as an ordinary property and call it with `target` as `this`. */
|
|
@@ -372,7 +458,17 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
372
458
|
return bound;
|
|
373
459
|
}
|
|
374
460
|
xt_value fn = xt_object_get(target, name);
|
|
375
|
-
if (XT_IS_FUNCTION(fn))
|
|
461
|
+
if (XT_IS_FUNCTION(fn)) {
|
|
462
|
+
/* `fn.toString()` resolves to `Function.prototype.toString`, whose body
|
|
463
|
+
* dispatches back through this function (`xt_method_value_invoke` →
|
|
464
|
+
* `xt_call_method`) — calling it would recurse until the stack dies.
|
|
465
|
+
* Recognise the prototype's own method and answer the native-style
|
|
466
|
+
* source here; a function's own `toString` still takes the normal path. */
|
|
467
|
+
if (strcmp(method, "toString") == 0 && fn == xt_object_get(xt_function_prototype(), name)) {
|
|
468
|
+
return xt_function_source_text(target);
|
|
469
|
+
}
|
|
470
|
+
return xt_call_with_this(fn, target, argc, argv);
|
|
471
|
+
}
|
|
376
472
|
/* Statics of a first-class built-in constructor (`const A = Array;
|
|
377
473
|
* A.isArray(x)`). */
|
|
378
474
|
xt_value builtinStatic = xt_builtin_static_value(target, name);
|
|
@@ -380,14 +476,7 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
380
476
|
if (XT_IS_FUNCTION(builtinStatic)) return xt_call_with_this(builtinStatic, target, argc, argv);
|
|
381
477
|
return builtinStatic;
|
|
382
478
|
}
|
|
383
|
-
if (strcmp(method, "toString") == 0)
|
|
384
|
-
/* Source text is not retained; report a native-style representation. */
|
|
385
|
-
xt_function *self = (xt_function *)XT_GET_PTR(target);
|
|
386
|
-
const char *selfName = self->name ? xt_string_bytes(self->name) : "";
|
|
387
|
-
char buffer[256];
|
|
388
|
-
snprintf(buffer, sizeof(buffer), "function %s() { [native code] }", selfName);
|
|
389
|
-
return xt_string_from_cstr(buffer);
|
|
390
|
-
}
|
|
479
|
+
if (strcmp(method, "toString") == 0) return xt_function_source_text(target);
|
|
391
480
|
{
|
|
392
481
|
char message[256];
|
|
393
482
|
snprintf(message, sizeof(message), "TypeError: function has no callable method '%s'", method);
|
|
@@ -387,7 +387,13 @@ static xt_value xt_date_method(xt_value target, const char *method, int32_t argc
|
|
|
387
387
|
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)fmod(date->time, 1000.0));
|
|
388
388
|
return xt_string_from_cstr(buffer);
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
/* `toJSON` is the JSON hook: an invalid date serializes as `null` instead of
|
|
391
|
+
* throwing the way `toISOString` does. */
|
|
392
|
+
if (strcmp(method, "toJSON") == 0) {
|
|
393
|
+
if (isnan(date->time)) return XT_NULL;
|
|
394
|
+
return xt_call_method(target, xt_string_from_cstr("toISOString"), 0, NULL);
|
|
395
|
+
}
|
|
396
|
+
if (strcmp(method, "toString") == 0) return xt_call_method(target, xt_string_from_cstr("toISOString"), 0, NULL);
|
|
391
397
|
*handled = 0;
|
|
392
398
|
return XT_UNDEFINED;
|
|
393
399
|
}
|
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
static const char *const XT_ERROR_NAMES[] = {
|
|
8
8
|
"Error", "TypeError", "RangeError", "SyntaxError",
|
|
9
9
|
"ReferenceError", "EvalError", "URIError", "AggregateError",
|
|
10
|
+
/* WebAssembly's three error constructors are ordinary Error members. The
|
|
11
|
+
* runtime names them so `instanceof WebAssembly.CompileError` and a real
|
|
12
|
+
* `.name`/`.message` work; they are not globals in the language. */
|
|
13
|
+
"CompileError", "LinkError", "RuntimeError",
|
|
10
14
|
};
|
|
11
15
|
|
|
12
16
|
static int xt_error_is_family(const char *name) {
|