xbintsc 0.6.28 → 0.7.6
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/dist/src/ast/common.d.ts +10 -0
- 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/source.js +4 -0
- package/dist/src/checker/source.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/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +29 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +95 -1
- 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/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +24 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- 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.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +13 -29
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.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/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- 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 +21 -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 +18 -12
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.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 +79 -8
- 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 +4 -4
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +43 -13
- 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 +11 -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/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/options.d.ts +1 -4
- 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 +28 -5
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/driver/version.js.map +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +48 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- 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/registry.d.ts +27 -0
- package/dist/src/extensions/registry.js +13 -4
- package/dist/src/extensions/registry.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/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.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/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +28 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- 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/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/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.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-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.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 +53 -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-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.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/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +35 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +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/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- 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/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- 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/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- 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/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.js +44 -29
- package/dist/tests/e2e/web-streams.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- 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 +1 -0
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/cli.md +1 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +26 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/known-issues.md +35 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +14 -0
- package/doc/implemented/codegen.md +7 -0
- 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.md +7 -1
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +3 -2
- package/doc/implemented/runtime-core.md +13 -2
- package/doc/implemented/stdlib.md +79 -4
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/unimplemented/classes.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +19 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/known-issues.md +24 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +10 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- 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.md +1 -1
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +3 -2
- package/doc/zh-CN/implemented/runtime-core.md +10 -2
- package/doc/zh-CN/implemented/stdlib.md +64 -4
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/doc/zh-CN/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +9 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_internal.h +3 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +6 -1
- package/runtime/ext_gui/gui_engine.h +2 -0
- package/runtime/ext_gui/gui_events.cpp +13 -8
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +20 -170
- package/runtime/ext_gui/webgl_context.cpp +117 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_objects.h +16 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +8 -0
- 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/rt.h +63 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +61 -69
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +154 -181
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +29 -24
- package/runtime/xt_constructors.c +102 -2
- package/runtime/xt_containers/access.inc +125 -12
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +59 -75
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +5 -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_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +136 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +66 -1
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +104 -9
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +71 -55
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/scripts/build-runtime.ts +8 -0
- package/src/ast/common.ts +10 -0
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/source.ts +3 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +28 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +99 -1
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +26 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +13 -36
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +22 -0
- package/src/codegen/generator/tables.ts +18 -12
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +96 -12
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +4 -4
- package/src/driver/bundler/merge.ts +42 -9
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +14 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/frontend.ts +3 -4
- package/src/driver/options.ts +1 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +28 -5
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +50 -1
- 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/registry.ts +41 -4
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
- package/src/parser/literals.ts +6 -2
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
/* ------------------------------------------------------------------------- */
|
|
4
4
|
|
|
5
5
|
static void xt_object_reserve(xt_object *obj, uint32_t needed) {
|
|
6
|
+
XT_PROFILE_TICK(XT_PROFILE_OBJECT_RESERVE);
|
|
6
7
|
if (needed <= obj->capacity) return;
|
|
7
8
|
uint32_t capacity = obj->capacity ? obj->capacity * 2 : 8;
|
|
8
9
|
while (capacity < needed) capacity *= 2;
|
|
9
|
-
obj->properties =
|
|
10
|
+
obj->properties =
|
|
11
|
+
(xt_property *)xt_raw_realloc(obj->properties, sizeof(xt_property) * capacity);
|
|
10
12
|
if (!obj->properties) {
|
|
11
13
|
fprintf(stderr, "xbintsc: out of memory growing object\n");
|
|
12
14
|
abort();
|
|
@@ -125,6 +127,13 @@ xt_value xt_function_prototype(void) {
|
|
|
125
127
|
xt_function_proto_ready = 1;
|
|
126
128
|
xt_function_proto_root = xt_object_new_with_proto(xt_object_prototype());
|
|
127
129
|
xt_gc_add_root(&xt_function_proto_root);
|
|
130
|
+
/* `Function.prototype.call` / `.apply` / `.bind` / `.toString` are values
|
|
131
|
+
* libraries uncurry (`Function.call.bind(...)`), and
|
|
132
|
+
* `Function.prototype[Symbol.hasInstance]` must be present for the same
|
|
133
|
+
* reason. */
|
|
134
|
+
xt_install_proto_methods(xt_function_proto_root, "Function");
|
|
135
|
+
xt_object_set(xt_function_proto_root, xt_symbol_well_known("hasInstance"),
|
|
136
|
+
xt_function_has_instance_method());
|
|
128
137
|
/* `Array.constructor === Function` (every function inherits from here). The
|
|
129
138
|
* factory sees the ready flag, so this does not recurse. */
|
|
130
139
|
xt_value constructor = xt_builtin_constructor(xt_string_from_cstr("Function"));
|
|
@@ -188,6 +197,7 @@ xt_object *xt_as_object(xt_value value) {
|
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
static xt_property *xt_object_find(xt_object *obj, xt_value key) {
|
|
200
|
+
XT_PROFILE_TICK(XT_PROFILE_OBJECT_FIND);
|
|
191
201
|
for (uint32_t i = 0; i < obj->count; i++) {
|
|
192
202
|
if (xt_property_key_equals(obj->properties[i].key, key)) return &obj->properties[i];
|
|
193
203
|
}
|
|
@@ -223,6 +233,7 @@ static int xt_key_is_array_index(xt_string *key, uint32_t *out) {
|
|
|
223
233
|
/* Insert a new property for `key`, preserving JavaScript key order. Symbols
|
|
224
234
|
* are not array indices and simply append in insertion order. */
|
|
225
235
|
static xt_property *xt_object_insert_property(xt_object *obj, xt_value key) {
|
|
236
|
+
XT_PROFILE_TICK(XT_PROFILE_OBJECT_INSERT);
|
|
226
237
|
uint32_t index = 0;
|
|
227
238
|
uint32_t position = obj->count;
|
|
228
239
|
if (XT_IS_STRING(key) && xt_key_is_array_index(xt_as_string(key), &index)) {
|
|
@@ -282,9 +293,12 @@ static int xt_key_is_prototype(xt_value key) {
|
|
|
282
293
|
xt_value xt_object_get(xt_value value, xt_value key) {
|
|
283
294
|
/* A function's `.prototype` lives in a dedicated field (set by
|
|
284
295
|
`xt_function_set_prototype`), not in its property bag. Expose it as a
|
|
285
|
-
normal property so `Class.prototype` returns the object instances use.
|
|
296
|
+
normal property so `Class.prototype` returns the object instances use.
|
|
297
|
+
A plain function declaration starts without one — ES5 code assigns
|
|
298
|
+
`Foo.prototype.bar = ...` right after declaring `Foo`, so materialise it on
|
|
299
|
+
first read, like the specification's [[Construct]]-able function. */
|
|
286
300
|
if (XT_IS_FUNCTION(value) && xt_key_is_prototype(key)) {
|
|
287
|
-
return (
|
|
301
|
+
return xt_function_prototype_object(value);
|
|
288
302
|
}
|
|
289
303
|
xt_object *obj = xt_as_object(value);
|
|
290
304
|
if (!obj) return XT_UNDEFINED;
|
|
@@ -292,8 +306,11 @@ xt_value xt_object_get(xt_value value, xt_value key) {
|
|
|
292
306
|
layout. Containers such as Map/Set/Date/RegExp/Promise/Array must not be
|
|
293
307
|
interpreted as property tables, or property lookup reads past the end of
|
|
294
308
|
their real representation. */
|
|
295
|
-
if (obj->header.kind
|
|
296
|
-
|
|
309
|
+
if (!xt_kind_is_object(obj->header.kind)) return XT_UNDEFINED;
|
|
310
|
+
if (obj->header.kind == XT_OBJECT_KIND_ARRAY_BUFFER) {
|
|
311
|
+
xt_value served = xt_array_buffer_served_property(value, key);
|
|
312
|
+
if (served != XT_UNDEFINED) return served; /* `byteLength` / `slice` */
|
|
313
|
+
}
|
|
297
314
|
xt_value k = xt_to_property_key(key);
|
|
298
315
|
/* Walk the prototype chain like JavaScript property lookup. */
|
|
299
316
|
xt_object *cur = obj;
|
|
@@ -318,7 +335,15 @@ xt_value xt_object_get(xt_value value, xt_value key) {
|
|
|
318
335
|
continue;
|
|
319
336
|
}
|
|
320
337
|
if (!XT_IS_OBJECT(cur->prototype)) break;
|
|
321
|
-
|
|
338
|
+
xt_object *next = (xt_object *)XT_GET_PTR(cur->prototype);
|
|
339
|
+
if (next == cur) break;
|
|
340
|
+
/* A prototype may be any object value (`Object.setPrototypeOf(o, new Map())`
|
|
341
|
+
* is legal). Only plain objects and errors share the property-table layout;
|
|
342
|
+
* walking into a Map/Set/Date would read `count`/`properties` at the wrong
|
|
343
|
+
* offsets. Stop the chain instead, which is what the lookup would find
|
|
344
|
+
* anyway: those containers keep their state outside their property bag. */
|
|
345
|
+
if (!xt_kind_is_object(next->header.kind)) break;
|
|
346
|
+
cur = next;
|
|
322
347
|
}
|
|
323
348
|
/* A host view (`element.style`, `element.dataset`, computed style) answers the
|
|
324
349
|
* keys it owns dynamically. Only a miss reaches this point, so prototype
|
|
@@ -336,18 +361,19 @@ xt_value xt_object_get(xt_value value, xt_value key) {
|
|
|
336
361
|
static xt_object *xt_object_prototype_of(xt_value prototype, xt_object *current) {
|
|
337
362
|
xt_object *next = xt_as_object(prototype);
|
|
338
363
|
if (!next || next == current) return NULL;
|
|
339
|
-
if (next->header.kind
|
|
364
|
+
if (!xt_kind_is_object(next->header.kind))
|
|
340
365
|
return NULL;
|
|
341
366
|
return next;
|
|
342
367
|
}
|
|
343
368
|
|
|
344
369
|
xt_value xt_object_set(xt_value value, xt_value key, xt_value newValue) {
|
|
370
|
+
XT_PROFILE_TICK(XT_PROFILE_OBJECT_SET);
|
|
345
371
|
if (XT_IS_FUNCTION(value) && xt_key_is_prototype(key)) {
|
|
346
372
|
return xt_function_set_prototype(value, newValue);
|
|
347
373
|
}
|
|
348
374
|
xt_object *obj = xt_as_object(value);
|
|
349
375
|
if (!obj) return newValue;
|
|
350
|
-
if (obj->header.kind
|
|
376
|
+
if (!xt_kind_is_object(obj->header.kind))
|
|
351
377
|
return newValue;
|
|
352
378
|
if (obj->frozen) return newValue;
|
|
353
379
|
xt_value k = xt_to_property_key(key);
|
|
@@ -426,6 +452,7 @@ xt_value xt_object_get_prototype(xt_value value) {
|
|
|
426
452
|
switch (obj->header.kind) {
|
|
427
453
|
case XT_OBJECT_KIND_OBJECT:
|
|
428
454
|
case XT_OBJECT_KIND_ERROR:
|
|
455
|
+
case XT_OBJECT_KIND_ARRAY_BUFFER:
|
|
429
456
|
return obj->prototype;
|
|
430
457
|
case XT_OBJECT_KIND_SYMBOL:
|
|
431
458
|
case XT_OBJECT_KIND_MAP:
|
|
@@ -450,7 +477,12 @@ xt_value xt_object_set_prototype(xt_value value, xt_value proto) {
|
|
|
450
477
|
return value;
|
|
451
478
|
}
|
|
452
479
|
xt_object *obj = xt_as_object(value);
|
|
453
|
-
if (obj && !obj->frozen)
|
|
480
|
+
if (obj && !obj->frozen) {
|
|
481
|
+
obj->prototype = proto;
|
|
482
|
+
/* `reserved2` memoizes a typed array's element kind from its prototype
|
|
483
|
+
* (`xt_typed_array_kind_of`); a re-prototyped view is no longer that kind. */
|
|
484
|
+
obj->reserved2 = 0;
|
|
485
|
+
}
|
|
454
486
|
return value;
|
|
455
487
|
}
|
|
456
488
|
|
|
@@ -468,12 +500,22 @@ int xt_object_is_frozen(xt_value value) {
|
|
|
468
500
|
|
|
469
501
|
xt_value xt_object_from_entries(xt_value entries) {
|
|
470
502
|
xt_value result = xt_object_new();
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
503
|
+
/* `fromEntries` consumes *any* iterable (a `Map`, a `URLSearchParams`, a
|
|
504
|
+
* generator), not only an array: the shell-usage scan the Saltline page does
|
|
505
|
+
* with `Object.fromEntries(new URLSearchParams(location.search))` silently
|
|
506
|
+
* produced `{}` and the page fell back to its default boot path. */
|
|
507
|
+
xt_value iterator = xt_iter_open(entries);
|
|
508
|
+
xt_value index = xt_number(0);
|
|
509
|
+
while (xt_truthy(xt_iter_has(iterator, index))) {
|
|
510
|
+
xt_value item = xt_iter_value(iterator, index);
|
|
511
|
+
/* An entry is any object with `0`/`1` properties; arrays are a separate
|
|
512
|
+
* value tag, not `XT_IS_OBJECT` values. */
|
|
513
|
+
if (XT_IS_OBJECT(item) || XT_IS_ARRAY(item)) {
|
|
514
|
+
xt_value key = xt_get(item, xt_number(0));
|
|
515
|
+
xt_value value = xt_get(item, xt_number(1));
|
|
516
|
+
xt_object_set(result, key, value);
|
|
517
|
+
}
|
|
518
|
+
index = xt_number(xt_to_number(index) + 1.0);
|
|
477
519
|
}
|
|
478
520
|
return result;
|
|
479
521
|
}
|
|
@@ -481,7 +523,7 @@ xt_value xt_object_from_entries(xt_value entries) {
|
|
|
481
523
|
xt_value xt_object_has(xt_value value, xt_value key) {
|
|
482
524
|
if (!XT_IS_OBJECT(value)) return XT_FALSE;
|
|
483
525
|
xt_object *obj = (xt_object *)XT_GET_PTR(value);
|
|
484
|
-
if (obj->header.kind
|
|
526
|
+
if (!xt_kind_is_object(obj->header.kind)) {
|
|
485
527
|
return XT_FALSE;
|
|
486
528
|
}
|
|
487
529
|
xt_value propertyKey = xt_to_property_key(key);
|
|
@@ -499,68 +541,10 @@ xt_value xt_object_own_property_symbols(xt_value value) {
|
|
|
499
541
|
xt_value result = xt_array_new(0, NULL);
|
|
500
542
|
if (!XT_IS_OBJECT(value)) return result;
|
|
501
543
|
xt_object *obj = (xt_object *)XT_GET_PTR(value);
|
|
502
|
-
if (obj->header.kind
|
|
544
|
+
if (!xt_kind_is_object(obj->header.kind))
|
|
503
545
|
return result;
|
|
504
546
|
for (uint32_t i = 0; i < obj->count; i++) {
|
|
505
547
|
if (xt_is_symbol(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
|
|
506
548
|
}
|
|
507
549
|
return result;
|
|
508
550
|
}
|
|
509
|
-
|
|
510
|
-
xt_value xt_object_keys(xt_value value) {
|
|
511
|
-
xt_value result = xt_array_new(0, NULL);
|
|
512
|
-
/* A typed array's enumerable own keys are its indices; `length` and the
|
|
513
|
-
* buffer metadata are observable but not enumerable. */
|
|
514
|
-
int typed = xt_typed_array_kind_of(value);
|
|
515
|
-
if (typed >= 0) {
|
|
516
|
-
uint32_t length = (uint32_t)xt_to_number(xt_object_get_cstr(value, "length"));
|
|
517
|
-
for (uint32_t i = 0; i < length; i++) {
|
|
518
|
-
char buffer[32];
|
|
519
|
-
snprintf(buffer, sizeof(buffer), "%u", i);
|
|
520
|
-
xt_array_push(result, xt_string_from_cstr(buffer));
|
|
521
|
-
}
|
|
522
|
-
return result;
|
|
523
|
-
}
|
|
524
|
-
if (XT_IS_OBJECT(value)) {
|
|
525
|
-
xt_object *obj = (xt_object *)XT_GET_PTR(value);
|
|
526
|
-
for (uint32_t i = 0; i < obj->count; i++) {
|
|
527
|
-
if (XT_IS_STRING(obj->properties[i].key)) xt_array_push(result, obj->properties[i].key);
|
|
528
|
-
}
|
|
529
|
-
/* Dynamic keys of a host view (`element.dataset`, ...), appended without
|
|
530
|
-
* repeating a real property that was just pushed. */
|
|
531
|
-
xt_object_append_dynamic_keys(obj, value, result);
|
|
532
|
-
return result;
|
|
533
|
-
}
|
|
534
|
-
if (XT_IS_ARRAY(value)) {
|
|
535
|
-
xt_array *array = (xt_array *)XT_GET_PTR(value);
|
|
536
|
-
for (uint32_t i = 0; i < array->length; i++) {
|
|
537
|
-
char buffer[32];
|
|
538
|
-
snprintf(buffer, sizeof(buffer), "%u", i);
|
|
539
|
-
xt_array_push(result, xt_string_from_cstr(buffer));
|
|
540
|
-
}
|
|
541
|
-
if (XT_IS_OBJECT(array->extra)) {
|
|
542
|
-
xt_object *extra = (xt_object *)XT_GET_PTR(array->extra);
|
|
543
|
-
for (uint32_t i = 0; i < extra->count; i++) {
|
|
544
|
-
if (XT_IS_STRING(extra->properties[i].key)) xt_array_push(result, extra->properties[i].key);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return result;
|
|
548
|
-
}
|
|
549
|
-
if (XT_IS_STRING(value)) {
|
|
550
|
-
xt_string *s = xt_as_string(value);
|
|
551
|
-
uint32_t units = xt_string_utf16_length(s);
|
|
552
|
-
for (uint32_t i = 0; i < units; i++) {
|
|
553
|
-
char buffer[32];
|
|
554
|
-
snprintf(buffer, sizeof(buffer), "%u", i);
|
|
555
|
-
xt_array_push(result, xt_string_from_cstr(buffer));
|
|
556
|
-
}
|
|
557
|
-
return result;
|
|
558
|
-
}
|
|
559
|
-
return result;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
/* Convenience used by codegen for `obj.prop`. */
|
|
563
|
-
xt_value xt_object_get_cstr(xt_value value, const char *key) {
|
|
564
|
-
xt_value k = xt_string_from_cstr(key);
|
|
565
|
-
return xt_object_get(value, k);
|
|
566
|
-
}
|
|
@@ -4,23 +4,57 @@
|
|
|
4
4
|
|
|
5
5
|
/* Shapes are interned by their (parent, property key) transition. They are
|
|
6
6
|
* immortal metadata, but their keys are ordinary strings/symbols, so a root
|
|
7
|
-
* provider keeps those keys alive.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
7
|
+
* provider keeps those keys alive. A key is matched by *text* (see
|
|
8
|
+
* `xt_shape_bucket`), so an interned literal and a string built at run time with
|
|
9
|
+
* the same bytes share one transition.
|
|
10
|
+
*
|
|
11
|
+
* The bucket count and the intern limit are performance parameters, not
|
|
12
|
+
* semantics: a saturated table (or a NULL shape) disables the shape/method
|
|
13
|
+
* inline caches for every object created afterwards, so the next lookup is a
|
|
14
|
+
* linear scan of the receiver and its prototype chain. A GUI page built on a
|
|
15
|
+
* large JS bundle interns tens of thousands of transitions, so the old 256
|
|
16
|
+
* buckets / 16K shapes pair walked long chains and then silently degraded the
|
|
17
|
+
* hot paths; both are sized for a large application now.
|
|
18
|
+
*/
|
|
19
|
+
#define XT_SHAPE_BUCKETS 4096
|
|
11
20
|
/* Interned shapes are immortal metadata. A program that creates property names
|
|
12
21
|
* dynamically would otherwise leak one shape per name forever, so stop
|
|
13
22
|
* interning after a bounded number; those objects simply fall back to the
|
|
14
23
|
* uncached lookup (a NULL shape). */
|
|
15
|
-
#define XT_SHAPE_LIMIT
|
|
24
|
+
#define XT_SHAPE_LIMIT 262144
|
|
16
25
|
static xt_shape *g_shapes[XT_SHAPE_BUCKETS];
|
|
17
26
|
static xt_shape *g_shape_all = NULL;
|
|
18
27
|
static xt_shape *g_shape_root = NULL;
|
|
19
28
|
static uint32_t g_shape_count = 0;
|
|
20
29
|
|
|
30
|
+
/* A key's *content* decides its bucket, not the address of the string that
|
|
31
|
+
* holds it. Property keys built at run time (a typed array's `byteLength`, a
|
|
32
|
+
* DOM handle's `length`, any `obj["k" + i]`) are fresh string objects with the
|
|
33
|
+
* same bytes; hashing the pointer would put each of them in its own bucket, so
|
|
34
|
+
* the value comparison in the chain below could never find the existing
|
|
35
|
+
* transition and *every insert* would intern a new shape. Hashing the bytes is
|
|
36
|
+
* what makes value interning work, and therefore what keeps the shape table
|
|
37
|
+
* (and the inline caches that depend on it) usable in a large program. */
|
|
38
|
+
static uint64_t xt_shape_key_hash(xt_value key) {
|
|
39
|
+
if (XT_IS_STRING(key)) {
|
|
40
|
+
xt_string *string = xt_as_string(key);
|
|
41
|
+
const char *bytes = xt_string_bytes(string);
|
|
42
|
+
uint64_t hash = 1469598103934665603ULL; /* FNV-1a */
|
|
43
|
+
for (uint32_t i = 0; i < string->length; i++) {
|
|
44
|
+
hash ^= (unsigned char)bytes[i];
|
|
45
|
+
hash *= 1099511628211ULL;
|
|
46
|
+
}
|
|
47
|
+
return hash;
|
|
48
|
+
}
|
|
49
|
+
return (uint64_t)(uintptr_t)XT_GET_PTR(key);
|
|
50
|
+
}
|
|
51
|
+
|
|
21
52
|
static size_t xt_shape_bucket(xt_shape *parent, xt_value key) {
|
|
22
|
-
uintptr_t mixed = ((uintptr_t)parent >> 4) ^ (
|
|
23
|
-
|
|
53
|
+
uintptr_t mixed = ((uintptr_t)parent >> 4) ^ (uintptr_t)xt_shape_key_hash(key);
|
|
54
|
+
/* The low bits are alignment, not entropy: mix them before masking. */
|
|
55
|
+
mixed ^= mixed >> 17;
|
|
56
|
+
mixed *= 0x9e3779b97f4a7c15ULL;
|
|
57
|
+
return (size_t)(mixed >> 32) & (XT_SHAPE_BUCKETS - 1);
|
|
24
58
|
}
|
|
25
59
|
|
|
26
60
|
static void xt_shape_gc_roots(void) {
|
|
@@ -38,11 +72,111 @@ static xt_shape *xt_shape_empty(void) {
|
|
|
38
72
|
return shape;
|
|
39
73
|
}
|
|
40
74
|
|
|
75
|
+
static int xt_shape_trace_enabled(void) {
|
|
76
|
+
static int enabled = -1;
|
|
77
|
+
if (enabled < 0) {
|
|
78
|
+
const char *env = getenv("XT_SHAPE_TRACE");
|
|
79
|
+
enabled = (env != NULL && env[0] != '\0' && env[0] != '0') ? 1 : 0;
|
|
80
|
+
}
|
|
81
|
+
return enabled;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static uint64_t g_shape_rebuilds = 0;
|
|
85
|
+
|
|
86
|
+
/* Trace-only histogram over the property names that create transitions. */
|
|
87
|
+
typedef struct {
|
|
88
|
+
char text[24];
|
|
89
|
+
uint32_t count;
|
|
90
|
+
} xt_shape_key_stat;
|
|
91
|
+
#define XT_SHAPE_TRACE_KEYS 64
|
|
92
|
+
static xt_shape_key_stat g_shape_key_stats[XT_SHAPE_TRACE_KEYS];
|
|
93
|
+
static uint32_t g_shape_key_stat_count = 0;
|
|
94
|
+
|
|
95
|
+
static void xt_shape_trace_record(xt_value key) {
|
|
96
|
+
char text[24];
|
|
97
|
+
if (XT_IS_STRING(key)) {
|
|
98
|
+
xt_string *string = xt_as_string(key);
|
|
99
|
+
const char *bytes = xt_string_bytes(string);
|
|
100
|
+
uint32_t length = string->length;
|
|
101
|
+
if (length > 20) length = 20;
|
|
102
|
+
if (bytes) {
|
|
103
|
+
memcpy(text, bytes, length);
|
|
104
|
+
text[length] = '\0';
|
|
105
|
+
} else {
|
|
106
|
+
text[0] = '\0';
|
|
107
|
+
}
|
|
108
|
+
} else if (xt_is_symbol(key)) {
|
|
109
|
+
xt_value description = xt_symbol_description(key);
|
|
110
|
+
const char *name = XT_IS_STRING(description) ? xt_string_bytes(xt_as_string(description)) : "";
|
|
111
|
+
snprintf(text, sizeof(text), "@%s", name != NULL ? name : "");
|
|
112
|
+
} else {
|
|
113
|
+
snprintf(text, sizeof(text), "<other>");
|
|
114
|
+
}
|
|
115
|
+
for (uint32_t i = 0; i < g_shape_key_stat_count; i++) {
|
|
116
|
+
if (strcmp(g_shape_key_stats[i].text, text) == 0) {
|
|
117
|
+
g_shape_key_stats[i].count++;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (g_shape_key_stat_count < XT_SHAPE_TRACE_KEYS) {
|
|
122
|
+
snprintf(g_shape_key_stats[g_shape_key_stat_count].text, sizeof(g_shape_key_stats[0].text), "%s", text);
|
|
123
|
+
g_shape_key_stats[g_shape_key_stat_count].count = 1;
|
|
124
|
+
g_shape_key_stat_count++;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
static void xt_shape_trace_report(void) {
|
|
129
|
+
fprintf(stderr, "xt_shape: %u transitions, %llu rebuilds; top property names:", (unsigned)g_shape_count,
|
|
130
|
+
(unsigned long long)g_shape_rebuilds);
|
|
131
|
+
for (int rank = 0; rank < 8; rank++) {
|
|
132
|
+
int best = -1;
|
|
133
|
+
for (uint32_t i = 0; i < g_shape_key_stat_count; i++) {
|
|
134
|
+
if (g_shape_key_stats[i].count == 0) continue;
|
|
135
|
+
if (best < 0 || g_shape_key_stats[i].count > g_shape_key_stats[best].count) best = (int)i;
|
|
136
|
+
}
|
|
137
|
+
if (best < 0) break;
|
|
138
|
+
fprintf(stderr, " %s=%u", g_shape_key_stats[best].text, g_shape_key_stats[best].count);
|
|
139
|
+
g_shape_key_stats[best].count = 0;
|
|
140
|
+
}
|
|
141
|
+
fprintf(stderr, "\n");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/* Print the full property layout of a newly interned shape (root first). */
|
|
145
|
+
static void xt_shape_trace_chain(xt_shape *shape) {
|
|
146
|
+
const xt_shape *chain[64];
|
|
147
|
+
int depth = 0;
|
|
148
|
+
for (const xt_shape *s = shape; s != NULL && s->parent != NULL && depth < 64; s = s->parent) chain[depth++] = s;
|
|
149
|
+
fprintf(stderr, "xt_shape: latest layout:");
|
|
150
|
+
for (int i = depth - 1; i >= 0; i--) {
|
|
151
|
+
xt_value key = chain[i]->key;
|
|
152
|
+
if (XT_IS_STRING(key)) {
|
|
153
|
+
xt_string *string = xt_as_string(key);
|
|
154
|
+
const char *bytes = xt_string_bytes(string);
|
|
155
|
+
uint32_t length = string->length;
|
|
156
|
+
if (length > 16) length = 16;
|
|
157
|
+
fprintf(stderr, " %.*s", (int)length, bytes != NULL ? bytes : "");
|
|
158
|
+
} else if (xt_is_symbol(key)) {
|
|
159
|
+
xt_value description = xt_symbol_description(key);
|
|
160
|
+
const char *name = XT_IS_STRING(description) ? xt_string_bytes(xt_as_string(description)) : "?";
|
|
161
|
+
fprintf(stderr, " @%s", name != NULL ? name : "?");
|
|
162
|
+
} else {
|
|
163
|
+
fprintf(stderr, " <other>");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
fprintf(stderr, "\n");
|
|
167
|
+
}
|
|
168
|
+
|
|
41
169
|
xt_shape *xt_shape_transition(xt_shape *parent, xt_value key) {
|
|
42
170
|
if (!parent) parent = xt_shape_empty();
|
|
43
171
|
size_t bucket = xt_shape_bucket(parent, key);
|
|
44
172
|
for (xt_shape *shape = g_shapes[bucket]; shape; shape = shape->next) {
|
|
45
|
-
if (shape->parent
|
|
173
|
+
if (shape->parent != parent) continue;
|
|
174
|
+
/* Property keys are interned for literals, but a key built at run time
|
|
175
|
+
* (`obj[name]`, a number converted to a string, a symbol-less parser) is a
|
|
176
|
+
* fresh value every time. Interning by value, not by pointer, is what keeps
|
|
177
|
+
* a page from creating one shape per *insert* instead of one per distinct
|
|
178
|
+
* layout. */
|
|
179
|
+
if (shape->key == key || xt_property_key_equals(shape->key, key)) return shape;
|
|
46
180
|
}
|
|
47
181
|
if (g_shape_count >= XT_SHAPE_LIMIT) return NULL;
|
|
48
182
|
xt_shape *shape = (xt_shape *)calloc(1, sizeof(xt_shape));
|
|
@@ -55,10 +189,21 @@ xt_shape *xt_shape_transition(xt_shape *parent, xt_value key) {
|
|
|
55
189
|
shape->all_next = g_shape_all;
|
|
56
190
|
g_shape_all = shape;
|
|
57
191
|
g_shape_count++;
|
|
192
|
+
/* Diagnostics: `XT_SHAPE_TRACE=1` reports the interned-transition count so a
|
|
193
|
+
* page that needs a larger table is visible instead of silently degrading.
|
|
194
|
+
* The per-key histogram shows *which* property names are multiplying. */
|
|
195
|
+
if (xt_shape_trace_enabled()) {
|
|
196
|
+
xt_shape_trace_record(key);
|
|
197
|
+
if ((g_shape_count & 32767u) == 0) {
|
|
198
|
+
xt_shape_trace_report();
|
|
199
|
+
xt_shape_trace_chain(shape);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
58
202
|
return shape;
|
|
59
203
|
}
|
|
60
204
|
|
|
61
205
|
void xt_object_shape_changed(xt_object *obj) {
|
|
206
|
+
g_shape_rebuilds++;
|
|
62
207
|
xt_shape *shape = xt_shape_empty();
|
|
63
208
|
for (uint32_t i = 0; i < obj->count; i++) {
|
|
64
209
|
shape = xt_shape_transition(shape, obj->properties[i].key);
|
package/runtime/xt_containers.c
CHANGED
|
@@ -17,7 +17,12 @@
|
|
|
17
17
|
#include <string.h>
|
|
18
18
|
|
|
19
19
|
#include "xt_containers/shapes.inc"
|
|
20
|
+
#include "xt_containers/function_prototypes.inc"
|
|
20
21
|
#include "xt_containers/objects.inc"
|
|
22
|
+
#include "xt_containers/cstr_cache.inc"
|
|
23
|
+
#include "xt_containers/object_keys.inc"
|
|
21
24
|
#include "xt_containers/arrays.inc"
|
|
22
25
|
#include "xt_containers/access.inc"
|
|
26
|
+
#include "xt_containers/method_cache.inc"
|
|
23
27
|
#include "xt_containers/boxes.inc"
|
|
28
|
+
|
|
@@ -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"
|