@despia-native/kernel 0.0.0-coming-soon.0 → 0.3.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/LICENSE +202 -0
- package/NOTICE +1414 -0
- package/README.md +16 -1
- package/dist/.dsx-build-stamp.json +7 -0
- package/dist/api-cohort.d.ts +27 -0
- package/dist/api-cohort.d.ts.map +1 -0
- package/dist/api-cohort.js +94 -0
- package/dist/api-cohort.js.map +1 -0
- package/dist/api.d.ts +454 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +2442 -0
- package/dist/api.js.map +1 -0
- package/dist/app-consts.d.ts +10 -0
- package/dist/app-consts.d.ts.map +1 -0
- package/dist/app-consts.js +39 -0
- package/dist/app-consts.js.map +1 -0
- package/dist/app-update.d.ts +12 -0
- package/dist/app-update.d.ts.map +1 -0
- package/dist/app-update.js +32 -0
- package/dist/app-update.js.map +1 -0
- package/dist/aria.d.ts +152 -0
- package/dist/aria.d.ts.map +1 -0
- package/dist/aria.js +524 -0
- package/dist/aria.js.map +1 -0
- package/dist/audio-core.d.ts +260 -0
- package/dist/audio-core.d.ts.map +1 -0
- package/dist/audio-core.js +1440 -0
- package/dist/audio-core.js.map +1 -0
- package/dist/audio-edit.d.ts +100 -0
- package/dist/audio-edit.d.ts.map +1 -0
- package/dist/audio-edit.js +489 -0
- package/dist/audio-edit.js.map +1 -0
- package/dist/audio-mix.d.ts +84 -0
- package/dist/audio-mix.d.ts.map +1 -0
- package/dist/audio-mix.js +393 -0
- package/dist/audio-mix.js.map +1 -0
- package/dist/auth-proof.d.ts +145 -0
- package/dist/auth-proof.d.ts.map +1 -0
- package/dist/auth-proof.js +644 -0
- package/dist/auth-proof.js.map +1 -0
- package/dist/availability-explain.d.ts +3 -0
- package/dist/availability-explain.d.ts.map +1 -0
- package/dist/availability-explain.js +322 -0
- package/dist/availability-explain.js.map +1 -0
- package/dist/availability.d.ts +246 -0
- package/dist/availability.d.ts.map +1 -0
- package/dist/availability.js +615 -0
- package/dist/availability.js.map +1 -0
- package/dist/background.d.ts +116 -0
- package/dist/background.d.ts.map +1 -0
- package/dist/background.js +235 -0
- package/dist/background.js.map +1 -0
- package/dist/boot-tables-flag.d.ts +2 -0
- package/dist/boot-tables-flag.d.ts.map +1 -0
- package/dist/boot-tables-flag.js +16 -0
- package/dist/boot-tables-flag.js.map +1 -0
- package/dist/boot-tables.d.ts +40 -0
- package/dist/boot-tables.d.ts.map +1 -0
- package/dist/boot-tables.js +102 -0
- package/dist/boot-tables.js.map +1 -0
- package/dist/border-edges.d.ts +5 -0
- package/dist/border-edges.d.ts.map +1 -0
- package/dist/border-edges.js +47 -0
- package/dist/border-edges.js.map +1 -0
- package/dist/bus.d.ts +1203 -0
- package/dist/bus.d.ts.map +1 -0
- package/dist/bus.js +2647 -0
- package/dist/bus.js.map +1 -0
- package/dist/calendar-core.d.ts +143 -0
- package/dist/calendar-core.d.ts.map +1 -0
- package/dist/calendar-core.js +372 -0
- package/dist/calendar-core.js.map +1 -0
- package/dist/call-value.d.ts +16 -0
- package/dist/call-value.d.ts.map +1 -0
- package/dist/call-value.js +54 -0
- package/dist/call-value.js.map +1 -0
- package/dist/camera-core.d.ts +222 -0
- package/dist/camera-core.d.ts.map +1 -0
- package/dist/camera-core.js +980 -0
- package/dist/camera-core.js.map +1 -0
- package/dist/canvas-core.d.ts +404 -0
- package/dist/canvas-core.d.ts.map +1 -0
- package/dist/canvas-core.js +2186 -0
- package/dist/canvas-core.js.map +1 -0
- package/dist/capture-core.d.ts +74 -0
- package/dist/capture-core.d.ts.map +1 -0
- package/dist/capture-core.js +158 -0
- package/dist/capture-core.js.map +1 -0
- package/dist/compile/codegen.d.ts +146 -0
- package/dist/compile/codegen.d.ts.map +1 -0
- package/dist/compile/codegen.js +1949 -0
- package/dist/compile/codegen.js.map +1 -0
- package/dist/compile/jstier.d.ts +44 -0
- package/dist/compile/jstier.d.ts.map +1 -0
- package/dist/compile/jstier.js +181 -0
- package/dist/compile/jstier.js.map +1 -0
- package/dist/compile/tier-door.d.ts +41 -0
- package/dist/compile/tier-door.d.ts.map +1 -0
- package/dist/compile/tier-door.js +167 -0
- package/dist/compile/tier-door.js.map +1 -0
- package/dist/compile/tier-realm.d.ts +49 -0
- package/dist/compile/tier-realm.d.ts.map +1 -0
- package/dist/compile/tier-realm.js +368 -0
- package/dist/compile/tier-realm.js.map +1 -0
- package/dist/compile/tier.d.ts +23 -0
- package/dist/compile/tier.d.ts.map +1 -0
- package/dist/compile/tier.js +157 -0
- package/dist/compile/tier.js.map +1 -0
- package/dist/compose-core.d.ts +86 -0
- package/dist/compose-core.d.ts.map +1 -0
- package/dist/compose-core.js +112 -0
- package/dist/compose-core.js.map +1 -0
- package/dist/config-validate.d.ts +31 -0
- package/dist/config-validate.d.ts.map +1 -0
- package/dist/config-validate.js +147 -0
- package/dist/config-validate.js.map +1 -0
- package/dist/config-values.d.ts +106 -0
- package/dist/config-values.d.ts.map +1 -0
- package/dist/config-values.js +340 -0
- package/dist/config-values.js.map +1 -0
- package/dist/contacts-core.d.ts +127 -0
- package/dist/contacts-core.d.ts.map +1 -0
- package/dist/contacts-core.js +211 -0
- package/dist/contacts-core.js.map +1 -0
- package/dist/content-transition.d.ts +58 -0
- package/dist/content-transition.d.ts.map +1 -0
- package/dist/content-transition.js +94 -0
- package/dist/content-transition.js.map +1 -0
- package/dist/controls-core.d.ts +227 -0
- package/dist/controls-core.d.ts.map +1 -0
- package/dist/controls-core.js +652 -0
- package/dist/controls-core.js.map +1 -0
- package/dist/cookies.d.ts +78 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +265 -0
- package/dist/cookies.js.map +1 -0
- package/dist/corner-shape-core.d.ts +69 -0
- package/dist/corner-shape-core.d.ts.map +1 -0
- package/dist/corner-shape-core.js +261 -0
- package/dist/corner-shape-core.js.map +1 -0
- package/dist/crypto-core.d.ts +57 -0
- package/dist/crypto-core.d.ts.map +1 -0
- package/dist/crypto-core.js +128 -0
- package/dist/crypto-core.js.map +1 -0
- package/dist/dataviz.d.ts +436 -0
- package/dist/dataviz.d.ts.map +1 -0
- package/dist/dataviz.js +956 -0
- package/dist/dataviz.js.map +1 -0
- package/dist/debug.d.ts +293 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +767 -0
- package/dist/debug.js.map +1 -0
- package/dist/device-ownership.d.ts +50 -0
- package/dist/device-ownership.d.ts.map +1 -0
- package/dist/device-ownership.js +105 -0
- package/dist/device-ownership.js.map +1 -0
- package/dist/effects.d.ts +86 -0
- package/dist/effects.d.ts.map +1 -0
- package/dist/effects.js +98 -0
- package/dist/effects.js.map +1 -0
- package/dist/element.d.ts +108 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +63 -0
- package/dist/element.js.map +1 -0
- package/dist/file-watch.d.ts +16 -0
- package/dist/file-watch.d.ts.map +1 -0
- package/dist/file-watch.js +49 -0
- package/dist/file-watch.js.map +1 -0
- package/dist/filepaths.d.ts +72 -0
- package/dist/filepaths.d.ts.map +1 -0
- package/dist/filepaths.js +271 -0
- package/dist/filepaths.js.map +1 -0
- package/dist/film.d.ts +264 -0
- package/dist/film.d.ts.map +1 -0
- package/dist/film.js +313 -0
- package/dist/film.js.map +1 -0
- package/dist/fonts.d.ts +66 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +135 -0
- package/dist/fonts.js.map +1 -0
- package/dist/forms.d.ts +191 -0
- package/dist/forms.d.ts.map +1 -0
- package/dist/forms.js +663 -0
- package/dist/forms.js.map +1 -0
- package/dist/geo.d.ts +289 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +460 -0
- package/dist/geo.js.map +1 -0
- package/dist/handler-announce.d.ts +46 -0
- package/dist/handler-announce.d.ts.map +1 -0
- package/dist/handler-announce.js +96 -0
- package/dist/handler-announce.js.map +1 -0
- package/dist/handoff.d.ts +71 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +250 -0
- package/dist/handoff.js.map +1 -0
- package/dist/identity-durability.d.ts +76 -0
- package/dist/identity-durability.d.ts.map +1 -0
- package/dist/identity-durability.js +150 -0
- package/dist/identity-durability.js.map +1 -0
- package/dist/image-core.d.ts +240 -0
- package/dist/image-core.d.ts.map +1 -0
- package/dist/image-core.js +618 -0
- package/dist/image-core.js.map +1 -0
- package/dist/image-schemes.d.ts +10 -0
- package/dist/image-schemes.d.ts.map +1 -0
- package/dist/image-schemes.js +28 -0
- package/dist/image-schemes.js.map +1 -0
- package/dist/index.d.ts +143 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -0
- package/dist/ink-core.d.ts +53 -0
- package/dist/ink-core.d.ts.map +1 -0
- package/dist/ink-core.js +119 -0
- package/dist/ink-core.js.map +1 -0
- package/dist/input.d.ts +148 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +358 -0
- package/dist/input.js.map +1 -0
- package/dist/integrity.d.ts +63 -0
- package/dist/integrity.d.ts.map +1 -0
- package/dist/integrity.js +150 -0
- package/dist/integrity.js.map +1 -0
- package/dist/intents.d.ts +95 -0
- package/dist/intents.d.ts.map +1 -0
- package/dist/intents.js +282 -0
- package/dist/intents.js.map +1 -0
- package/dist/interpolate-core.d.ts +37 -0
- package/dist/interpolate-core.d.ts.map +1 -0
- package/dist/interpolate-core.js +443 -0
- package/dist/interpolate-core.js.map +1 -0
- package/dist/jse/color.d.ts +12 -0
- package/dist/jse/color.d.ts.map +1 -0
- package/dist/jse/color.js +196 -0
- package/dist/jse/color.js.map +1 -0
- package/dist/jse/core.d.ts +54 -0
- package/dist/jse/core.d.ts.map +1 -0
- package/dist/jse/core.js +1519 -0
- package/dist/jse/core.js.map +1 -0
- package/dist/jse/dispatch.d.ts +28 -0
- package/dist/jse/dispatch.d.ts.map +1 -0
- package/dist/jse/dispatch.js +116 -0
- package/dist/jse/dispatch.js.map +1 -0
- package/dist/jse/highlight-grammar.d.ts +15 -0
- package/dist/jse/highlight-grammar.d.ts.map +1 -0
- package/dist/jse/highlight-grammar.js +161 -0
- package/dist/jse/highlight-grammar.js.map +1 -0
- package/dist/jse/highlight-grammars.generated.d.ts +2 -0
- package/dist/jse/highlight-grammars.generated.d.ts.map +1 -0
- package/dist/jse/highlight-grammars.generated.js +4 -0
- package/dist/jse/highlight-grammars.generated.js.map +1 -0
- package/dist/jse/highlight.d.ts +37 -0
- package/dist/jse/highlight.d.ts.map +1 -0
- package/dist/jse/highlight.js +323 -0
- package/dist/jse/highlight.js.map +1 -0
- package/dist/jse/jse.d.ts +674 -0
- package/dist/jse/jse.d.ts.map +1 -0
- package/dist/jse/jse.js +5841 -0
- package/dist/jse/jse.js.map +1 -0
- package/dist/jse/pathmatch.d.ts +10 -0
- package/dist/jse/pathmatch.d.ts.map +1 -0
- package/dist/jse/pathmatch.js +73 -0
- package/dist/jse/pathmatch.js.map +1 -0
- package/dist/jse/regex.d.ts +33 -0
- package/dist/jse/regex.d.ts.map +1 -0
- package/dist/jse/regex.js +375 -0
- package/dist/jse/regex.js.map +1 -0
- package/dist/jse/stdlib.d.ts +8 -0
- package/dist/jse/stdlib.d.ts.map +1 -0
- package/dist/jse/stdlib.js +765 -0
- package/dist/jse/stdlib.js.map +1 -0
- package/dist/jse/tokens.d.ts +102 -0
- package/dist/jse/tokens.d.ts.map +1 -0
- package/dist/jse/tokens.js +982 -0
- package/dist/jse/tokens.js.map +1 -0
- package/dist/jse/values.d.ts +206 -0
- package/dist/jse/values.d.ts.map +1 -0
- package/dist/jse/values.js +846 -0
- package/dist/jse/values.js.map +1 -0
- package/dist/keyboard.d.ts +196 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +186 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/label-choices.d.ts +3 -0
- package/dist/label-choices.d.ts.map +1 -0
- package/dist/label-choices.js +168 -0
- package/dist/label-choices.js.map +1 -0
- package/dist/language.d.ts +33 -0
- package/dist/language.d.ts.map +1 -0
- package/dist/language.js +50 -0
- package/dist/language.js.map +1 -0
- package/dist/length-units.d.ts +30 -0
- package/dist/length-units.d.ts.map +1 -0
- package/dist/length-units.js +83 -0
- package/dist/length-units.js.map +1 -0
- package/dist/lightsensor.d.ts +48 -0
- package/dist/lightsensor.d.ts.map +1 -0
- package/dist/lightsensor.js +97 -0
- package/dist/lightsensor.js.map +1 -0
- package/dist/link-refresh.d.ts +27 -0
- package/dist/link-refresh.d.ts.map +1 -0
- package/dist/link-refresh.js +166 -0
- package/dist/link-refresh.js.map +1 -0
- package/dist/link.d.ts +57 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +333 -0
- package/dist/link.js.map +1 -0
- package/dist/linkpreview.d.ts +114 -0
- package/dist/linkpreview.d.ts.map +1 -0
- package/dist/linkpreview.js +439 -0
- package/dist/linkpreview.js.map +1 -0
- package/dist/list-presence.d.ts +32 -0
- package/dist/list-presence.d.ts.map +1 -0
- package/dist/list-presence.js +48 -0
- package/dist/list-presence.js.map +1 -0
- package/dist/live-stream.d.ts +27 -0
- package/dist/live-stream.d.ts.map +1 -0
- package/dist/live-stream.js +274 -0
- package/dist/live-stream.js.map +1 -0
- package/dist/livelogs.d.ts +134 -0
- package/dist/livelogs.d.ts.map +1 -0
- package/dist/livelogs.js +409 -0
- package/dist/livelogs.js.map +1 -0
- package/dist/logs.d.ts +80 -0
- package/dist/logs.d.ts.map +1 -0
- package/dist/logs.js +206 -0
- package/dist/logs.js.map +1 -0
- package/dist/mcp/apps.d.ts +82 -0
- package/dist/mcp/apps.d.ts.map +1 -0
- package/dist/mcp/apps.js +219 -0
- package/dist/mcp/apps.js.map +1 -0
- package/dist/mcp/entities.d.ts +25 -0
- package/dist/mcp/entities.d.ts.map +1 -0
- package/dist/mcp/entities.js +71 -0
- package/dist/mcp/entities.js.map +1 -0
- package/dist/mcp/result.d.ts +73 -0
- package/dist/mcp/result.d.ts.map +1 -0
- package/dist/mcp/result.js +119 -0
- package/dist/mcp/result.js.map +1 -0
- package/dist/mcp/webmcp.d.ts +162 -0
- package/dist/mcp/webmcp.d.ts.map +1 -0
- package/dist/mcp/webmcp.js +214 -0
- package/dist/mcp/webmcp.js.map +1 -0
- package/dist/mcp.d.ts +5 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +14 -0
- package/dist/mcp.js.map +1 -0
- package/dist/media-core.d.ts +191 -0
- package/dist/media-core.d.ts.map +1 -0
- package/dist/media-core.js +446 -0
- package/dist/media-core.js.map +1 -0
- package/dist/media-timeline-core.d.ts +94 -0
- package/dist/media-timeline-core.d.ts.map +1 -0
- package/dist/media-timeline-core.js +620 -0
- package/dist/media-timeline-core.js.map +1 -0
- package/dist/message.d.ts +42 -0
- package/dist/message.d.ts.map +1 -0
- package/dist/message.js +582 -0
- package/dist/message.js.map +1 -0
- package/dist/missing-element.d.ts +29 -0
- package/dist/missing-element.d.ts.map +1 -0
- package/dist/missing-element.js +76 -0
- package/dist/missing-element.js.map +1 -0
- package/dist/motion-core.d.ts +160 -0
- package/dist/motion-core.d.ts.map +1 -0
- package/dist/motion-core.js +752 -0
- package/dist/motion-core.js.map +1 -0
- package/dist/motion-pose.d.ts +65 -0
- package/dist/motion-pose.d.ts.map +1 -0
- package/dist/motion-pose.js +143 -0
- package/dist/motion-pose.js.map +1 -0
- package/dist/motion.d.ts +132 -0
- package/dist/motion.d.ts.map +1 -0
- package/dist/motion.js +260 -0
- package/dist/motion.js.map +1 -0
- package/dist/mount-core.d.ts +203 -0
- package/dist/mount-core.d.ts.map +1 -0
- package/dist/mount-core.js +437 -0
- package/dist/mount-core.js.map +1 -0
- package/dist/net-core.d.ts +110 -0
- package/dist/net-core.d.ts.map +1 -0
- package/dist/net-core.js +225 -0
- package/dist/net-core.js.map +1 -0
- package/dist/notify.d.ts +399 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +964 -0
- package/dist/notify.js.map +1 -0
- package/dist/orientation-binding.d.ts +39 -0
- package/dist/orientation-binding.d.ts.map +1 -0
- package/dist/orientation-binding.js +64 -0
- package/dist/orientation-binding.js.map +1 -0
- package/dist/orientation.d.ts +55 -0
- package/dist/orientation.d.ts.map +1 -0
- package/dist/orientation.js +89 -0
- package/dist/orientation.js.map +1 -0
- package/dist/ota.d.ts +52 -0
- package/dist/ota.d.ts.map +1 -0
- package/dist/ota.js +122 -0
- package/dist/ota.js.map +1 -0
- package/dist/passkeys.d.ts +91 -0
- package/dist/passkeys.d.ts.map +1 -0
- package/dist/passkeys.js +307 -0
- package/dist/passkeys.js.map +1 -0
- package/dist/payment.d.ts +85 -0
- package/dist/payment.d.ts.map +1 -0
- package/dist/payment.js +270 -0
- package/dist/payment.js.map +1 -0
- package/dist/pending-presenter.d.ts +31 -0
- package/dist/pending-presenter.d.ts.map +1 -0
- package/dist/pending-presenter.js +119 -0
- package/dist/pending-presenter.js.map +1 -0
- package/dist/permission-core.d.ts +59 -0
- package/dist/permission-core.d.ts.map +1 -0
- package/dist/permission-core.js +102 -0
- package/dist/permission-core.js.map +1 -0
- package/dist/persist.d.ts +169 -0
- package/dist/persist.d.ts.map +1 -0
- package/dist/persist.js +361 -0
- package/dist/persist.js.map +1 -0
- package/dist/phase-plan.d.ts +114 -0
- package/dist/phase-plan.d.ts.map +1 -0
- package/dist/phase-plan.js +837 -0
- package/dist/phase-plan.js.map +1 -0
- package/dist/playback-core.d.ts +64 -0
- package/dist/playback-core.d.ts.map +1 -0
- package/dist/playback-core.js +176 -0
- package/dist/playback-core.js.map +1 -0
- package/dist/player-sources.d.ts +12 -0
- package/dist/player-sources.d.ts.map +1 -0
- package/dist/player-sources.js +44 -0
- package/dist/player-sources.js.map +1 -0
- package/dist/proxy-denylist.d.ts +11 -0
- package/dist/proxy-denylist.d.ts.map +1 -0
- package/dist/proxy-denylist.js +44 -0
- package/dist/proxy-denylist.js.map +1 -0
- package/dist/public-config.d.ts +20 -0
- package/dist/public-config.d.ts.map +1 -0
- package/dist/public-config.js +109 -0
- package/dist/public-config.js.map +1 -0
- package/dist/qoe-core.d.ts +72 -0
- package/dist/qoe-core.d.ts.map +1 -0
- package/dist/qoe-core.js +113 -0
- package/dist/qoe-core.js.map +1 -0
- package/dist/reactive-request.d.ts +80 -0
- package/dist/reactive-request.d.ts.map +1 -0
- package/dist/reactive-request.js +192 -0
- package/dist/reactive-request.js.map +1 -0
- package/dist/read-cache.d.ts +129 -0
- package/dist/read-cache.d.ts.map +1 -0
- package/dist/read-cache.js +566 -0
- package/dist/read-cache.js.map +1 -0
- package/dist/recorder-core.d.ts +57 -0
- package/dist/recorder-core.d.ts.map +1 -0
- package/dist/recorder-core.js +136 -0
- package/dist/recorder-core.js.map +1 -0
- package/dist/ref.d.ts +41 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +98 -0
- package/dist/ref.js.map +1 -0
- package/dist/refusal.d.ts +82 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +218 -0
- package/dist/refusal.js.map +1 -0
- package/dist/region-insets.d.ts +61 -0
- package/dist/region-insets.d.ts.map +1 -0
- package/dist/region-insets.js +67 -0
- package/dist/region-insets.js.map +1 -0
- package/dist/rive-core.d.ts +323 -0
- package/dist/rive-core.d.ts.map +1 -0
- package/dist/rive-core.js +677 -0
- package/dist/rive-core.js.map +1 -0
- package/dist/runner.d.ts +595 -0
- package/dist/runner.d.ts.map +1 -0
- package/dist/runner.js +4094 -0
- package/dist/runner.js.map +1 -0
- package/dist/scene/a11y.d.ts +11 -0
- package/dist/scene/a11y.d.ts.map +1 -0
- package/dist/scene/a11y.js +67 -0
- package/dist/scene/a11y.js.map +1 -0
- package/dist/scene/anim.d.ts +149 -0
- package/dist/scene/anim.d.ts.map +1 -0
- package/dist/scene/anim.js +396 -0
- package/dist/scene/anim.js.map +1 -0
- package/dist/scene/bind.d.ts +33 -0
- package/dist/scene/bind.d.ts.map +1 -0
- package/dist/scene/bind.js +66 -0
- package/dist/scene/bind.js.map +1 -0
- package/dist/scene/collide.d.ts +56 -0
- package/dist/scene/collide.d.ts.map +1 -0
- package/dist/scene/collide.js +146 -0
- package/dist/scene/collide.js.map +1 -0
- package/dist/scene/frame.d.ts +22 -0
- package/dist/scene/frame.d.ts.map +1 -0
- package/dist/scene/frame.js +57 -0
- package/dist/scene/frame.js.map +1 -0
- package/dist/scene/gltf.d.ts +79 -0
- package/dist/scene/gltf.d.ts.map +1 -0
- package/dist/scene/gltf.js +409 -0
- package/dist/scene/gltf.js.map +1 -0
- package/dist/scene/ir.d.ts +293 -0
- package/dist/scene/ir.d.ts.map +1 -0
- package/dist/scene/ir.js +692 -0
- package/dist/scene/ir.js.map +1 -0
- package/dist/scene/math.d.ts +50 -0
- package/dist/scene/math.d.ts.map +1 -0
- package/dist/scene/math.js +180 -0
- package/dist/scene/math.js.map +1 -0
- package/dist/scene/orbit.d.ts +19 -0
- package/dist/scene/orbit.d.ts.map +1 -0
- package/dist/scene/orbit.js +60 -0
- package/dist/scene/orbit.js.map +1 -0
- package/dist/scene/physics.d.ts +228 -0
- package/dist/scene/physics.d.ts.map +1 -0
- package/dist/scene/physics.js +1500 -0
- package/dist/scene/physics.js.map +1 -0
- package/dist/scene/registry.d.ts +85 -0
- package/dist/scene/registry.d.ts.map +1 -0
- package/dist/scene/registry.js +75 -0
- package/dist/scene/registry.js.map +1 -0
- package/dist/scene/skin.d.ts +82 -0
- package/dist/scene/skin.d.ts.map +1 -0
- package/dist/scene/skin.js +351 -0
- package/dist/scene/skin.js.map +1 -0
- package/dist/scene/sprite.d.ts +36 -0
- package/dist/scene/sprite.d.ts.map +1 -0
- package/dist/scene/sprite.js +107 -0
- package/dist/scene/sprite.js.map +1 -0
- package/dist/scene/viewer.d.ts +96 -0
- package/dist/scene/viewer.d.ts.map +1 -0
- package/dist/scene/viewer.js +235 -0
- package/dist/scene/viewer.js.map +1 -0
- package/dist/scoped-slots.d.ts +9 -0
- package/dist/scoped-slots.d.ts.map +1 -0
- package/dist/scoped-slots.js +42 -0
- package/dist/scoped-slots.js.map +1 -0
- package/dist/screen.d.ts +109 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +309 -0
- package/dist/screen.js.map +1 -0
- package/dist/scroll.d.ts +525 -0
- package/dist/scroll.d.ts.map +1 -0
- package/dist/scroll.js +1226 -0
- package/dist/scroll.js.map +1 -0
- package/dist/settings-plane.d.ts +58 -0
- package/dist/settings-plane.d.ts.map +1 -0
- package/dist/settings-plane.js +86 -0
- package/dist/settings-plane.js.map +1 -0
- package/dist/share-inbox.d.ts +56 -0
- package/dist/share-inbox.d.ts.map +1 -0
- package/dist/share-inbox.js +114 -0
- package/dist/share-inbox.js.map +1 -0
- package/dist/shared-transition.d.ts +152 -0
- package/dist/shared-transition.d.ts.map +1 -0
- package/dist/shared-transition.js +257 -0
- package/dist/shared-transition.js.map +1 -0
- package/dist/sheet-content-padding.d.ts +24 -0
- package/dist/sheet-content-padding.d.ts.map +1 -0
- package/dist/sheet-content-padding.js +32 -0
- package/dist/sheet-content-padding.js.map +1 -0
- package/dist/shot-devices.d.ts +36 -0
- package/dist/shot-devices.d.ts.map +1 -0
- package/dist/shot-devices.js +90 -0
- package/dist/shot-devices.js.map +1 -0
- package/dist/shot-guards.d.ts +100 -0
- package/dist/shot-guards.d.ts.map +1 -0
- package/dist/shot-guards.js +260 -0
- package/dist/shot-guards.js.map +1 -0
- package/dist/shot-scope.d.ts +140 -0
- package/dist/shot-scope.d.ts.map +1 -0
- package/dist/shot-scope.js +302 -0
- package/dist/shot-scope.js.map +1 -0
- package/dist/slot-partition.d.ts +9 -0
- package/dist/slot-partition.d.ts.map +1 -0
- package/dist/slot-partition.js +38 -0
- package/dist/slot-partition.js.map +1 -0
- package/dist/snackbar.d.ts +165 -0
- package/dist/snackbar.d.ts.map +1 -0
- package/dist/snackbar.js +220 -0
- package/dist/snackbar.js.map +1 -0
- package/dist/socket.d.ts +96 -0
- package/dist/socket.d.ts.map +1 -0
- package/dist/socket.js +370 -0
- package/dist/socket.js.map +1 -0
- package/dist/spotlight.d.ts +77 -0
- package/dist/spotlight.d.ts.map +1 -0
- package/dist/spotlight.js +174 -0
- package/dist/spotlight.js.map +1 -0
- package/dist/state-primitive.d.ts +37 -0
- package/dist/state-primitive.d.ts.map +1 -0
- package/dist/state-primitive.js +91 -0
- package/dist/state-primitive.js.map +1 -0
- package/dist/store-query.d.ts +25 -0
- package/dist/store-query.d.ts.map +1 -0
- package/dist/store-query.js +88 -0
- package/dist/store-query.js.map +1 -0
- package/dist/store-value.d.ts +48 -0
- package/dist/store-value.d.ts.map +1 -0
- package/dist/store-value.js +264 -0
- package/dist/store-value.js.map +1 -0
- package/dist/store-versioning.d.ts +70 -0
- package/dist/store-versioning.d.ts.map +1 -0
- package/dist/store-versioning.js +188 -0
- package/dist/store-versioning.js.map +1 -0
- package/dist/store.d.ts +282 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +1144 -0
- package/dist/store.js.map +1 -0
- package/dist/strings.d.ts +141 -0
- package/dist/strings.d.ts.map +1 -0
- package/dist/strings.js +581 -0
- package/dist/strings.js.map +1 -0
- package/dist/telemetry.d.ts +95 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +255 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/transform-core.d.ts +228 -0
- package/dist/transform-core.d.ts.map +1 -0
- package/dist/transform-core.js +921 -0
- package/dist/transform-core.js.map +1 -0
- package/dist/transition-core.d.ts +58 -0
- package/dist/transition-core.d.ts.map +1 -0
- package/dist/transition-core.js +352 -0
- package/dist/transition-core.js.map +1 -0
- package/dist/trim-trailing.d.ts +3 -0
- package/dist/trim-trailing.d.ts.map +1 -0
- package/dist/trim-trailing.js +14 -0
- package/dist/trim-trailing.js.map +1 -0
- package/dist/upload.d.ts +51 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +68 -0
- package/dist/upload.js.map +1 -0
- package/dist/vendor-face.d.ts +44 -0
- package/dist/vendor-face.d.ts.map +1 -0
- package/dist/vendor-face.js +80 -0
- package/dist/vendor-face.js.map +1 -0
- package/dist/vendor-session.d.ts +166 -0
- package/dist/vendor-session.d.ts.map +1 -0
- package/dist/vendor-session.js +423 -0
- package/dist/vendor-session.js.map +1 -0
- package/dist/vendor-surface.d.ts +290 -0
- package/dist/vendor-surface.d.ts.map +1 -0
- package/dist/vendor-surface.js +439 -0
- package/dist/vendor-surface.js.map +1 -0
- package/dist/version-rules.generated.d.ts +17 -0
- package/dist/version-rules.generated.d.ts.map +1 -0
- package/dist/version-rules.generated.js +99 -0
- package/dist/version-rules.generated.js.map +1 -0
- package/dist/view-transition-core.d.ts +99 -0
- package/dist/view-transition-core.d.ts.map +1 -0
- package/dist/view-transition-core.js +127 -0
- package/dist/view-transition-core.js.map +1 -0
- package/dist/view-transition-door.d.ts +26 -0
- package/dist/view-transition-door.d.ts.map +1 -0
- package/dist/view-transition-door.js +88 -0
- package/dist/view-transition-door.js.map +1 -0
- package/dist/window-identity.d.ts +3 -0
- package/dist/window-identity.d.ts.map +1 -0
- package/dist/window-identity.js +27 -0
- package/dist/window-identity.js.map +1 -0
- package/package.json +141 -2
package/dist/runner.js
ADDED
|
@@ -0,0 +1,4094 @@
|
|
|
1
|
+
//
|
|
2
|
+
// runner.ts - the action runner: executes `on:*` handler strings and `<action>` bodies.
|
|
3
|
+
// TS twin of JseRunner.kt in CONTRACT (statement grammar, verbs, write routing, event
|
|
4
|
+
// emission, budgets); structurally the web runner is async/await all the way down —
|
|
5
|
+
// "on web, await is a real await; same observable ordering" (/web/07).
|
|
6
|
+
//
|
|
7
|
+
// Statement grammar (the reference set):
|
|
8
|
+
// • effect verbs: `fetch: dest = METHOD url …` · `remove: arr …` · `animate: k = e`
|
|
9
|
+
// • assignment `path = expr` (dotted LHS; jsSugar rewrites `i++` / `x += e`)
|
|
10
|
+
// • dsx.module.<scheme>.<m>({…}) · dsx.action.name() · dsx.component.push/present/dismiss
|
|
11
|
+
// • dsx.event(name,{…}): the ONE emission a document has
|
|
12
|
+
// • setTimeout/setInterval(fn, ms[, key]) (interval min 250ms, keyed) · clearTimeout/Interval(key)
|
|
13
|
+
// • array mutations: path.push/pop/shift/unshift/splice/sort(…)
|
|
14
|
+
// • blocks: const/let/var · if/else · while · for / for…of · switch · try/catch/finally ·
|
|
15
|
+
// break/continue/return/throw — loop budget 100 000 per entry event
|
|
16
|
+
// • await on: fetch(…) · dsx.module.* · dsx.event(…) · Promise.* · any Promise value
|
|
17
|
+
//
|
|
18
|
+
// Not carried to web v1 (logged, never a crash): `new WebSocket` statement sockets
|
|
19
|
+
// (the WebSocket module owns sockets on web), `resolve:`/`error:` module-surface verbs.
|
|
20
|
+
//
|
|
21
|
+
var _a;
|
|
22
|
+
import { JSE, carrySlotScope, bindScopeThis, bindScopeEvent, bindScopeActionInputs, isArgumentRead, JSE_SCOPE_INPUTS, JSE_SCOPE_LOCALS, declareLocal, bindingsOf, openBlock, closeBlock, newBinding, rebind, blockNames, isLocal, localsOf, Parser, bumpNumbers, spreadValues, forInKeys, parseDeclarators, bindPattern, beginEvaluation, endEvaluation, ARRAY_MUTATORS, arrayVerb } from "./jse/jse.js";
|
|
23
|
+
import { cachedTokens, tokenize } from "./jse/tokens.js";
|
|
24
|
+
import { NSNull, isDict, isLambda, number, string, truthy, safeInt } from "./jse/values.js";
|
|
25
|
+
import { ReactiveStore, DSXState, rebuildStatePath, statePathParts, holdStore, releaseStore } from "./store.js";
|
|
26
|
+
import { ModuleRegistry, DSXEvents, ModuleCallError, ERROR_NOT_LOADED } from "./bus.js";
|
|
27
|
+
import { containsCallValue, findCallValue } from "./call-value.js";
|
|
28
|
+
import { reportLog } from "./logs.js";
|
|
29
|
+
import { STATE_APPLY_CHAIN, stateApplyMessage } from "./state-primitive.js";
|
|
30
|
+
import { carryEventMembers, elementHost } from "./element.js";
|
|
31
|
+
/** The /web/15 escalation seam. Wired by `installJsTier()` (compile/jstier.ts) rather
|
|
32
|
+
* than imported here: the runner ships in EVERY bundle (self-contained embeds included)
|
|
33
|
+
* and the classifier+executor would otherwise ride along, the byte-scarcity lesson the
|
|
34
|
+
* screen seam above already encodes. Only a full surface (the dom boot/adopt hosts)
|
|
35
|
+
* installs it; an embed keeps the pre-W9 interpreter path for every body.
|
|
36
|
+
*
|
|
37
|
+
* ONE DOOR, ONE INSTALL. `route` is the WHOLE JS tier door and lives in compile/jstier.ts:
|
|
38
|
+
* the classifier, the two refusals (compile/tier-door.ts: provenance and the ambient fence)
|
|
39
|
+
* and the executor env, in that order, answering true when the body was handled (executed,
|
|
40
|
+
* or refused TOTALLY) and false when it belongs to the interpreter. All of it arrives with
|
|
41
|
+
* one line, because all of it is consulted on one path and nowhere else. That is what makes
|
|
42
|
+
* the fence undroppable: a bundler cannot keep the tier and drop the door, and a bundle with
|
|
43
|
+
* no door does not escalate at all, which is the fail closed direction. It replaces a fence
|
|
44
|
+
* that sat in runner.ts and shipped into every embed, where no `js` verdict can ever exist.
|
|
45
|
+
*
|
|
46
|
+
* `run` is the executor the door calls, a seam of its own only so a test can observe that a
|
|
47
|
+
* refused body never reaches an engine. */
|
|
48
|
+
export const RunnerJsTierSeam = {
|
|
49
|
+
route: null,
|
|
50
|
+
run: null,
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* THE DEBUG CHOKE POINT, AND IT IS ABSENT UNLESS SOMETHING INSTALLS IT.
|
|
54
|
+
*
|
|
55
|
+
* `runStatements` offers every statement to `onStatement` and awaits what it answers, so a
|
|
56
|
+
* debugger holds a run simply by not resolving. Nothing else in the runner knows a debugger
|
|
57
|
+
* exists.
|
|
58
|
+
*
|
|
59
|
+
* WHY A SEAM RATHER THAN A FLAG. The debugger design calls this the
|
|
60
|
+
* load bearing half of the security rule: a rule enforced only by a credential check is one
|
|
61
|
+
* misconfiguration away from being off, so "a production build does not include the debug
|
|
62
|
+
* choke point at all". The development and Sandbox hosts install this; nothing else does, and
|
|
63
|
+
* a bundle where it is null has no code for a debug door to attach to. That is the refusal by
|
|
64
|
+
* absence `OpenSource/Conformance/debug/protocol.json` asserts in its production case, and it
|
|
65
|
+
* is the only enforcement that survives a bad day.
|
|
66
|
+
*/
|
|
67
|
+
export const RunnerDebugSeam = {
|
|
68
|
+
onStatement: null,
|
|
69
|
+
/** THE ACTION LOG (the live inspector, day-one Q79): every handler entry and every declared
|
|
70
|
+
* action as it starts and as it ends, with its duration and the throw that ended it. A
|
|
71
|
+
* development host installs a listener; with none this costs one null test, and a production
|
|
72
|
+
* embed folds the call sites away with the rest of this plane (`__DSX_OPTIONAL_DEBUG__`). */
|
|
73
|
+
onAction: null,
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* AND IN A PRODUCTION BUILD IT IS NOT COMPILED IN AT ALL.
|
|
77
|
+
*
|
|
78
|
+
* A null seam is absence at run time; this is absence at BUILD time, and section 5.3 of the
|
|
79
|
+
* debugger plan asks for the second one: "a production build does not include the debug choke
|
|
80
|
+
* point at all", because a rule enforced only by a field somebody could set is one assignment
|
|
81
|
+
* away from being off. An embed build pins `__DSX_OPTIONAL_DEBUG__` false
|
|
82
|
+
* (compiler/bin/embed-entry.ts, beside the link, adopt and JS tier folds) and the bundler folds
|
|
83
|
+
* this constant, the offer below, the stop it builds and the ledgers it keeps out of the graph.
|
|
84
|
+
*
|
|
85
|
+
* The G10 byte law is what made this urgent rather than merely correct: the choke point landed
|
|
86
|
+
* in every bundle including a self-contained widget, which has no debugger, no session and no
|
|
87
|
+
* door, and it put the demo embed over its gzip ceiling. A plane a widget can never reach is
|
|
88
|
+
* dead weight in a widget, which is the same argument the folds beside it already make.
|
|
89
|
+
*/
|
|
90
|
+
/** THE DEFINE IS READ AT EVERY SITE AND NEVER THROUGH A CONST. The embed slicing suite already
|
|
91
|
+
* learned this one the hard way and wrote it down: the long-press recognizer came back into
|
|
92
|
+
* every widget when its define moved from the `if` into a const read one statement earlier, so
|
|
93
|
+
* the rule is that a fold's define must be an OPERAND of the `if` it guards. This helper is
|
|
94
|
+
* inlined by hand at each of its four sites for that reason, and this comment is here so the
|
|
95
|
+
* next reader does not tidy them into one. */
|
|
96
|
+
/**
|
|
97
|
+
* The screen-readiness face of the runner — a SEAM, not an import, exactly like
|
|
98
|
+
* `RunnerFetchSeam` below. `runner.ts` ships in EVERY bundle, including a self-contained
|
|
99
|
+
* embed; a static `import { ScreenReadiness } from "./screen.ts"` therefore dragged the whole
|
|
100
|
+
* per-frame readiness machine into every embed, which has no router and no frame lifecycle at
|
|
101
|
+
* all — that cost ~230B gzip and left 3B of headroom under the hard 50176B media qualification.
|
|
102
|
+
* The dom/router host wires this in `installScreenPhase()`; an embed never calls it, so the
|
|
103
|
+
* machine stays out of its graph and `dsx.screen.settled()` is the documented silent no-op
|
|
104
|
+
* there (Article 7, fail-open).
|
|
105
|
+
*/
|
|
106
|
+
/** THE OTA ESCALATION DECISION (/web/15 law 3), as a pure function so one corpus can judge
|
|
107
|
+
* three renderers: OpenSource/Conformance/tier/ota-gate.json. May a body with this verdict,
|
|
108
|
+
* on a surface with this markup provenance, reach the JS tier? A jse-tier body is never the
|
|
109
|
+
* engine's business, so only the `js` verdict is gated. Twins: JsTierGate.admits in
|
|
110
|
+
* Engine/Swift/Tier.swift and Engine/Kotlin core Tier.kt, spelled the same way.
|
|
111
|
+
*
|
|
112
|
+
* It lives HERE, one line and no import, beside the doors table below, which is where the
|
|
113
|
+
* corpus points and which has a live producer in every bundle (dom mount.ts resolves a
|
|
114
|
+
* host's named door through it). The REFUSAL this decision feeds does not live here: it is
|
|
115
|
+
* compile/tier-door.ts, installed with the executor it guards. */
|
|
116
|
+
export function jsTierAdmits(tier, markupOverTheAir) {
|
|
117
|
+
return tier === "js" && !markupOverTheAir;
|
|
118
|
+
}
|
|
119
|
+
/** AN EMBED HAS NO JS TIER AT ALL, so it carries no consult for one. `installJsTier()` is
|
|
120
|
+
* app-boot machinery a self-contained widget never calls, which leaves the door seam above
|
|
121
|
+
* permanently null there and every rung that reads it unreachable. An embed build pins
|
|
122
|
+
* `__DSX_OPTIONAL_JS_TIER__` false (compiler/bin/embed-entry.ts, beside the link and adopt
|
|
123
|
+
* folds) and esbuild folds the two call sites out, the same way the link dispatch rungs go.
|
|
124
|
+
* Folding it cannot open the tier: with no door there is no escalation, which is the fail
|
|
125
|
+
* closed direction. Any other build leaves it unset, which reads true. */
|
|
126
|
+
function jsTierRouting() {
|
|
127
|
+
return globalThis
|
|
128
|
+
.__DSX_OPTIONAL_JS_TIER__ !== false;
|
|
129
|
+
}
|
|
130
|
+
/** THE DOORS (/web/15 law 3, corpus OpenSource/Conformance/tier/ota-gate.json `doors`).
|
|
131
|
+
*
|
|
132
|
+
* `markupOverTheAir` had a decision and a refusal on three lanes and exactly ONE producer in
|
|
133
|
+
* the whole tree: an explicit `dsx.render(xml, overTheAir:)` on iOS. Every other place markup
|
|
134
|
+
* enters a surface left the fact unset, which reads as "the binary's own markup", so the gate
|
|
135
|
+
* could not fire for anything a host actually fetched. A fact nobody stamps is not a fact, in
|
|
136
|
+
* the same way the flag this gate replaced was not a gate.
|
|
137
|
+
*
|
|
138
|
+
* So the doors are ENUMERATED, here, as a closed table: every place in this tree that admits
|
|
139
|
+
* markup into a surface, and whether markup that came through it arrived over the air. The
|
|
140
|
+
* call sites read this table by name instead of writing a bare `true` or `false`, which is
|
|
141
|
+
* what makes the inventory checkable: the corpus holds the same rows and the three lanes
|
|
142
|
+
* compare against it, so a door added in code without a row (or a row without a door) fails.
|
|
143
|
+
*
|
|
144
|
+
* AN UNKNOWN DOOR IS OVER THE AIR. `markupDoorIsOverTheAir` answers true for a name it does
|
|
145
|
+
* not hold, because the failure it guards against is a host that admits markup through a door
|
|
146
|
+
* nobody enumerated, and the safe answer to "where did this come from" is "somewhere else".
|
|
147
|
+
*
|
|
148
|
+
* WHAT IS DELIBERATELY NOT A DOOR, recorded rather than left to be rediscovered: the native
|
|
149
|
+
* ROUTE TABLE. A route row can arrive over the air (`global.routes`, or the signed bytes at
|
|
150
|
+
* `global.routesSigned`), and it was the obvious candidate. It is not one: a row names a
|
|
151
|
+
* COMPONENT, and the component's markup ships in the binary either way, so the body that runs
|
|
152
|
+
* is bundled first-party markup that a remote row merely selected. Stamping it would refuse
|
|
153
|
+
* the JS tier for every app that publishes its routes, and it would be refusing the wrong
|
|
154
|
+
* fact. The row `native/route-table` is in the table at false so that the decision is written
|
|
155
|
+
* down where the next reader of law 3 will look for it. */
|
|
156
|
+
const MARKUP_DOORS = new Map([
|
|
157
|
+
["web/bundled-registry", false],
|
|
158
|
+
["web/fetched-app-surface", true],
|
|
159
|
+
["web/uploaded-tenant-registry", true],
|
|
160
|
+
["native/bundled-component", false],
|
|
161
|
+
["native/route-table", false],
|
|
162
|
+
["native/remote-dsx-view", true],
|
|
163
|
+
]);
|
|
164
|
+
/** The door inventory, for the corpus and for a host enumerating what it may pass. */
|
|
165
|
+
export function markupDoors() { return MARKUP_DOORS; }
|
|
166
|
+
/** Did markup admitted through this door arrive over the air? Unknown door: yes. */
|
|
167
|
+
export function markupDoorIsOverTheAir(door) {
|
|
168
|
+
return MARKUP_DOORS.get(door) ?? true;
|
|
169
|
+
}
|
|
170
|
+
export const RunnerScreenSeam = {
|
|
171
|
+
settled: null,
|
|
172
|
+
};
|
|
173
|
+
// `dsx.transition(...)`: the door and its seam live in view-transition-door.ts so a
|
|
174
|
+
// self-contained embed can fold the whole plane (embed-entry.ts `viewTransitions`).
|
|
175
|
+
export { RunnerTransitionSeam } from "./view-transition-door.js";
|
|
176
|
+
import { formatLogArgs, mutateURLSearchParams } from "./jse/core.js";
|
|
177
|
+
import { transitionDoor } from "./view-transition-door.js";
|
|
178
|
+
export function makeRunEnv(store, partial) {
|
|
179
|
+
return {
|
|
180
|
+
store,
|
|
181
|
+
item: null,
|
|
182
|
+
actions: new Map(),
|
|
183
|
+
apis: new Map(),
|
|
184
|
+
emitEvent: () => { },
|
|
185
|
+
component: (verb, name) => { if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
186
|
+
console.warn(`[dsx runner] no router bound: ${verb} ${name}`); },
|
|
187
|
+
timers: new Map(),
|
|
188
|
+
actionDepth: 0,
|
|
189
|
+
loopWork: { count: 0 },
|
|
190
|
+
...partial,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const LOOP_CAP = 100_000;
|
|
194
|
+
/** The one refused-egress answer (RunEnv.egress) — a frozen literal rather than a per-call
|
|
195
|
+
* object, because this file ships in every bundle including a self-contained embed. */
|
|
196
|
+
const REFUSED_FETCH = { ok: false, status: -2, data: null, error: "invalid_request" };
|
|
197
|
+
/* EXPORTED because a second reader arrived: the devtools RUN door, which lets the editor fire a
|
|
198
|
+
* declared api as a TEST CALL. That door takes a NAME and has to answer the same question this
|
|
199
|
+
* function answers for a call expression — which declaration does `dsx.api.features` mean, and
|
|
200
|
+
* is `.cancel` the verb. Written again there it would be a second spelling table for the one
|
|
201
|
+
* grammar, and the two would drift the first time a verb moved; this way the door admits exactly
|
|
202
|
+
* what a document may write, including the refusal of every retired spelling. */
|
|
203
|
+
export function apiCallTarget(callee, apis) {
|
|
204
|
+
if (!callee.startsWith("dsx.api."))
|
|
205
|
+
return null;
|
|
206
|
+
const rest = callee.substring("dsx.api.".length);
|
|
207
|
+
const dot = rest.indexOf(".");
|
|
208
|
+
if (dot < 0) {
|
|
209
|
+
const handle = apis.get(rest);
|
|
210
|
+
return handle === undefined ? null : { handle, cancel: false };
|
|
211
|
+
}
|
|
212
|
+
if (rest.substring(dot + 1) !== "cancel")
|
|
213
|
+
return null;
|
|
214
|
+
const handle = apis.get(rest.substring(0, dot));
|
|
215
|
+
return handle === undefined ? null : { handle, cancel: true };
|
|
216
|
+
}
|
|
217
|
+
export function socketCallTarget(callee, sockets) {
|
|
218
|
+
if (sockets === undefined || !callee.startsWith("dsx.socket."))
|
|
219
|
+
return null;
|
|
220
|
+
const rest = callee.substring("dsx.socket.".length);
|
|
221
|
+
const dot = rest.indexOf(".");
|
|
222
|
+
if (dot < 0)
|
|
223
|
+
return null;
|
|
224
|
+
const verb = rest.substring(dot + 1);
|
|
225
|
+
if (verb !== "send" && verb !== "close" && verb !== "open")
|
|
226
|
+
return null;
|
|
227
|
+
const handle = sockets.get(rest.substring(0, dot));
|
|
228
|
+
return handle === undefined ? null : { handle, verb };
|
|
229
|
+
}
|
|
230
|
+
/** Run one socket verb; `send` answers the handle's `{ ok, id }`. */
|
|
231
|
+
function runSocketCall(target, args) {
|
|
232
|
+
if (target.verb === "send")
|
|
233
|
+
return target.handle.send(args[0] ?? null);
|
|
234
|
+
if (target.verb === "close")
|
|
235
|
+
target.handle.close();
|
|
236
|
+
else
|
|
237
|
+
target.handle.open();
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
/** The mutating `URLSearchParams` verbs — mutated through the owning url so href/search resync. */
|
|
241
|
+
const PARAM_VERBS = new Set(["set", "append", "delete"]);
|
|
242
|
+
/** THE EFFECT VERB ROSTER, exported because a second reader needs the SAME list.
|
|
243
|
+
* `effectVerb` below is the only thing that runs these, but the bare-reach analyser has to
|
|
244
|
+
* know a `<word>:` statement is a statement before it can judge the names inside one: it
|
|
245
|
+
* read `fetch: feed = GET https://…` as an expression and called `GET` and `https` bare
|
|
246
|
+
* reaches, suggesting `dsx.attribute.GET`. A roster copied into the compiler would go stale
|
|
247
|
+
* the first time a verb is added here, so the compiler imports this one. */
|
|
248
|
+
export const EFFECT_VERBS = new Set(["fetch", "remove", "animate", "resolve", "error"]);
|
|
249
|
+
/** AUTHORED locals in a scope (const/let declarations, for…of loop vars, catch vars) —
|
|
250
|
+
* the ONLY names an assignment may write in-scope. Every other write routes to the
|
|
251
|
+
* owning store (the reference store-always contract, actions corpus), so an entry-
|
|
252
|
+
* payload key riding dsx.this can never shadow a store write the way a plain
|
|
253
|
+
* hasOwnProperty check let it. Non-enumerable, so scope spreads don't carry it. */
|
|
254
|
+
// The ledger MOVED TO THE EVALUATOR (S3 cut, jse.ts `JSE_SCOPE_LOCALS`): `lookup` is what
|
|
255
|
+
// answers a bare identifier, so `lookup` is what has to know which names the block declared.
|
|
256
|
+
// It is the same ledger, the same symbol and the same two helpers; the runner declares into
|
|
257
|
+
// it at every binder exactly as before, and reads it here for the write routing below.
|
|
258
|
+
/**
|
|
259
|
+
* THE LEDGER, READ FROM OUTSIDE. The authored local names in a scope, sorted.
|
|
260
|
+
*
|
|
261
|
+
* The ledger's WRITER stays with the binders and must: a writer handed out here would let something
|
|
262
|
+
* other than the runner decide what an assignment may write in-scope, which is the one thing
|
|
263
|
+
* the ledger exists to decide. A READER is a different fact, and a debugger needs it:
|
|
264
|
+
* `OpenSource/Conformance/debug/frames.json` reports "the locals as their own member",
|
|
265
|
+
* separate from the store, and its `_locals_are_not_store` note gives the reason - a bare name
|
|
266
|
+
* could be either, and reporting them in one bag teaches the confusion the ledger removes.
|
|
267
|
+
*/
|
|
268
|
+
export function scopeLocalNames(scope) {
|
|
269
|
+
const set = localsOf(scope);
|
|
270
|
+
return set === undefined ? [] : [...set].sort();
|
|
271
|
+
}
|
|
272
|
+
/** The same ledger with each name's current value. A name declared but not yet assigned is a
|
|
273
|
+
* name with no value rather than a missing name, so the caller can tell the two apart. */
|
|
274
|
+
export function scopeLocals(scope) {
|
|
275
|
+
const out = {};
|
|
276
|
+
for (const name of scopeLocalNames(scope)) {
|
|
277
|
+
if (Object.prototype.hasOwnProperty.call(scope, name))
|
|
278
|
+
out[name] = scope[name];
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
/** Route a write to its owning store (the reference `write`). Bare single-segment
|
|
283
|
+
* names that are AUTHORED locals in `scope` write the scope (loop counters, awaited
|
|
284
|
+
* consts); names that merely EXIST in scope (item fields, the entry payload) write
|
|
285
|
+
* the store — the store-always reference behavior. */
|
|
286
|
+
export function writePath(env, scope, rawPath, value) {
|
|
287
|
+
const authoredParts = statePathParts(rawPath);
|
|
288
|
+
if (authoredParts === null)
|
|
289
|
+
return;
|
|
290
|
+
const first = authoredParts[0];
|
|
291
|
+
if (!rawPath.startsWith("dsx.") && isLocal(scope, first) && Object.prototype.hasOwnProperty.call(scope, first)) {
|
|
292
|
+
if (rawPath.includes(".")) {
|
|
293
|
+
// dotted write into a local: read-modify-write the local container
|
|
294
|
+
const rebuilt = rebuildStatePath(scope[first], authoredParts.slice(1), value);
|
|
295
|
+
if (rebuilt.accepted)
|
|
296
|
+
scope[first] = rebuilt.value;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
scope[rawPath] = value ?? NSNull;
|
|
300
|
+
}
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
// A WRITE IS A REACH TOO (S3 cut). `count = count + 1` with a retired bare read on the
|
|
304
|
+
// right and a bare write on the left is not one rule, and a bare write to a name nothing
|
|
305
|
+
// declares MINTS a surface store key silently - the shadow hazard this cut exists to
|
|
306
|
+
// remove, arriving through the one door the read side no longer has. `dsx.variable.count`
|
|
307
|
+
// is the spelling and it routes exactly as it did; a bare head that the block did not
|
|
308
|
+
// declare is refused with a word, never a write.
|
|
309
|
+
if (!rawPath.startsWith("dsx.")) {
|
|
310
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
311
|
+
console.warn(`[dsx runner] bare write: spell dsx.variable.${first}`);
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (/^dsx\.action\.[\w$]+\.pending$/.test(rawPath)) {
|
|
315
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
316
|
+
console.warn(`[dsx runner] action pending is read-only: ${rawPath}`);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// A MEMBER OF AN ELEMENT HANDLE (`dsx.ref.card.className = 'x'`, `dsx.this.target.dataset.state = 'on'`,
|
|
320
|
+
// ADR 0025 D4) is assigned through the handle, which writes the element's attribute store; it is not a
|
|
321
|
+
// state path. Only a path whose head can hold a handle is looked at, and only when its base is one.
|
|
322
|
+
if (rawPath.startsWith("dsx.ref.") || rawPath.startsWith("dsx.this.")) {
|
|
323
|
+
const dot = rawPath.lastIndexOf(".");
|
|
324
|
+
const host = elementHost(JSE.lookup(rawPath.substring(0, dot), env.store.jse, scope));
|
|
325
|
+
if (host !== null) {
|
|
326
|
+
if (!host.set(rawPath.substring(dot + 1), value) && globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false) {
|
|
327
|
+
console.warn(`[dsx runner] ${rawPath}: not a writable member of an element handle`);
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
const path = JSE.normalizeScope(rawPath);
|
|
333
|
+
// THE NAMESPACE IS CLOSED on the write side too: `dsx.<unknown>` normalizes to no path, and
|
|
334
|
+
// a write with no path is refused rather than minting a nameless surface key. A read of the
|
|
335
|
+
// same spelling answers the typed absence; the linter names it before the build.
|
|
336
|
+
if (path === "") {
|
|
337
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
338
|
+
console.warn(`[dsx runner] unknown dsx plane: ${rawPath}`);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (path.startsWith("global.")) {
|
|
342
|
+
DSXState.set(path.substring(7), value);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (path === "global") {
|
|
346
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
347
|
+
console.warn("[dsx runner] cannot replace the whole global store");
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (path.startsWith("route.") || path === "route") {
|
|
351
|
+
DSXState.set(path, value);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (path.startsWith("cookie.")) {
|
|
355
|
+
env.cookieSet?.(path.substring(7), value);
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
// CONTEXT IS READ-ONLY (PROPOSED, proposals/context.md decision 5). Ownership stays with
|
|
359
|
+
// the provider and a component boundary cannot forward a two-way binding, so a descendant
|
|
360
|
+
// changes shared state by calling the owner's <action>. The refusal has to be HERE and not
|
|
361
|
+
// only in the linter: `normalizeScope` folds the plane, so without this arm the write falls
|
|
362
|
+
// through to `setPath` and mints a surface variable literally named `context.x` on the
|
|
363
|
+
// CONSUMER - a write that succeeds, changes nothing, and is visible nowhere.
|
|
364
|
+
if (path === "context" || path.startsWith("context.")) {
|
|
365
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
366
|
+
console.warn(`[dsx runner] dsx.context is read-only: ${rawPath} — expose an <action> on the provider and call it`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
// A ROW FIELD WRITES BACK. `dsx.this.qty = v` (and `dsx.this.parent.stage = v`) in a handler
|
|
370
|
+
// inside a bound row lands on that row of the bound array, the write a control bound to the
|
|
371
|
+
// same field makes; outside a row, or over a list with no plain path, the write has no row to
|
|
372
|
+
// land on and is refused by name rather than minting a surface key called `item`.
|
|
373
|
+
if (path.startsWith("item.")) {
|
|
374
|
+
// A row writer exists only inside a bound collection row (dom mount.ts), so a slice with none
|
|
375
|
+
// (`__DSX_OPTIONAL_BOUND_COLLECTIONS__`) can only refuse.
|
|
376
|
+
const writer = globalThis.__DSX_OPTIONAL_BOUND_COLLECTIONS__ !== false
|
|
377
|
+
? scope[ROW_WRITER] : undefined;
|
|
378
|
+
if (typeof writer === "function" && writer(path.substring(5).split("."), value))
|
|
379
|
+
return;
|
|
380
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
381
|
+
console.warn(`[dsx runner] ${rawPath}: no bound row to write back to`);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
env.store.setPath(path, value);
|
|
385
|
+
}
|
|
386
|
+
/** The row writer a surface hands a handler run inside a bound row (dom mount.ts runHandler):
|
|
387
|
+
* `(fieldPath, value) => written`. A registered symbol, so it survives the scope's spreads. */
|
|
388
|
+
export const ROW_WRITER = Symbol.for("dsx.rowWriter");
|
|
389
|
+
export function readPath(env, scope, rawPath) {
|
|
390
|
+
return JSE.lookup(rawPath, env.store.jse, scope);
|
|
391
|
+
}
|
|
392
|
+
/** Stamp the emitter's identity onto an event payload as `__from = { type, name }`, so a
|
|
393
|
+
* consumer's `from:<type>` / `from:<type>.<name>` filter can say WHICH source it accepts.
|
|
394
|
+
* The reference is Stack.swift's `stampFrom` and JseRunner.kt's twin, byte for byte in
|
|
395
|
+
* behaviour: nothing is stamped without a name, and a `__from` the author wrote at the call
|
|
396
|
+
* site is never overwritten, so an unfiltered `dsx.event('x')` is unchanged. */
|
|
397
|
+
export function stampFrom(payload, type, name) {
|
|
398
|
+
if (name === undefined || name === "" || payload["__from"] !== undefined)
|
|
399
|
+
return payload;
|
|
400
|
+
return { ...payload, __from: { type, name } };
|
|
401
|
+
}
|
|
402
|
+
/** Whether a consumer's `from:<event>` filter accepts `payload` (reference/events.md, "Filtering by emitter"). The
|
|
403
|
+
* reference is Stack.swift's `OnHandler.accepts` and JseRunner.kt's twin: no filter accepts everything; a set filter
|
|
404
|
+
* rejects a payload with no `__from`; `action=` / `component=` match the stamp's type and name, a bare value its name. */
|
|
405
|
+
export function acceptsFrom(filter, payload) {
|
|
406
|
+
// BLOCK-FORM FOLD (`__DSX_OPTIONAL_FROM_FILTER__`, cli embed/entry.ts registryUsesFromFilter): the renderer hands a
|
|
407
|
+
// filter only from a `from:<event>` attribute the markup writes, so a slice that writes none always passes `undefined`,
|
|
408
|
+
// whose answer is the `true` below.
|
|
409
|
+
if (globalThis.__DSX_OPTIONAL_FROM_FILTER__ === false)
|
|
410
|
+
return true;
|
|
411
|
+
const raw = (filter ?? "").trim();
|
|
412
|
+
if (raw === "")
|
|
413
|
+
return true;
|
|
414
|
+
let type = "";
|
|
415
|
+
let name = raw;
|
|
416
|
+
const eq = raw.indexOf("=");
|
|
417
|
+
if (eq >= 0) {
|
|
418
|
+
const t = raw.slice(0, eq).trim();
|
|
419
|
+
if (t === "action" || t === "component") {
|
|
420
|
+
type = t;
|
|
421
|
+
name = raw.slice(eq + 1).trim();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const src = payload["__from"];
|
|
425
|
+
if (src === null || typeof src !== "object" || Array.isArray(src))
|
|
426
|
+
return false;
|
|
427
|
+
const stamp = src;
|
|
428
|
+
if (string(stamp["name"] ?? "") !== name)
|
|
429
|
+
return false;
|
|
430
|
+
return type === "" || string(stamp["type"] ?? "") === type;
|
|
431
|
+
}
|
|
432
|
+
// ── token utilities ──────────────────────────────────────────────────────────────────
|
|
433
|
+
function isOpTok(t, v) { return !!t && t.kind === "op" && t.v === v; }
|
|
434
|
+
function isIdentTok(t, v) {
|
|
435
|
+
return !!t && t.kind === "ident" && (v === undefined || t.v === v);
|
|
436
|
+
}
|
|
437
|
+
/** `i++` / `i--` / `++i` / `--i` → `x = +x ± 1` (counted as a number, JSE-VS-JS item 11:
|
|
438
|
+
* '5' is 5, null is 0) · `x += e` (and -=, *=, /=, %=, **=) → `x = x op (e)` —
|
|
439
|
+
* the jsSugar rewrite. The lexer emits `++` / `+=` / `**=` as single op tokens
|
|
440
|
+
* (syntax wave 1; the prefix forms are wave 3). */
|
|
441
|
+
/** A WRITE TARGET WITH MORE THAN ONE INDEX, OR AN INDEX FOLLOWED BY A MEMBER
|
|
442
|
+
* (`list[i].n = v`, `grid[r][c] = v`, `rows[0].tags[1] += 'x'`, `xs[i].n++`), as the ONE dotted
|
|
443
|
+
* path the statement writers already read and write (`list.1.n`): each index evaluates once,
|
|
444
|
+
* in order, before the right-hand side. Only `name[expr] = rhs` was a write; every longer target
|
|
445
|
+
* fell through to "an expression", so the statement ran and wrote NOTHING, on a local and on the
|
|
446
|
+
* store alike (logic parity sweep 6, actions corpus `a-nested-index-*`; JavaScript writes). A
|
|
447
|
+
* text index holding a `.` cannot be one dotted segment, so that target is left as it was.
|
|
448
|
+
* Twins: JseRunner.kt and Stack.swift `flattenTarget`. */
|
|
449
|
+
function flattenTarget(toks, evalIndex) {
|
|
450
|
+
if (toks.length < 5 || toks[0].kind !== "ident" || !isOpTok(toks[1], "["))
|
|
451
|
+
return toks;
|
|
452
|
+
// The SHAPE first, with nothing evaluated: an index expression may have effects
|
|
453
|
+
// (`m[a.pop()] = …`), and a target this does not rewrite is evaluated by its own branch.
|
|
454
|
+
const parts = [];
|
|
455
|
+
let i = 1;
|
|
456
|
+
for (;;) {
|
|
457
|
+
const t = toks[i];
|
|
458
|
+
if (isOpTok(t, "[")) {
|
|
459
|
+
let d = 0;
|
|
460
|
+
let close = -1;
|
|
461
|
+
for (let j = i; j < toks.length; j++) {
|
|
462
|
+
const u = toks[j];
|
|
463
|
+
if (u.kind === "op" && (u.v === "[" || u.v === "(" || u.v === "{"))
|
|
464
|
+
d += 1;
|
|
465
|
+
else if (u.kind === "op" && (u.v === "]" || u.v === ")" || u.v === "}")) {
|
|
466
|
+
d -= 1;
|
|
467
|
+
if (d === 0) {
|
|
468
|
+
close = j;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
if (close < 0)
|
|
474
|
+
return toks;
|
|
475
|
+
parts.push({ index: [i + 1, close] });
|
|
476
|
+
i = close + 1;
|
|
477
|
+
}
|
|
478
|
+
else if (isOpTok(t, ".") && toks[i + 1]?.kind === "ident") {
|
|
479
|
+
parts.push({ member: toks[i + 1].v });
|
|
480
|
+
i += 2;
|
|
481
|
+
}
|
|
482
|
+
else
|
|
483
|
+
break;
|
|
484
|
+
}
|
|
485
|
+
const op = toks[i];
|
|
486
|
+
if (op === undefined || op.kind !== "op")
|
|
487
|
+
return toks;
|
|
488
|
+
const assigns = ["=", "+=", "-=", "*=", "/=", "%=", "**="].includes(op.v)
|
|
489
|
+
|| ((op.v === "++" || op.v === "--") && i === toks.length - 1)
|
|
490
|
+
|| (["??", "&&", "||"].includes(op.v) && isOpTok(toks[i + 1], "="));
|
|
491
|
+
// One index then `=` is the existing single-level write; leave it on its own branch.
|
|
492
|
+
if (!assigns || (parts.length === 1 && op.v === "="))
|
|
493
|
+
return toks;
|
|
494
|
+
// Now each index evaluates once, in order, before the right-hand side.
|
|
495
|
+
let path = toks[0].v;
|
|
496
|
+
for (const part of parts) {
|
|
497
|
+
if ("member" in part) {
|
|
498
|
+
path += "." + part.member;
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const idx = evalIndex(toks.slice(part.index[0], part.index[1]));
|
|
502
|
+
const n = number(idx);
|
|
503
|
+
const seg = n !== null && Number.isFinite(n) && Math.trunc(n) === n ? String(safeInt(n)) : string(idx);
|
|
504
|
+
if (seg.length === 0)
|
|
505
|
+
return [];
|
|
506
|
+
// A TEXT INDEX HOLDING A `.` IS ONE PROPERTY NAME (JavaScript): as the last index of a plain
|
|
507
|
+
// write it becomes the one-index write below, which sets that one key; deeper it stays unwritten.
|
|
508
|
+
if (seg.includes(".")) {
|
|
509
|
+
if (part !== parts[parts.length - 1] || op.v !== "=")
|
|
510
|
+
return [];
|
|
511
|
+
return [{ kind: "ident", v: path }, { kind: "op", v: "[" }, { kind: "str", v: seg },
|
|
512
|
+
{ kind: "op", v: "]" }, ...toks.slice(i)];
|
|
513
|
+
}
|
|
514
|
+
path += "." + seg;
|
|
515
|
+
}
|
|
516
|
+
return [{ kind: "ident", v: path }, ...toks.slice(i)];
|
|
517
|
+
}
|
|
518
|
+
/** `container[key] = value` for a key holding a `.`: one property of the container, never a path. */
|
|
519
|
+
function writeKey(env, scope, container, key, value) {
|
|
520
|
+
const current = readPath(env, scope, container);
|
|
521
|
+
if (Array.isArray(current))
|
|
522
|
+
return;
|
|
523
|
+
writePath(env, scope, container, { ...(isDict(current) ? current : {}), [key]: value });
|
|
524
|
+
}
|
|
525
|
+
function jsSugar(toks) {
|
|
526
|
+
// prefix `++i` / `--i` — the same statement rewrite as the postfix form
|
|
527
|
+
if (toks.length === 2 && toks[0].kind === "op" && (toks[0].v === "++" || toks[0].v === "--") &&
|
|
528
|
+
toks[1].kind === "ident") {
|
|
529
|
+
return [toks[1], { kind: "op", v: "=" }, { kind: "op", v: "+" }, toks[1], { kind: "op", v: toks[0].v[0] }, { kind: "num", v: 1 }];
|
|
530
|
+
}
|
|
531
|
+
if (toks.length >= 2 && toks[0].kind === "ident") {
|
|
532
|
+
const t1 = toks[1];
|
|
533
|
+
if (toks.length === 2 && t1.kind === "op" && (t1.v === "++" || t1.v === "--")) {
|
|
534
|
+
return [toks[0], { kind: "op", v: "=" }, { kind: "op", v: "+" }, toks[0], { kind: "op", v: t1.v[0] }, { kind: "num", v: 1 }];
|
|
535
|
+
}
|
|
536
|
+
if (t1.kind === "op" && ["+=", "-=", "*=", "/=", "%=", "**="].includes(t1.v)) {
|
|
537
|
+
return [
|
|
538
|
+
toks[0], { kind: "op", v: "=" }, toks[0], { kind: "op", v: t1.v.slice(0, -1) },
|
|
539
|
+
{ kind: "op", v: "(" }, ...toks.slice(2), { kind: "op", v: ")" },
|
|
540
|
+
];
|
|
541
|
+
}
|
|
542
|
+
// logical assigns `x ??= e` / `x &&= e` / `x ||= e` — the op lexes as [??][=]
|
|
543
|
+
const t2 = toks.length >= 3 ? toks[2] : null;
|
|
544
|
+
if (t1.kind === "op" && ["??", "&&", "||"].includes(t1.v) && t2 !== null && t2.kind === "op" && t2.v === "=") {
|
|
545
|
+
return [
|
|
546
|
+
toks[0], { kind: "op", v: "=" }, toks[0], { kind: "op", v: t1.v },
|
|
547
|
+
{ kind: "op", v: "(" }, ...toks.slice(3), { kind: "op", v: ")" },
|
|
548
|
+
];
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return toks;
|
|
552
|
+
}
|
|
553
|
+
/** A `fetch:` URL span written BARE (no quotes): `https://…` / `api.example.com/…` —
|
|
554
|
+
* evaluating it as an expression yields "" (the idents aren't scope names). */
|
|
555
|
+
function looksLikeBareUrl(toks) {
|
|
556
|
+
if (toks.length < 2 || toks[0].kind !== "ident")
|
|
557
|
+
return false;
|
|
558
|
+
const head = toks[0];
|
|
559
|
+
if ((head.v === "https" || head.v === "http") && isOpTok(toks[1], ":"))
|
|
560
|
+
return true;
|
|
561
|
+
return head.v.includes(".") && isOpTok(toks[1], "/");
|
|
562
|
+
}
|
|
563
|
+
/** Reassemble the bare URL from its token source forms, verbatim, no spaces. A path
|
|
564
|
+
* segment can lex as a REGEX token (`//host/path/` — `/` in prefix position); its
|
|
565
|
+
* source form is `/pattern/flags`. */
|
|
566
|
+
function rebuildBareUrl(toks) {
|
|
567
|
+
let out = "";
|
|
568
|
+
for (const t of toks) {
|
|
569
|
+
if (t.kind === "ident" || t.kind === "op")
|
|
570
|
+
out += t.v;
|
|
571
|
+
else if (t.kind === "num")
|
|
572
|
+
out += string(t.v);
|
|
573
|
+
else if (t.kind === "str")
|
|
574
|
+
out += t.v;
|
|
575
|
+
else if (t.kind === "regex")
|
|
576
|
+
out += "/" + t.pattern + "/" + t.flags;
|
|
577
|
+
}
|
|
578
|
+
return out;
|
|
579
|
+
}
|
|
580
|
+
const activeHolds = new Set();
|
|
581
|
+
let holdBackstopQueued = false;
|
|
582
|
+
function holdBackstop() {
|
|
583
|
+
holdBackstopQueued = false;
|
|
584
|
+
for (const h of [...activeHolds])
|
|
585
|
+
letGo(h);
|
|
586
|
+
}
|
|
587
|
+
function takeHold(h) {
|
|
588
|
+
if (h === null || !h.live || h.active)
|
|
589
|
+
return;
|
|
590
|
+
h.active = true;
|
|
591
|
+
activeHolds.add(h);
|
|
592
|
+
holdStore(h.store);
|
|
593
|
+
if (!holdBackstopQueued) {
|
|
594
|
+
holdBackstopQueued = true;
|
|
595
|
+
setTimeout(holdBackstop, 0);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function letGo(h) {
|
|
599
|
+
if (h === null || !h.active)
|
|
600
|
+
return;
|
|
601
|
+
h.active = false;
|
|
602
|
+
activeHolds.delete(h);
|
|
603
|
+
releaseStore(h.store);
|
|
604
|
+
}
|
|
605
|
+
/** the hold of the entry each runner is executing (Law 1, above); absent between entries */
|
|
606
|
+
const runnerHolds = new WeakMap();
|
|
607
|
+
/** How many of a runner's entries are suspended on something outside the document right now (a module
|
|
608
|
+
* call, a fetch, `dsx.wait`). A new entry does not queue behind those (runExclusive). */
|
|
609
|
+
const runnerIoWaits = new WeakMap();
|
|
610
|
+
const runnerBatons = new WeakMap();
|
|
611
|
+
function batonOf(r) {
|
|
612
|
+
let b = runnerBatons.get(r);
|
|
613
|
+
if (b === undefined) {
|
|
614
|
+
b = { owner: null, queue: [] };
|
|
615
|
+
runnerBatons.set(r, b);
|
|
616
|
+
}
|
|
617
|
+
return b;
|
|
618
|
+
}
|
|
619
|
+
/** null when the baton was free or already this entry's and is now taken; otherwise the wait for it. */
|
|
620
|
+
function takeBaton(r, entry, boundMs) {
|
|
621
|
+
const b = batonOf(r);
|
|
622
|
+
if (b.owner === null || b.owner === entry) {
|
|
623
|
+
b.owner = entry;
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
return new Promise((resolve) => {
|
|
627
|
+
const enter = () => {
|
|
628
|
+
clearTimeout(timer);
|
|
629
|
+
const at = b.queue.indexOf(enter);
|
|
630
|
+
if (at >= 0)
|
|
631
|
+
b.queue.splice(at, 1);
|
|
632
|
+
b.owner = entry;
|
|
633
|
+
resolve();
|
|
634
|
+
// the entry holds the baton now, so its other strands waiting in the queue (reads started together under
|
|
635
|
+
// Promise.all whose answers came while another entry held it) hold it too: left queued, each waited out the bound
|
|
636
|
+
b.queue.find((waiter) => batonWaiters.get(waiter) === entry)?.();
|
|
637
|
+
};
|
|
638
|
+
const timer = setTimeout(enter, boundMs);
|
|
639
|
+
batonWaiters.set(enter, entry);
|
|
640
|
+
b.queue.push(enter);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
/** Which entry each queued baton waiter resumes. */
|
|
644
|
+
const batonWaiters = new WeakMap();
|
|
645
|
+
function giveBaton(r, entry) {
|
|
646
|
+
const b = batonOf(r);
|
|
647
|
+
if (b.owner !== entry)
|
|
648
|
+
return;
|
|
649
|
+
b.owner = null;
|
|
650
|
+
b.queue[0]?.();
|
|
651
|
+
}
|
|
652
|
+
/** One strand of `entry` stops running (it waits, or it ended); the last one gives the baton up. */
|
|
653
|
+
function strandStops(r, entry) {
|
|
654
|
+
entry.running = Math.max(0, entry.running - 1);
|
|
655
|
+
if (entry.running !== 0)
|
|
656
|
+
return;
|
|
657
|
+
const handBack = entry.handBack;
|
|
658
|
+
if (handBack === undefined) {
|
|
659
|
+
giveBaton(r, entry);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
entry.handBack = undefined;
|
|
663
|
+
batonOf(r).owner = entry.caller ?? null;
|
|
664
|
+
handBack();
|
|
665
|
+
}
|
|
666
|
+
/** THE TIMERS OF A PAGE OUT OF VIEW. A page the router has taken out of the document (a parked tab page, a covered
|
|
667
|
+
* page of the back stack) keeps its state but does no timer work: while its frame is held, every `setTimeout` /
|
|
668
|
+
* `setInterval` tick of an instance mounted in that frame is kept (one per timer) instead of run, and the kept
|
|
669
|
+
* ticks run once, in order, when the frame is released. The router holds and releases; DOM-free like the rest. */
|
|
670
|
+
export const FrameTimers = {
|
|
671
|
+
held: new Map(),
|
|
672
|
+
hold(frame) { if (!this.held.has(frame))
|
|
673
|
+
this.held.set(frame, new Map()); },
|
|
674
|
+
/** Keep `tick` for later when `frame` is held; false when the frame is live and the tick should run now. */
|
|
675
|
+
defer(frame, id, tick) {
|
|
676
|
+
const kept = this.held.get(frame);
|
|
677
|
+
if (kept === undefined)
|
|
678
|
+
return false;
|
|
679
|
+
kept.set(id, tick);
|
|
680
|
+
return true;
|
|
681
|
+
},
|
|
682
|
+
release(frame) {
|
|
683
|
+
const kept = this.held.get(frame);
|
|
684
|
+
this.held.delete(frame);
|
|
685
|
+
for (const tick of kept?.values() ?? [])
|
|
686
|
+
tick();
|
|
687
|
+
},
|
|
688
|
+
/** The frame left for good: drop its kept ticks without running them. */
|
|
689
|
+
drop(frame) { this.held.delete(frame); },
|
|
690
|
+
};
|
|
691
|
+
export class ActionRunner {
|
|
692
|
+
env;
|
|
693
|
+
constructor(env) {
|
|
694
|
+
this.env = env;
|
|
695
|
+
}
|
|
696
|
+
/** Entry: run an `on:*` handler string or an `<action>` body. A fresh entry event
|
|
697
|
+
* (depth 0) resets the bounded-execution ledgers and any stray flow signal; the
|
|
698
|
+
* 32-frame recursion cap is owned by callAction (the action-call frame), matching
|
|
699
|
+
* the JseRunner contract exactly. */
|
|
700
|
+
async run(action, item = null, args = {}) {
|
|
701
|
+
if (!JSE.validSyntax(action))
|
|
702
|
+
return;
|
|
703
|
+
const body = action.trim();
|
|
704
|
+
if (body.length === 0)
|
|
705
|
+
return;
|
|
706
|
+
this.#entryBody = body; // uncaught-throw context (reportUncaught's `snippet`)
|
|
707
|
+
if (globalThis
|
|
708
|
+
.__DSX_OPTIONAL_DEBUG__ !== false) {
|
|
709
|
+
this.debugStops = 0;
|
|
710
|
+
RunnerDebugSeam.onAction?.({ kind: "handler", name: body, phase: "start", store: this.env.store });
|
|
711
|
+
}
|
|
712
|
+
const began = Date.now();
|
|
713
|
+
try {
|
|
714
|
+
await this.#runExclusive(async () => {
|
|
715
|
+
// `on:tap="save"` IS RETIRED (S3 cut). A handler string that was only a name ran the
|
|
716
|
+
// declared action; after the cut a handler is an expression like every other JSE site
|
|
717
|
+
// and the call is spelled `dsx.action.save()`. A bare name is an identifier nothing
|
|
718
|
+
// binds, so the body below evaluates it to null and nothing runs, which is the answer
|
|
719
|
+
// the `bare-reach` lint names before the build.
|
|
720
|
+
const scope = { ...(this.env.item ?? {}), ...(item ?? {}), ...args };
|
|
721
|
+
carrySlotScope(scope, this.env.item, item);
|
|
722
|
+
carryEventMembers(scope, item);
|
|
723
|
+
// /web/15: an action-tier body beyond the JSE subset ESCALATES — ordinary JS in
|
|
724
|
+
// the /web/12 sandbox — instead of lossy-compiling into wrong behavior.
|
|
725
|
+
if (jsTierRouting()) {
|
|
726
|
+
const route = RunnerJsTierSeam.route;
|
|
727
|
+
if (route !== null && await route(this, body, scope))
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const walker = new StmtWalker(cachedTokens(body));
|
|
731
|
+
await this.runStatements(walker, scope, true);
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
finally {
|
|
735
|
+
if (globalThis
|
|
736
|
+
.__DSX_OPTIONAL_DEBUG__ !== false)
|
|
737
|
+
RunnerDebugSeam.onAction?.({ kind: "handler", name: body, phase: "end", ms: Date.now() - began, store: this.env.store });
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
/** ONE PIECE OF A LOAD THE SERVER PHASE SPLIT (phase-plan.ts): `locals` are the top-level locals the earlier piece
|
|
741
|
+
* declared, declared again before `body` runs; the answer says how the piece ended and the top-level locals it holds
|
|
742
|
+
* now, so the next piece (on the server, or the client's remainder) reads the same values. */
|
|
743
|
+
async runPhase(body, item, args, locals = {}) {
|
|
744
|
+
let ended = "done";
|
|
745
|
+
let held = { ...locals };
|
|
746
|
+
// BLOCK-FORM FOLD (`__DSX_OPTIONAL_ADOPT__`): the one caller, dom mount.ts phaseRun, reads a server phase ledger
|
|
747
|
+
// only while adopting a server page, under the same flag; a self-contained embed adopts none. Block form, so the
|
|
748
|
+
// body's references leave the bundle with it (an early return kept them: esbuild keeps every class member).
|
|
749
|
+
if (globalThis.__DSX_OPTIONAL_ADOPT__ !== false) {
|
|
750
|
+
const source = body.trim();
|
|
751
|
+
if (source.length > 0) {
|
|
752
|
+
this.#entryBody = source;
|
|
753
|
+
await this.#runExclusive(async () => {
|
|
754
|
+
const scope = { ...(this.env.item ?? {}), ...(item ?? {}), ...args };
|
|
755
|
+
carrySlotScope(scope, this.env.item, item);
|
|
756
|
+
for (const [name, value] of Object.entries(locals)) {
|
|
757
|
+
scope[name] = value;
|
|
758
|
+
declareLocal(scope, name);
|
|
759
|
+
}
|
|
760
|
+
await this.runStatements(new StmtWalker(cachedTokens(source)), scope, true);
|
|
761
|
+
const flow = this.flow;
|
|
762
|
+
ended = flow === null ? "done" : flow.kind === "throw" ? "throw" : "return";
|
|
763
|
+
held = scopeLocals(scope);
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return { ended, locals: held };
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Read and CLEAR a pending throw — the server's half of an action call
|
|
771
|
+
* (backend-authoring.md; `@despia-native/server` shapes the outcome, this only hands over the signal).
|
|
772
|
+
*
|
|
773
|
+
* A surface entry is fire-and-forget: a tap has no caller waiting, so `run()` reports an
|
|
774
|
+
* uncaught throw to the ledger and swallows it. A request has a caller, and the throw IS the
|
|
775
|
+
* answer — a deliberate `throw { code: 'invalid_request' }` is a 400, not a server fault, and must
|
|
776
|
+
* not be filed as an unobserved runtime error. Kept to four lines on purpose: this method
|
|
777
|
+
* ships in every bundle including a self-contained embed, so the outcome shaping lives in the
|
|
778
|
+
* server package where no embed can pay for it.
|
|
779
|
+
*/
|
|
780
|
+
/** Record a value thrown out of the JS TIER executor as this runner's flow signal, so a
|
|
781
|
+
* caller's try/catch and the uncaught fan-out behave identically across tiers. The
|
|
782
|
+
* executor's env is built in compile/jstier.ts, which ships only where the tier does. */
|
|
783
|
+
recordThrow(e) {
|
|
784
|
+
// MEMBER FOLD, the stopgap store.ts canHoldCall names (Article 17.4, EMBED-MEMBER-FOLDS-STOPGAP-1120): the one caller is the JS tier's executor
|
|
785
|
+
// (compile/jstier.ts), which ships only under `__DSX_OPTIONAL_JS_TIER__`.
|
|
786
|
+
if (globalThis.__DSX_OPTIONAL_JS_TIER__ !== false) {
|
|
787
|
+
this.flow = { kind: "throw", value: e instanceof Error ? { message: e.message } : e };
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
takeThrow() {
|
|
791
|
+
const flow = this.#currentFlow();
|
|
792
|
+
if (flow === null || flow.kind !== "throw")
|
|
793
|
+
return null;
|
|
794
|
+
this.flow = null;
|
|
795
|
+
return { value: flow.value };
|
|
796
|
+
}
|
|
797
|
+
/** the tail of the in-flight top-level entry (an async mutex — see runExclusive) */
|
|
798
|
+
#entryLock = Promise.resolve();
|
|
799
|
+
/** How long a NEW entry waits for the in-flight one before proceeding anyway (ms).
|
|
800
|
+
* The exclusivity below exists to protect the per-entry ledgers while a body is
|
|
801
|
+
* suspended at an `await` — but an entry whose awaited module call NEVER settles
|
|
802
|
+
* (a clipboard read hanging on permission, an interactive paywall held open) must
|
|
803
|
+
* not freeze every later tap on the surface forever: bounded execution is the JSE
|
|
804
|
+
* law, and the iOS runner (the reference) interleaves entries freely at suspension
|
|
805
|
+
* points. Interleaving is ledger-safe there by construction — at any suspension
|
|
806
|
+
* point the flow signal is null (signals unwind synchronously) and a reset loop
|
|
807
|
+
* budget only ever REFRESHES the suspended entry's allowance — so proceeding after
|
|
808
|
+
* a bounded wait trades a theoretical budget refresh for never bricking the page. */
|
|
809
|
+
static ENTRY_LOCK_BOUND_MS = 1500;
|
|
810
|
+
// THE AWAITABLE DELAY'S CEILING (Appendix E item 7). `await dsx.wait(ms)` suspends the
|
|
811
|
+
// body that asked for it while holding that body's entry lock, so an unbounded argument is
|
|
812
|
+
// a surface that never answers again. Thirty seconds is far past any animation or poll
|
|
813
|
+
// interval an author writes and far short of a hang a person would report as one. The same
|
|
814
|
+
// constant is spelled on all three runners (Stack.swift, JseRunner.kt).
|
|
815
|
+
static WAIT_BOUND_MS = 30_000;
|
|
816
|
+
/** Run a top-level entry (an `on:*` handler, an `<action>` body, or a fired timer lambda)
|
|
817
|
+
* with EXCLUSIVE access to this runner's per-entry ledgers — the flow signal, the loop
|
|
818
|
+
* budget (`loopWork`), and the action-recursion depth. ONE ActionRunner is shared across
|
|
819
|
+
* all of a component's handlers, and those ledgers are mutable instance/env state; because
|
|
820
|
+
* the web runner awaits mid-body, a second entry that started while another was suspended
|
|
821
|
+
* at an `await` would reset them under the suspended one (its loop budget zeroed, its flow
|
|
822
|
+
* cleared). Chaining on `entryLock` keeps entries one-at-a-time whenever they finish
|
|
823
|
+
* promptly — but the wait is BOUNDED (ENTRY_LOCK_BOUND_MS): an entry suspended on a
|
|
824
|
+
* never-settling module call releases the surface instead of jamming every later tap
|
|
825
|
+
* (proven by the demo Device-info page: one hung clipboard.read froze the whole page).
|
|
826
|
+
* Nested action calls go through callAction (not this), so they never re-enter
|
|
827
|
+
* the lock — no deadlock, no self-wait. */
|
|
828
|
+
async #runExclusive(work) {
|
|
829
|
+
const prior = this.#entryLock;
|
|
830
|
+
let release;
|
|
831
|
+
this.#entryLock = new Promise((r) => { release = r; });
|
|
832
|
+
// AN ENTRY PARKED ON THE OUTSIDE WORLD IS NOT FINISHING PROMPTLY. A shell whose on:appear awaits its
|
|
833
|
+
// session check and three fetches held every tap on its sidebar for the length of those requests
|
|
834
|
+
// . The
|
|
835
|
+
// bound below already proceeds past such an entry; proceeding at once is the same trade without
|
|
836
|
+
// the delay, and it is what the iOS reference does at every suspension point.
|
|
837
|
+
if ((runnerIoWaits.get(this) ?? 0) === 0) {
|
|
838
|
+
await Promise.race([prior, new Promise((r) => setTimeout(r, _a.ENTRY_LOCK_BOUND_MS))]);
|
|
839
|
+
}
|
|
840
|
+
const entry = { running: 1 };
|
|
841
|
+
const turn = takeBaton(this, entry, _a.ENTRY_LOCK_BOUND_MS);
|
|
842
|
+
if (turn !== null)
|
|
843
|
+
await turn;
|
|
844
|
+
const outerEntry = this.entry;
|
|
845
|
+
this.entry = entry;
|
|
846
|
+
// fresh entry: the previous one has fully unwound (depth back to 0) — clear the ledgers.
|
|
847
|
+
// callBudget joins them because its contract ("how many module calls one ENTRY may
|
|
848
|
+
// make", the type doc above) was per-entry all along — the single-entry hosts (a CLI
|
|
849
|
+
// invocation, a server request) never noticed the missing reset, and a long-lived
|
|
850
|
+
// scoped surface (studio-apps.md §5) is the first multi-entry env that would have
|
|
851
|
+
// starved after its cap's worth of taps.
|
|
852
|
+
this.env.actionDepth = 0;
|
|
853
|
+
this.env.loopWork.count = 0;
|
|
854
|
+
if (this.env.callBudget !== undefined)
|
|
855
|
+
this.env.callBudget.count = 0;
|
|
856
|
+
this.flow = null;
|
|
857
|
+
let heldBefore = null;
|
|
858
|
+
let hold = null;
|
|
859
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false) {
|
|
860
|
+
heldBefore = runnerHolds.get(this) ?? null;
|
|
861
|
+
hold = { store: this.env.store, live: true, active: false };
|
|
862
|
+
runnerHolds.set(this, hold);
|
|
863
|
+
takeHold(hold);
|
|
864
|
+
}
|
|
865
|
+
try {
|
|
866
|
+
await work();
|
|
867
|
+
}
|
|
868
|
+
finally {
|
|
869
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false) {
|
|
870
|
+
hold.live = false;
|
|
871
|
+
letGo(hold);
|
|
872
|
+
runnerHolds.set(this, heldBefore);
|
|
873
|
+
}
|
|
874
|
+
// An uncaught `throw` that unwound the whole entry used to vanish here — now it
|
|
875
|
+
// reports through the ambient fan-out with origin "uncaught" (errors corpus): the
|
|
876
|
+
// ledger, module.error, the page channel + dsx mirror, the reactive keys. The
|
|
877
|
+
// window.onerror analogue for markup actions; control flow is already unwound, so
|
|
878
|
+
// recording changes nothing (Article 7 — observe, never crash).
|
|
879
|
+
// (read through a method so TS doesn't over-narrow the mutated instance field)
|
|
880
|
+
const f = this.#currentFlow();
|
|
881
|
+
if (f !== null && f.kind === "throw")
|
|
882
|
+
this.#reportUncaught(f.value);
|
|
883
|
+
this.flow = null;
|
|
884
|
+
entry.running = 0;
|
|
885
|
+
giveBaton(this, entry);
|
|
886
|
+
this.entry = outerEntry;
|
|
887
|
+
release();
|
|
888
|
+
}
|
|
889
|
+
while (entry.strands !== undefined && entry.strands.size > 0)
|
|
890
|
+
await Promise.allSettled([...entry.strands]);
|
|
891
|
+
}
|
|
892
|
+
/** The body of the entry (or nested action) currently running — a throw that unwinds
|
|
893
|
+
* keeps the THROWING body here (callAction skips the restore on throw, like `flow`),
|
|
894
|
+
* so reportUncaught's `snippet` says WHAT threw. */
|
|
895
|
+
#entryBody = "";
|
|
896
|
+
/** Derive the canonical error fields from an uncaught thrown value (corpus-pinned): a
|
|
897
|
+
* dict with a string `code` keeps its code/message/recoverable/data; a codeless dict
|
|
898
|
+
* with a string `message` (a JSE `new Error("…")`, the browser-parity throw) keeps the
|
|
899
|
+
* message and rides whole as data; any other dict rides as data; anything else records
|
|
900
|
+
* code "uncaught" with the JSE string coercion as message. RUNTIME ERROR CONTEXT: the
|
|
901
|
+
* data additionally carries `snippet` — the first 120 chars of the body that threw —
|
|
902
|
+
* so a ledger entry says WHAT threw, not just that something did (dict data gains the
|
|
903
|
+
* key unless the author set one; scalar data rides untouched; expects stay green — the
|
|
904
|
+
* errors corpus subset-matches). */
|
|
905
|
+
#reportUncaught(value) {
|
|
906
|
+
let code = "uncaught";
|
|
907
|
+
let message = null;
|
|
908
|
+
let recoverable = false;
|
|
909
|
+
let data;
|
|
910
|
+
if (isDict(value)) {
|
|
911
|
+
const d = value;
|
|
912
|
+
const c = d["code"];
|
|
913
|
+
if (typeof c === "string" && c.length > 0) {
|
|
914
|
+
code = c;
|
|
915
|
+
const m = d["message"];
|
|
916
|
+
message = m === undefined || m === null || m === NSNull ? null : string(m);
|
|
917
|
+
recoverable = truthy(d["recoverable"]);
|
|
918
|
+
if (d["data"] !== undefined)
|
|
919
|
+
data = d["data"];
|
|
920
|
+
}
|
|
921
|
+
else if (typeof d["message"] === "string" && d["message"].length > 0) {
|
|
922
|
+
message = d["message"];
|
|
923
|
+
data = d;
|
|
924
|
+
}
|
|
925
|
+
else {
|
|
926
|
+
data = d;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
else {
|
|
930
|
+
message = string(value);
|
|
931
|
+
}
|
|
932
|
+
// A FAILED MODULE CALL NAMES ITSELF (F15): the throw's `call` rides beside the snippet, so
|
|
933
|
+
// the ledger, the dev overlay and a telemetry sink say which module and which action.
|
|
934
|
+
const context = { snippet: this.#entryBody.slice(0, 120) };
|
|
935
|
+
if (isDict(value) && typeof value["call"] === "string")
|
|
936
|
+
context["call"] = value["call"];
|
|
937
|
+
if (isDict(data)) {
|
|
938
|
+
data = { ...context, ...data };
|
|
939
|
+
}
|
|
940
|
+
else if (data === undefined || data === null || data === NSNull) {
|
|
941
|
+
data = context;
|
|
942
|
+
}
|
|
943
|
+
else if (context["call"] !== undefined) {
|
|
944
|
+
// A failed call whose module answered a scalar (`missing_param` with data "text") keeps
|
|
945
|
+
// it as `value`, so the call still rides with it. A plain scalar throw is untouched.
|
|
946
|
+
data = { ...context, value: data };
|
|
947
|
+
}
|
|
948
|
+
ModuleRegistry.reportAmbientError(this.env.ownerScheme ?? "app", code, { message, recoverable, data, origin: "uncaught" });
|
|
949
|
+
}
|
|
950
|
+
/** Invoke a declared `<action as=…>` — declared inputs evaluated in CALLER scope,
|
|
951
|
+
* first-arg object merges into the action scope, payload rides dsx.this. Actions
|
|
952
|
+
* ARE workflows: they call each other (`dsx.action.x()` / bare `x()`), chain, and
|
|
953
|
+
* pass args — depth-capped at 32 so a recursive workflow is bounded, never a hang
|
|
954
|
+
* (the JseRunner contract). Each call runs with its OWN flow signal, so a nested
|
|
955
|
+
* action's `return`/`break` can't abort the caller.
|
|
956
|
+
*
|
|
957
|
+
* RETURNING ACTIONS (actions corpus): resolves to the callee's OWN `return <expr>`
|
|
958
|
+
* value — captured from its flow signal {kind:"return", value} BEFORE the caller's
|
|
959
|
+
* flow is swapped back, so a nested call's leftover can never masquerade as this
|
|
960
|
+
* callee's return. Null when the body never returned (or returned bare). Only an
|
|
961
|
+
* AWAITING `dsx.action` caller consumes it; every other call site ignores it.
|
|
962
|
+
*
|
|
963
|
+
* THE HOST RULE (jse.md): a HOST entry (`options.entry`, the CLI node, a server request, a
|
|
964
|
+
* context provider's call) is an entry of its own, so calls its body makes without `await`
|
|
965
|
+
* start and the body goes on, as on a surface; the host's answer still waits for every one of
|
|
966
|
+
* them to finish (Workers' waitUntil), so a request never ends with its side effects cut off. */
|
|
967
|
+
async callAction(name, callArgs, item = null, payload = {}, options = {}) {
|
|
968
|
+
// MEMBER FOLD, the stopgap store.ts canHoldCall names (Article 17.4, EMBED-MEMBER-FOLDS-STOPGAP-1120): every path ends in callActionFrame, which
|
|
969
|
+
// answers null when `__DSX_OPTIONAL_NAMED_ACTIONS__` is folded, so the folded body gives the same answer.
|
|
970
|
+
if (globalThis.__DSX_OPTIONAL_NAMED_ACTIONS__ !== false) {
|
|
971
|
+
const baton = batonOf(this);
|
|
972
|
+
if (options.entry !== true || this.entry !== null || baton.owner !== null
|
|
973
|
+
|| globalThis.__DSX_OPTIONAL_ACTION_FRAME__ === false) {
|
|
974
|
+
return this.callActionFrame(name, callArgs, item, payload, options);
|
|
975
|
+
}
|
|
976
|
+
const root = { running: 1 };
|
|
977
|
+
baton.owner = root;
|
|
978
|
+
this.entry = root;
|
|
979
|
+
let value;
|
|
980
|
+
try {
|
|
981
|
+
value = await this.callActionFrame(name, callArgs, item, payload, options);
|
|
982
|
+
}
|
|
983
|
+
finally {
|
|
984
|
+
root.running = 0;
|
|
985
|
+
giveBaton(this, root);
|
|
986
|
+
if (this.entry === root)
|
|
987
|
+
this.entry = null;
|
|
988
|
+
}
|
|
989
|
+
// the entry's own ending (a throw the host reads with takeThrow) outlives the strands' runs
|
|
990
|
+
const ended = this.#currentFlow();
|
|
991
|
+
const endedBody = this.#entryBody;
|
|
992
|
+
while (root.strands !== undefined && root.strands.size > 0)
|
|
993
|
+
await Promise.allSettled([...root.strands]);
|
|
994
|
+
this.flow = ended;
|
|
995
|
+
this.#entryBody = endedBody;
|
|
996
|
+
return value;
|
|
997
|
+
}
|
|
998
|
+
return null;
|
|
999
|
+
}
|
|
1000
|
+
async callActionFrame(name, callArgs, item, payload, options) {
|
|
1001
|
+
if (globalThis.__DSX_OPTIONAL_NAMED_ACTIONS__ !== false) {
|
|
1002
|
+
const decl = this.env.actions.get(name);
|
|
1003
|
+
if (!decl) {
|
|
1004
|
+
// Inside a try, an action nothing declares is the SAME absence as a module that is
|
|
1005
|
+
// not in this build, and the law gives it the same throw so one guard covers both
|
|
1006
|
+
// (jse.md). Outside a try it stays the warning and the null it always was.
|
|
1007
|
+
if (this.tryDepth > 0 && this.flow === null) {
|
|
1008
|
+
this.flow = { kind: "throw", value: { code: ERROR_NOT_LOADED, call: name } };
|
|
1009
|
+
return null;
|
|
1010
|
+
}
|
|
1011
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
1012
|
+
console.warn(`[dsx runner] unknown action: ${name}`);
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
if (!JSE.validSyntax(decl.body))
|
|
1016
|
+
return null;
|
|
1017
|
+
if (this.env.actionDepth >= 32) {
|
|
1018
|
+
console.warn(`[dsx runner] action depth (32) exceeded at ${name} — recursion contained`);
|
|
1019
|
+
return null;
|
|
1020
|
+
}
|
|
1021
|
+
// THE CALLER'S LOCALS ARE THE CALLER'S (S3 cut). An input expression is evaluated in the
|
|
1022
|
+
// CALLER's scope (`inputs="word"` beside a caller that declared `const word`), and a
|
|
1023
|
+
// spread does not carry the non-enumerable ledger, so without this every such expression
|
|
1024
|
+
// read a bare name the caller HAD declared and answered null. The names are the caller's
|
|
1025
|
+
// own; only the dict is a copy. The CALLEE's scope below is built from this one and does
|
|
1026
|
+
// NOT inherit it: a callee's locals are its own, which is what the spread gives for free.
|
|
1027
|
+
const callerScope = { ...(this.env.item ?? {}), ...(item ?? {}) };
|
|
1028
|
+
carrySlotScope(callerScope, this.env.item, item);
|
|
1029
|
+
if (this.env.item !== null)
|
|
1030
|
+
for (const n of scopeLocalNames(this.env.item))
|
|
1031
|
+
declareLocal(callerScope, n);
|
|
1032
|
+
if (item !== null)
|
|
1033
|
+
for (const n of scopeLocalNames(item))
|
|
1034
|
+
declareLocal(callerScope, n);
|
|
1035
|
+
const scope = { ...callerScope, ...payload };
|
|
1036
|
+
for (const [k, expr] of Object.entries(decl.inputs)) {
|
|
1037
|
+
// AN ENTRY CALL HAS NO CALLER, so it has no caller scope to evaluate against, and a
|
|
1038
|
+
// declared input names a payload KEY rather than an expression to compute. The two
|
|
1039
|
+
// readings of `inputs="message"` are both correct and they are not the same: at a surface
|
|
1040
|
+
// call site the caller HAS a `message` in scope and the action means "take that one"; at
|
|
1041
|
+
// an entry the value arrives from outside and the action means "I accept one".
|
|
1042
|
+
//
|
|
1043
|
+
// Collapsing them cost a shipped bug. The surface rule ran unconditionally, so an entry
|
|
1044
|
+
// evaluated the input against an empty scope, got nothing, and OVERWROTE the host's
|
|
1045
|
+
// payload with the absent sentinel — a `<server>` action declaring `inputs="title, total"`
|
|
1046
|
+
// received null for both, which made declaring the contract strictly worse than omitting
|
|
1047
|
+
// it. Every host then coped differently: the CLI node discarded declared inputs entirely,
|
|
1048
|
+
// the queue drain routed its message through `callArgs`, and the HTTP path just shipped
|
|
1049
|
+
// the nulls. One unspecified case, three workarounds, one live defect.
|
|
1050
|
+
if (options.entry === true) {
|
|
1051
|
+
// OWN keys only. `k in payload` walks the prototype chain, so an input named `toString`
|
|
1052
|
+
// or `constructor` would read as supplied when it was not — and the Kotlin twin
|
|
1053
|
+
// (`containsKey`) and the Swift twin (a dictionary subscript) both test own keys, so
|
|
1054
|
+
// `in` would be a silent three-renderer divergence on exactly those names.
|
|
1055
|
+
if (Object.prototype.hasOwnProperty.call(payload, k))
|
|
1056
|
+
continue;
|
|
1057
|
+
// THE PAYLOAD IS THE ENTRY'S SCOPE, and `dsx.this` is how a declaration reads it. The
|
|
1058
|
+
// shorthand above is a shorthand, not the only path: an input whose NAME differs from
|
|
1059
|
+
// the payload key it takes is spelled `input:bucket="dsx.this.key"`, which is the
|
|
1060
|
+
// attribute classes law (the right side is an expression evaluated where the block is
|
|
1061
|
+
// used) applied to the one caller a host has. This used to evaluate against an EMPTY
|
|
1062
|
+
// item, so every such declaration bound the typed absence: the Sync socket door
|
|
1063
|
+
// declared `input:bucket="dsx.this.key"`, read undefined and refused every hello with
|
|
1064
|
+
// `door_refused`. A default that reads the store keeps working, because the store is
|
|
1065
|
+
// reachable from any scope.
|
|
1066
|
+
scope[k] = JSE.evalBlock(string(expr), this.env.store.jse, payload) ?? NSNull;
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
// A DECLARED INPUT IS EVALUATED IN ITS CALLER'S CONTEXT (reference/jse.md),
|
|
1070
|
+
// and a surface caller is an action body or a handler: its array mutators
|
|
1071
|
+
// write, as the caller's own expression would. The entry arm above has no caller body and
|
|
1072
|
+
// stays pure. A block-bodied input stays the pure block it always was.
|
|
1073
|
+
const src = string(expr).trim();
|
|
1074
|
+
scope[k] = (globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false &&
|
|
1075
|
+
!src.includes(";") && !src.includes("\n") && !src.startsWith("return") && !src.startsWith("{")
|
|
1076
|
+
? this.evalSync(cachedTokens(src), callerScope)
|
|
1077
|
+
: JSE.evalBlock(src, this.env.store.jse, callerScope)) ?? NSNull;
|
|
1078
|
+
}
|
|
1079
|
+
Object.assign(scope, callArgs);
|
|
1080
|
+
// A DECLARED `input:` NAME IS A LOCAL OF THE BLOCK THAT DECLARES IT (S3 cut, plan
|
|
1081
|
+
// section 0). It is the one bare name an `<action>` body may still read, because the
|
|
1082
|
+
// action declared it; every other bare name in that body is a reach and answers null.
|
|
1083
|
+
// Declared AFTER `callArgs` is applied, so a passed argument under the same name is the
|
|
1084
|
+
// same local, and before the `dsx.input` bag is built, which is the unshadowable second
|
|
1085
|
+
// spelling of exactly these names.
|
|
1086
|
+
for (const k of Object.keys(decl.inputs))
|
|
1087
|
+
declareLocal(scope, k);
|
|
1088
|
+
// THE SECOND SPELLING, PUBLISHED ONCE PER CALL (JSE_SCOPE_INPUTS, and `lookup`'s
|
|
1089
|
+
// `dsx.input.` branch reads it). Every name this call bound is reachable as
|
|
1090
|
+
// `dsx.input.<name>`, by string key, so a reserved head cannot shadow it: an author whose
|
|
1091
|
+
// input is spelled like a runtime scope name has a spelling that answers the CALLER's value.
|
|
1092
|
+
// The bag is the bound scope minus its own key, so it never nests into itself.
|
|
1093
|
+
const boundInputs = { ...scope };
|
|
1094
|
+
delete boundInputs[JSE_SCOPE_INPUTS];
|
|
1095
|
+
scope[JSE_SCOPE_INPUTS] = boundInputs;
|
|
1096
|
+
// `dsx.action.argument("x")`: the declared arguments alone (D59 Q2), bound for every call so a caller's never leaks in.
|
|
1097
|
+
bindScopeActionInputs(scope, Object.keys(decl.inputs));
|
|
1098
|
+
const savedFlow = this.flow; // isolate the callee's control flow from the caller
|
|
1099
|
+
const savedBody = this.#entryBody;
|
|
1100
|
+
const savedStops = this.debugStops;
|
|
1101
|
+
this.flow = null;
|
|
1102
|
+
if (globalThis
|
|
1103
|
+
.__DSX_OPTIONAL_DEBUG__ !== false)
|
|
1104
|
+
this.debugStops = 0;
|
|
1105
|
+
this.#entryBody = decl.body; // uncaught-throw context: the body that threw (see reportUncaught)
|
|
1106
|
+
this.env.actionDepth += 1;
|
|
1107
|
+
this.env.store.actionEntry(name, 1);
|
|
1108
|
+
const actionBegan = Date.now();
|
|
1109
|
+
if (globalThis
|
|
1110
|
+
.__DSX_OPTIONAL_DEBUG__ !== false)
|
|
1111
|
+
RunnerDebugSeam.onAction?.({ kind: "action", name, phase: "start", args: { ...callArgs, ...payload }, store: this.env.store });
|
|
1112
|
+
this.#actionNames.push(name); // which action is running - a `dsx.event` it raises is stamped with it
|
|
1113
|
+
this.#codeOwners.push(name);
|
|
1114
|
+
let returned = null;
|
|
1115
|
+
// An action entered with no entry running on this runner (a host entry, a context
|
|
1116
|
+
// provider's action called from a consumer) holds its own store for its stretches.
|
|
1117
|
+
let ownHold = null;
|
|
1118
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false) {
|
|
1119
|
+
const current = runnerHolds.get(this) ?? null;
|
|
1120
|
+
if (current === null || !current.live) {
|
|
1121
|
+
ownHold = { store: this.env.store, live: true, active: false };
|
|
1122
|
+
runnerHolds.set(this, ownHold);
|
|
1123
|
+
takeHold(ownHold);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
try {
|
|
1127
|
+
// /web/15: a declared <action> beyond the subset escalates like an entry body
|
|
1128
|
+
const route = jsTierRouting() ? RunnerJsTierSeam.route : null;
|
|
1129
|
+
if (route === null || !(await route(this, decl.body, scope))) {
|
|
1130
|
+
const walker = new StmtWalker(cachedTokens(decl.body));
|
|
1131
|
+
await this.runStatements(walker, scope, true);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
finally {
|
|
1135
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false && ownHold !== null) {
|
|
1136
|
+
ownHold.live = false;
|
|
1137
|
+
letGo(ownHold);
|
|
1138
|
+
if (runnerHolds.get(this) === ownHold)
|
|
1139
|
+
runnerHolds.set(this, null);
|
|
1140
|
+
}
|
|
1141
|
+
this.env.store.actionEntry(name, -1);
|
|
1142
|
+
if (globalThis
|
|
1143
|
+
.__DSX_OPTIONAL_DEBUG__ !== false) {
|
|
1144
|
+
const thrown = this.#currentFlow();
|
|
1145
|
+
RunnerDebugSeam.onAction?.({ kind: "action", name, phase: "end", ms: Date.now() - actionBegan, store: this.env.store,
|
|
1146
|
+
...(thrown !== null && thrown.kind === "throw" ? { error: string(thrown.value) } : {}) });
|
|
1147
|
+
}
|
|
1148
|
+
this.env.actionDepth -= 1;
|
|
1149
|
+
this.#actionNames.pop();
|
|
1150
|
+
this.#codeOwners.pop();
|
|
1151
|
+
// a `throw` propagates to the caller (real exception → its try/catch); a
|
|
1152
|
+
// `return`/`break`/`continue` is LOCAL to the action (it just ends the body).
|
|
1153
|
+
// (read through a method so TS doesn't over-narrow the mutated instance field)
|
|
1154
|
+
const f = this.#currentFlow();
|
|
1155
|
+
if (f !== null && f.kind === "return")
|
|
1156
|
+
returned = f.value ?? null;
|
|
1157
|
+
if (globalThis
|
|
1158
|
+
.__DSX_OPTIONAL_DEBUG__ !== false)
|
|
1159
|
+
this.debugStops = savedStops;
|
|
1160
|
+
if (!this.threw()) {
|
|
1161
|
+
this.flow = savedFlow;
|
|
1162
|
+
this.#entryBody = savedBody;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
return returned;
|
|
1166
|
+
}
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
/** the current flow signal is a `throw` (a real exception to propagate) */
|
|
1170
|
+
threw() {
|
|
1171
|
+
const f = this.flow;
|
|
1172
|
+
return f !== null && f.kind === "throw";
|
|
1173
|
+
}
|
|
1174
|
+
/** `dsx.action.x()` WITHOUT `await` follows JavaScript (Conformance/actions `unawaited-*`): the
|
|
1175
|
+
* callee runs as its own strand up to its first real suspension, then the caller goes on; the
|
|
1176
|
+
* callee's rest runs when the caller waits or ends (the baton). Its throw, early or late, is
|
|
1177
|
+
* reported like an unhandled rejection and never stops the caller. */
|
|
1178
|
+
async startUnawaited(name, argObj, scope, handlers) {
|
|
1179
|
+
// BLOCK-FORM FOLD (`__DSX_OPTIONAL_ACTION_FRAME__`): the one call site sits under the same flag, and a class
|
|
1180
|
+
// method survives tree shaking, so the strand machinery (holds, the baton hand-back) folds here too.
|
|
1181
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ === false)
|
|
1182
|
+
return;
|
|
1183
|
+
const caller = this.entry;
|
|
1184
|
+
const saved = { flow: this.flow, depth: this.env.actionDepth, body: this.#entryBody, names: [...this.#actionNames],
|
|
1185
|
+
owners: [...this.#codeOwners], events: this.#actionEvents, stops: this.debugStops };
|
|
1186
|
+
let handBack;
|
|
1187
|
+
const handedBack = new Promise((r) => { handBack = r; });
|
|
1188
|
+
const root = caller.root ?? caller;
|
|
1189
|
+
const strand = { running: 1, handBack, caller, root };
|
|
1190
|
+
batonOf(this).owner = strand;
|
|
1191
|
+
this.entry = strand;
|
|
1192
|
+
this.ownCallbacks(handlers);
|
|
1193
|
+
if (handlers !== null)
|
|
1194
|
+
this.#actionEvents = handlers;
|
|
1195
|
+
// The strand holds its own stretches (one action, one frame), also after its caller has ended.
|
|
1196
|
+
const callerHold = runnerHolds.get(this) ?? null;
|
|
1197
|
+
const hold = { store: this.env.store, live: true, active: false };
|
|
1198
|
+
runnerHolds.set(this, hold);
|
|
1199
|
+
takeHold(hold);
|
|
1200
|
+
const run = this.callAction(name, argObj, scope, {}).then(() => {
|
|
1201
|
+
const f = this.#currentFlow();
|
|
1202
|
+
if (f !== null && f.kind === "throw") {
|
|
1203
|
+
this.#reportUncaught(f.value);
|
|
1204
|
+
this.flow = null;
|
|
1205
|
+
}
|
|
1206
|
+
hold.live = false;
|
|
1207
|
+
letGo(hold);
|
|
1208
|
+
if (runnerHolds.get(this) === hold)
|
|
1209
|
+
runnerHolds.set(this, null);
|
|
1210
|
+
strandStops(this, strand);
|
|
1211
|
+
if (this.entry === strand)
|
|
1212
|
+
this.entry = null;
|
|
1213
|
+
});
|
|
1214
|
+
const strands = root.strands ?? (root.strands = new Set());
|
|
1215
|
+
strands.add(run);
|
|
1216
|
+
void run.finally(() => strands.delete(run));
|
|
1217
|
+
await Promise.race([run, handedBack]);
|
|
1218
|
+
runnerHolds.set(this, callerHold);
|
|
1219
|
+
this.entry = caller;
|
|
1220
|
+
this.flow = saved.flow;
|
|
1221
|
+
this.env.actionDepth = saved.depth;
|
|
1222
|
+
this.#entryBody = saved.body;
|
|
1223
|
+
this.#actionNames = saved.names;
|
|
1224
|
+
this.#codeOwners = saved.owners;
|
|
1225
|
+
this.#actionEvents = saved.events;
|
|
1226
|
+
this.debugStops = saved.stops;
|
|
1227
|
+
}
|
|
1228
|
+
/** Await something that really suspends, with the store let go for the wait: what the action
|
|
1229
|
+
* wrote so far paints ("Saving..."), and a write that lands from elsewhere during the wait is
|
|
1230
|
+
* not held back by this action. Another entry may run meanwhile (the baton) and resets the
|
|
1231
|
+
* per-entry ledgers when it starts, so this entry's own are put back before it resumes, with
|
|
1232
|
+
* the baton and the hold taken again. */
|
|
1233
|
+
suspend(p) {
|
|
1234
|
+
// BLOCK-FORM FOLD: every caller already reads `__DSX_OPTIONAL_ACTION_FRAME__` before it suspends.
|
|
1235
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ === false)
|
|
1236
|
+
return p;
|
|
1237
|
+
const h = runnerHolds.get(this) ?? null;
|
|
1238
|
+
letGo(h);
|
|
1239
|
+
const entry = this.entry;
|
|
1240
|
+
const parked = {
|
|
1241
|
+
flow: this.flow, depth: this.env.actionDepth, loop: this.env.loopWork.count,
|
|
1242
|
+
calls: this.env.callBudget?.count, body: this.#entryBody, names: [...this.#actionNames],
|
|
1243
|
+
owners: [...this.#codeOwners], events: this.#actionEvents, stops: this.debugStops,
|
|
1244
|
+
};
|
|
1245
|
+
runnerIoWaits.set(this, (runnerIoWaits.get(this) ?? 0) + 1);
|
|
1246
|
+
if (entry !== null)
|
|
1247
|
+
strandStops(this, entry);
|
|
1248
|
+
const resume = async () => {
|
|
1249
|
+
runnerIoWaits.set(this, Math.max(0, (runnerIoWaits.get(this) ?? 1) - 1));
|
|
1250
|
+
if (entry !== null) {
|
|
1251
|
+
entry.running += 1;
|
|
1252
|
+
const turn = takeBaton(this, entry, _a.ENTRY_LOCK_BOUND_MS);
|
|
1253
|
+
if (turn !== null)
|
|
1254
|
+
await turn;
|
|
1255
|
+
}
|
|
1256
|
+
this.entry = entry;
|
|
1257
|
+
this.flow = parked.flow;
|
|
1258
|
+
this.env.actionDepth = parked.depth;
|
|
1259
|
+
this.env.loopWork.count = parked.loop;
|
|
1260
|
+
if (this.env.callBudget !== undefined && parked.calls !== undefined)
|
|
1261
|
+
this.env.callBudget.count = parked.calls;
|
|
1262
|
+
this.#entryBody = parked.body;
|
|
1263
|
+
this.#actionNames = parked.names;
|
|
1264
|
+
this.#codeOwners = parked.owners;
|
|
1265
|
+
this.#actionEvents = parked.events;
|
|
1266
|
+
this.debugStops = parked.stops;
|
|
1267
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false)
|
|
1268
|
+
runnerHolds.set(this, h);
|
|
1269
|
+
takeHold(h);
|
|
1270
|
+
};
|
|
1271
|
+
return p.then(async (v) => { await resume(); return v; }, async (e) => { await resume(); throw e; });
|
|
1272
|
+
}
|
|
1273
|
+
/** the current flow signal, read through a method (TS over-narrows the mutated field) */
|
|
1274
|
+
#currentFlow() {
|
|
1275
|
+
return this.flow;
|
|
1276
|
+
}
|
|
1277
|
+
// ── statement machinery ────────────────────────────────────────────────────────────
|
|
1278
|
+
flow = null;
|
|
1279
|
+
/** > 0 while a `try` BODY runs. THE UNIVERSAL FEATURE DETECTION LAW (jse.md, "try/catch
|
|
1280
|
+
* is universal feature-detection"): inside a try, a call to a module that is not in this
|
|
1281
|
+
* build, or to an action no `<action>` declares, throws `{ code: "not_loaded", call }` so
|
|
1282
|
+
* the catch runs the fallback; outside a try the same call stays a silent no-op, because
|
|
1283
|
+
* a missing OPTIONAL module must never crash a surface.
|
|
1284
|
+
*
|
|
1285
|
+
* Both natives have carried this counter since the law was written (Stack.swift
|
|
1286
|
+
* `store.tryDepth`, JseRunner.kt the same). This runner never had it, so the documented
|
|
1287
|
+
* catch NEVER RAN on the web: a fire and forget module call swallowed its rejection, an
|
|
1288
|
+
* awaited one bound the `{ ok: false }` envelope and kept going, and an unknown action
|
|
1289
|
+
* warned to the console and answered null. Every capability fallback an author wrote in
|
|
1290
|
+
* the documented shape therefore did nothing here and worked on a phone, which is the
|
|
1291
|
+
* worst possible split for a feature detection idiom (Appendix E item 2). */
|
|
1292
|
+
tryDepth = 0;
|
|
1293
|
+
/** event callbacks passed as the 2nd arg of the in-flight `dsx.action.x(args, { evt: fn })`
|
|
1294
|
+
* call — an event the callee raises runs the matching callback (native store.actionEvents). */
|
|
1295
|
+
#actionEvents = null;
|
|
1296
|
+
/** the named `<action>`s currently executing, innermost last - the twin of Stack.swift's
|
|
1297
|
+
* `store.actionNameStack` and JseRunner.kt's. It exists so a `dsx.event` raised from an
|
|
1298
|
+
* action body can be stamped with WHICH action raised it. */
|
|
1299
|
+
#actionNames = [];
|
|
1300
|
+
/** WHOSE CODE IS RUNNING: the action whose body is being run, or, inside an event callback, the
|
|
1301
|
+
* action whose body wrote that callback. It differs from `actionNames` only inside a callback,
|
|
1302
|
+
* where the stamp (`__from`, the `from:` filter's reading) names the action that raised the event
|
|
1303
|
+
* and this names the action whose own code raised it. A host that answers by an action's own
|
|
1304
|
+
* events (a server route, constitution Article 28.8) reads it as `emitEvent`'s fourth argument. */
|
|
1305
|
+
#codeOwners = [];
|
|
1306
|
+
/** the action whose body wrote each callback handed to an action call (`dsx.action.x(args, { … })`) */
|
|
1307
|
+
lambdaOwners = new WeakMap();
|
|
1308
|
+
/** Record the caller as the writer of each callback in a call's callback map. */
|
|
1309
|
+
ownCallbacks(handlers) {
|
|
1310
|
+
// MEMBER FOLD, a STOPGAP for design 3.2b (Article 17.4, backlog row EMBED-MEMBER-FOLDS-STOPGAP-1120): esbuild keeps
|
|
1311
|
+
// every class member, so a member whose only callers sit behind a fold keeps its body unless the body folds too.
|
|
1312
|
+
// Removed when 3.2b moves the member out of the class. A callback map reaches here only with a named-action call (`__DSX_OPTIONAL_NAMED_ACTIONS__`).
|
|
1313
|
+
if (globalThis.__DSX_OPTIONAL_NAMED_ACTIONS__ !== false) {
|
|
1314
|
+
const owner = this.#codeOwners.at(-1);
|
|
1315
|
+
if (handlers === null || owner === undefined)
|
|
1316
|
+
return;
|
|
1317
|
+
for (const cb of Object.values(handlers))
|
|
1318
|
+
if (isLambda(cb))
|
|
1319
|
+
this.lambdaOwners.set(cb, owner);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
/** the entry whose strand is executing (the baton's unit); null for a body run outside an entry */
|
|
1323
|
+
entry = null;
|
|
1324
|
+
async runStatements(w, scope, topLevel) {
|
|
1325
|
+
if (globalThis
|
|
1326
|
+
.__DSX_OPTIONAL_DEBUG__ !== false) {
|
|
1327
|
+
this.debugOuter.push(this.debugDepth);
|
|
1328
|
+
this.debugDepth = topLevel ? 0 : this.debugDepth + 1;
|
|
1329
|
+
}
|
|
1330
|
+
try {
|
|
1331
|
+
for (;;) {
|
|
1332
|
+
if (this.flow !== null)
|
|
1333
|
+
return;
|
|
1334
|
+
const tk = w.cur();
|
|
1335
|
+
if (tk === null)
|
|
1336
|
+
return;
|
|
1337
|
+
if (isOpTok(tk, "}"))
|
|
1338
|
+
return;
|
|
1339
|
+
if (isOpTok(tk, ";")) {
|
|
1340
|
+
w.i += 1;
|
|
1341
|
+
continue;
|
|
1342
|
+
}
|
|
1343
|
+
// THE ONE PLACE A DEBUGGER STOPS. One boolean read when nothing is installed, which
|
|
1344
|
+
// is what makes it free in a development bundle with no debugger attached, and a held
|
|
1345
|
+
// promise when something is: the body waits here and holds what it was holding. The
|
|
1346
|
+
// whole block folds out of a build that pinned the plane off, which is section 5.3's
|
|
1347
|
+
// rule that a production build has no choke point compiled in at all.
|
|
1348
|
+
if (globalThis
|
|
1349
|
+
.__DSX_OPTIONAL_DEBUG__ !== false) {
|
|
1350
|
+
const stop = RunnerDebugSeam.onStatement;
|
|
1351
|
+
if (stop !== null) {
|
|
1352
|
+
await stop({
|
|
1353
|
+
body: this.#entryBody, token: w.i, ordinal: this.debugStops, depth: this.debugDepth,
|
|
1354
|
+
scope, locals: scopeLocals(scope),
|
|
1355
|
+
actionDepth: this.env.actionDepth, chain: [...this.#actionNames],
|
|
1356
|
+
});
|
|
1357
|
+
this.debugStops += 1;
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
const before = w.i;
|
|
1361
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false)
|
|
1362
|
+
takeHold(runnerHolds.get(this) ?? null);
|
|
1363
|
+
await this.statement(w, scope, topLevel);
|
|
1364
|
+
if (w.i === before)
|
|
1365
|
+
w.i += 1; // never spin
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
finally {
|
|
1369
|
+
if (globalThis
|
|
1370
|
+
.__DSX_OPTIONAL_DEBUG__ !== false) {
|
|
1371
|
+
this.debugDepth = this.debugOuter.pop() ?? 0;
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
/** Block nesting of the statements currently being offered to the debug seam, and the stack
|
|
1376
|
+
* the nesting is restored from. Both are written only behind the fold. */
|
|
1377
|
+
debugDepth = 0;
|
|
1378
|
+
debugOuter = [];
|
|
1379
|
+
/** Statements offered to the debug seam in the body now running. Saved and restored around
|
|
1380
|
+
* an action call for the same reason `entryBody` is: the callee's count is its own. */
|
|
1381
|
+
debugStops = 0;
|
|
1382
|
+
async statement(w, scope, topLevel) {
|
|
1383
|
+
const tk = w.cur();
|
|
1384
|
+
if (tk === null)
|
|
1385
|
+
return;
|
|
1386
|
+
if (globalThis.__DSX_OPTIONAL_IF_STATEMENTS__ !== false
|
|
1387
|
+
&& isIdentTok(tk, "if")) {
|
|
1388
|
+
await ifStmt(this, w, scope, topLevel);
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
// BLOCK ITERATION and BLOCK CONTROL are the SAME two folds the expression evaluator
|
|
1392
|
+
// takes (jse.ts), decided by the SAME two roster keys, and this is the statement
|
|
1393
|
+
// runner's half of each. Read the flag inline, never through a const, so esbuild's
|
|
1394
|
+
// define substitutes the member access, `false !== false` folds, the branch drops, and
|
|
1395
|
+
// with every reference gone the module-level impls below DCE out of a folded slice —
|
|
1396
|
+
// which is why they are module functions and not methods: a class method is reachable
|
|
1397
|
+
// through the class and no bundler can drop it, so the fold that shed the evaluator's
|
|
1398
|
+
// copy left the runner's shipping in every widget. Folded, the five words fall to the
|
|
1399
|
+
// generic statement arm exactly as they did before the words existed.
|
|
1400
|
+
if (globalThis
|
|
1401
|
+
.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false) {
|
|
1402
|
+
if (isIdentTok(tk, "while")) {
|
|
1403
|
+
await BLOCK_ITERATION_RUN_IMPL.whileStmt(this, w, scope);
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
1406
|
+
if (isIdentTok(tk, "do")) {
|
|
1407
|
+
await BLOCK_ITERATION_RUN_IMPL.doWhileStmt(this, w, scope);
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
if (isIdentTok(tk, "for")) {
|
|
1411
|
+
await BLOCK_ITERATION_RUN_IMPL.forStmt(this, w, scope);
|
|
1412
|
+
return;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
if (globalThis
|
|
1416
|
+
.__DSX_OPTIONAL_BLOCK_CONTROL__ !== false) {
|
|
1417
|
+
if (isIdentTok(tk, "switch")) {
|
|
1418
|
+
await BLOCK_CONTROL_RUN_IMPL.switchStmt(this, w, scope);
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
if (isIdentTok(tk, "try")) {
|
|
1422
|
+
await BLOCK_CONTROL_RUN_IMPL.tryStmt(this, w, scope);
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
// THE MULTI-STATEMENT VOCABULARY (`__DSX_OPTIONAL_STATEMENTS__`, cli embed entry.ts
|
|
1427
|
+
// registryUsesStatements): a declaration, `function`, `return`, `break`, `continue`, `throw` and
|
|
1428
|
+
// a bare block exist only in a body with more than one expression in it. A widget whose every
|
|
1429
|
+
// handler, action and watch is ONE expression sheds these arms (and with them the frames the
|
|
1430
|
+
// bare block opens); the words cannot occur in such a slice, so nothing it runs changes.
|
|
1431
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENTS__ !== false) {
|
|
1432
|
+
if (isIdentTok(tk, "function")) {
|
|
1433
|
+
w.skipFunction();
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
if (isIdentTok(tk, "const") || isIdentTok(tk, "let") || isIdentTok(tk, "var")) {
|
|
1437
|
+
await this.declStmt(w, scope);
|
|
1438
|
+
return;
|
|
1439
|
+
}
|
|
1440
|
+
if (isIdentTok(tk, "return")) {
|
|
1441
|
+
w.i += 1;
|
|
1442
|
+
const toks = w.capture(new Set([";"]));
|
|
1443
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
1444
|
+
w.i += 1;
|
|
1445
|
+
const v = toks.length === 0 ? null : await this.evalMaybeAsync(toks, scope);
|
|
1446
|
+
this.flow = { kind: "return", value: v };
|
|
1447
|
+
return;
|
|
1448
|
+
}
|
|
1449
|
+
if (isIdentTok(tk, "break")) {
|
|
1450
|
+
w.i += 1;
|
|
1451
|
+
this.flow = { kind: "break" };
|
|
1452
|
+
return;
|
|
1453
|
+
}
|
|
1454
|
+
if (isIdentTok(tk, "continue")) {
|
|
1455
|
+
w.i += 1;
|
|
1456
|
+
this.flow = { kind: "continue" };
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
if (isIdentTok(tk, "throw")) {
|
|
1460
|
+
w.i += 1;
|
|
1461
|
+
const toks = w.capture(new Set([";"]));
|
|
1462
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
1463
|
+
w.i += 1;
|
|
1464
|
+
this.flow = { kind: "throw", value: await this.evalMaybeAsync(toks, scope) };
|
|
1465
|
+
return;
|
|
1466
|
+
}
|
|
1467
|
+
if (isOpTok(tk, "{")) { // bare block scope
|
|
1468
|
+
w.i += 1;
|
|
1469
|
+
openBlock(scope);
|
|
1470
|
+
try {
|
|
1471
|
+
await this.runStatements(w, scope, topLevel);
|
|
1472
|
+
}
|
|
1473
|
+
finally {
|
|
1474
|
+
closeBlock(scope);
|
|
1475
|
+
}
|
|
1476
|
+
if (isOpTok(w.cur() ?? undefined, "}"))
|
|
1477
|
+
w.i += 1;
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
// effect verbs: `fetch:` `remove:` `animate:` … — the optional fold
|
|
1482
|
+
// (__DSX_OPTIONAL_EFFECT_VERBS__), the shape the two block folds above use. A verb is
|
|
1483
|
+
// reachable only through its own `<word>:` label, so a slice the build PROVED spells
|
|
1484
|
+
// none of the five sheds the arm and every one of the words falls through to the
|
|
1485
|
+
// generic statement arm, which is where an unknown label already went.
|
|
1486
|
+
if (globalThis
|
|
1487
|
+
.__DSX_OPTIONAL_EFFECT_VERBS__ !== false
|
|
1488
|
+
&& tk.kind === "ident" && EFFECT_VERBS.has(tk.v) && isOpTok(w.t[w.i + 1], ":")) {
|
|
1489
|
+
const verb = tk.v;
|
|
1490
|
+
w.i += 2;
|
|
1491
|
+
const toks = w.capture(new Set([";"]));
|
|
1492
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
1493
|
+
w.i += 1;
|
|
1494
|
+
await EFFECT_VERB_RUN_IMPL.effectVerb(this, verb, toks, scope);
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
const toks = w.capture(new Set([";"]));
|
|
1498
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
1499
|
+
w.i += 1;
|
|
1500
|
+
if (toks.length > 0)
|
|
1501
|
+
await this.leafStatement(toks, scope);
|
|
1502
|
+
}
|
|
1503
|
+
async declStmt(w, scope) {
|
|
1504
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_WRITES__ === false)
|
|
1505
|
+
return;
|
|
1506
|
+
// `var` keeps the body's scope (JavaScript's function scope); `let` and `const` are the block's.
|
|
1507
|
+
const blockScoped = !isIdentTok(w.cur() ?? undefined, "var");
|
|
1508
|
+
w.i += 1;
|
|
1509
|
+
const toks = w.capture(new Set([";"]));
|
|
1510
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
1511
|
+
w.i += 1;
|
|
1512
|
+
// multi-declarators + flat destructuring: `let a = 1, b = 2` · `const {x, y: r} = o` ·
|
|
1513
|
+
// `const [p, q] = await Promise.all([…])` — each initializer keeps the async routing.
|
|
1514
|
+
for (const d of parseDeclarators(toks)) {
|
|
1515
|
+
const v = d.expr.length === 0 ? null : await this.evalMaybeAsync(d.expr, scope);
|
|
1516
|
+
bindPattern(d.pattern, v, (n, val) => { if (blockScoped)
|
|
1517
|
+
newBinding(scope, n); scope[n] = val ?? NSNull; declareLocal(scope, n); },
|
|
1518
|
+
// A `= default` is evaluated in the SCOPE BEING BUILT, so an earlier position in the
|
|
1519
|
+
// same pattern is already visible to a later one's default — the JS rule.
|
|
1520
|
+
(toks) => this.evalSync(toks, scope));
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
/** One leaf statement (assignment / call / mutation) — the runJSStatement table. */
|
|
1524
|
+
async leafStatement(rawToks, scope) {
|
|
1525
|
+
// `await dsx.module.x.y(…)` AS A WHOLE STATEMENT IS THE STATEMENT CALL (F15): nothing reads
|
|
1526
|
+
// its envelope, so it waits for the verdict and a failure throws into the handler
|
|
1527
|
+
// (dsxStatement's module branch, `waits`). `await dsx.stop(x)` is the same statement call.
|
|
1528
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_CALLS__ !== false
|
|
1529
|
+
&& isIdentTok(rawToks[0], "await") && rawToks[1]?.kind === "ident"
|
|
1530
|
+
&& (rawToks[1].v.startsWith("dsx.module.") || rawToks[1].v === "dsx.stop")
|
|
1531
|
+
&& isOpTok(rawToks[2], "(") && isOpTok(rawToks[rawToks.length - 1], ")")) {
|
|
1532
|
+
let depth = 0;
|
|
1533
|
+
let end = -1;
|
|
1534
|
+
for (let i = 2; i < rawToks.length && end < 0; i++) {
|
|
1535
|
+
const t = rawToks[i];
|
|
1536
|
+
if (t.kind === "op" && "([{".includes(t.v))
|
|
1537
|
+
depth += 1;
|
|
1538
|
+
else if (t.kind === "op" && ")]}".includes(t.v) && --depth === 0)
|
|
1539
|
+
end = i;
|
|
1540
|
+
}
|
|
1541
|
+
if (end === rawToks.length - 1) {
|
|
1542
|
+
await this.#dsxStatement(rawToks[1].v, rawToks.slice(1), scope, false, true);
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
// a module-level arm (esbuild cannot drop a class method): a slice that awaits nothing
|
|
1547
|
+
// (__DSX_OPTIONAL_ASYNC_EXPRESSIONS__ false) sheds it with the rest of the await door.
|
|
1548
|
+
if (globalThis.__DSX_OPTIONAL_ASYNC_EXPRESSIONS__ !== false &&
|
|
1549
|
+
await awaitedArgsCall(this, rawToks, scope))
|
|
1550
|
+
return;
|
|
1551
|
+
const writes = globalThis.__DSX_OPTIONAL_STATEMENT_WRITES__ !== false;
|
|
1552
|
+
const toks = writes ? jsSugar(flattenTarget(rawToks, (ts) => this.evalSync(ts, scope))) : rawToks;
|
|
1553
|
+
// THE THIRD BARE CALL FORM IS RETIRED TOO (S3 cut). A body like
|
|
1554
|
+
// `dsx.variable.x = 1; copyDemo; dsx.variable.y = 2` ran `copyDemo` mid-body, so a WORD
|
|
1555
|
+
// ON ITS OWN was a call on the lanes that had this branch and an expression on the lanes
|
|
1556
|
+
// that did not. It is an expression everywhere now: the statement evaluates a name
|
|
1557
|
+
// nothing binds, answers null, and the writes around it land exactly as they did.
|
|
1558
|
+
// `dsx.action.copyDemo()` is the call, and the actions corpus row
|
|
1559
|
+
// `a bare action name mid body is not a call: nothing runs` pins it on all three runners.
|
|
1560
|
+
// This was the last of the three: the handler shortcut in `run()`, the paren form in
|
|
1561
|
+
// `runJSStatement`, and this one.
|
|
1562
|
+
// DESTRUCTURING ASSIGNMENT `[a, b] = [b, a]` (syntax-005) — the declaration-less
|
|
1563
|
+
// pattern write. parseDeclarators reads `pattern = expr` exactly as it does after a
|
|
1564
|
+
// `const`; only the binder differs: writePath routes each name as an ordinary
|
|
1565
|
+
// assignment (an authored local stays local, everything else is the store), so the
|
|
1566
|
+
// statement writes wherever `a = …` would have. The RHS evaluates ONCE, before any
|
|
1567
|
+
// binding — which is what makes a swap a swap.
|
|
1568
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_WRITES__ !== false) {
|
|
1569
|
+
if (toks.length >= 4 && isOpTok(toks[0], "[")) {
|
|
1570
|
+
const decls = parseDeclarators(toks);
|
|
1571
|
+
const d0 = decls.length === 1 ? decls[0] : null;
|
|
1572
|
+
if (d0 !== null && d0.pattern.kind === "array" && d0.expr.length > 0 &&
|
|
1573
|
+
(d0.pattern.items.some((it) => it !== null) || d0.pattern.rest !== undefined)) {
|
|
1574
|
+
const v = await this.evalMaybeAsync(d0.expr, scope);
|
|
1575
|
+
bindPattern(d0.pattern, v, (n, val) => writePath(this.env, scope, n, val ?? NSNull), (dts) => this.evalSync(dts, scope));
|
|
1576
|
+
return;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
// assignment: single dotted-ident LHS `=` RHS
|
|
1580
|
+
if (toks.length >= 2 && toks[0].kind === "ident" && isOpTok(toks[1], "=")) {
|
|
1581
|
+
const lhs = toks[0].v;
|
|
1582
|
+
const value = await this.evalMaybeAsync(toks.slice(2), scope);
|
|
1583
|
+
// A RIGHT-HAND SIDE THAT THREW WRITES NOTHING (JavaScript): a call the document holds that fails inside
|
|
1584
|
+
// a `try` leaves its target as it was (Conformance/held-calls/document-stop.json). Twins: JseRunner.kt
|
|
1585
|
+
// and Stack.swift `holdInTry`.
|
|
1586
|
+
if (this.threw())
|
|
1587
|
+
return;
|
|
1588
|
+
const refusedWrite = callDataRefusal(this.env, scope, lhs, value);
|
|
1589
|
+
if (refusedWrite !== null) {
|
|
1590
|
+
await this.settleCall(notData(refusedWrite), refusedWrite, false, false, () => null);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
writePath(this.env, scope, lhs, value);
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
// indexed assignment: `name[expr] = rhs` (one index level) — the index evaluates and
|
|
1597
|
+
// the write routes through the dotted path (`arr.0` / `o.key`), same as `set:` paths
|
|
1598
|
+
if (toks.length >= 5 && toks[0].kind === "ident" && isOpTok(toks[1], "[")) {
|
|
1599
|
+
let d = 0;
|
|
1600
|
+
let close = -1;
|
|
1601
|
+
for (let i = 1; i < toks.length; i++) {
|
|
1602
|
+
const t = toks[i];
|
|
1603
|
+
if (t.kind === "op" && (t.v === "[" || t.v === "(" || t.v === "{"))
|
|
1604
|
+
d += 1;
|
|
1605
|
+
else if (t.kind === "op" && (t.v === "]" || t.v === ")" || t.v === "}")) {
|
|
1606
|
+
d -= 1;
|
|
1607
|
+
if (d === 0) {
|
|
1608
|
+
close = i;
|
|
1609
|
+
break;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
if (close > 1 && isOpTok(toks[close + 1], "=")) {
|
|
1614
|
+
const idxVal = this.evalSync(toks.slice(2, close), scope);
|
|
1615
|
+
const value = await this.evalMaybeAsync(toks.slice(close + 2), scope);
|
|
1616
|
+
const n = number(idxVal);
|
|
1617
|
+
const seg = n !== null && Number.isFinite(n) && Math.trunc(n) === n ? String(safeInt(n)) : string(idxVal);
|
|
1618
|
+
const refusedWrite = callDataRefusal(this.env, scope, toks[0].v, value);
|
|
1619
|
+
if (refusedWrite !== null) {
|
|
1620
|
+
await this.settleCall(notData(refusedWrite), refusedWrite, false, false, () => null);
|
|
1621
|
+
return;
|
|
1622
|
+
}
|
|
1623
|
+
if (seg.includes(".")) {
|
|
1624
|
+
writeKey(this.env, scope, toks[0].v, seg, value);
|
|
1625
|
+
return;
|
|
1626
|
+
}
|
|
1627
|
+
writePath(this.env, scope, `${toks[0].v}.${seg}`, value);
|
|
1628
|
+
return;
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
// call-shaped statements
|
|
1633
|
+
if (toks.length >= 2 && toks[0].kind === "ident" && isOpTok(toks[1], "(")) {
|
|
1634
|
+
const callee = toks[0].v;
|
|
1635
|
+
// THE INVOKE FACE, ahead of the `dsx.*` statement dispatch: `dsx.api.<as>(args?)` and
|
|
1636
|
+
// `dsx.api.<as>.cancel()`. Nothing else on `dsx.api.` resolves.
|
|
1637
|
+
// folded out of a widget that declares no <socket> (`__DSX_OPTIONAL_SOCKETS__`) or no <api>
|
|
1638
|
+
// (`__DSX_OPTIONAL_APIS__`): neither handle table can hold anything there
|
|
1639
|
+
// Each arm is a block under its flag, not a `const x = flag ? … : null` test: esbuild does not carry a folded
|
|
1640
|
+
// constant into the `if` that reads it, so the arm and every helper it names stayed in a widget with neither.
|
|
1641
|
+
if (globalThis.__DSX_OPTIONAL_SOCKETS__ !== false) {
|
|
1642
|
+
const socketCall = socketCallTarget(callee, this.env.sockets);
|
|
1643
|
+
if (socketCall !== null) {
|
|
1644
|
+
runSocketCall(socketCall, this.#parseArgs(toks.slice(1), scope));
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
if (globalThis.__DSX_OPTIONAL_APIS__ !== false) {
|
|
1649
|
+
const apiCall = apiCallTarget(callee, this.env.apis);
|
|
1650
|
+
if (apiCall !== null) {
|
|
1651
|
+
if (apiCall.cancel) {
|
|
1652
|
+
apiCall.handle.cancel();
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
const callArgs = this.#parseArgs(toks.slice(1), scope);
|
|
1656
|
+
void apiCall.handle.call(isDict(callArgs[0]) ? callArgs[0] : undefined, this.apiCallListener(callArgs[1])).catch(() => { });
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
// timers
|
|
1661
|
+
if (callee === "setTimeout" || callee === "setInterval") {
|
|
1662
|
+
this.#timerStatement(callee, toks, scope);
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
if (callee === "clearTimeout" || callee === "clearInterval") {
|
|
1666
|
+
const args = this.#parseArgs(toks.slice(1), scope);
|
|
1667
|
+
const key = string(args[0]);
|
|
1668
|
+
const t = this.env.timers.get(key);
|
|
1669
|
+
if (t) {
|
|
1670
|
+
(t.interval ? clearInterval : clearTimeout)(t.id);
|
|
1671
|
+
this.env.timers.delete(key);
|
|
1672
|
+
}
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
// array mutations on a dotted path — INCLUDING the explicit dsx.variable.x.push
|
|
1676
|
+
// form (checked before the generic dsx.* dispatch); dsx.component.push (the router
|
|
1677
|
+
// verb), dsx.module.*.push, and dsx.action.<verb> (a point-to-point call to an
|
|
1678
|
+
// action named push/pop/sort/… — the natives strip the prefix and invoke it) are
|
|
1679
|
+
// excluded so they route as calls, not as an invalid store mutation.
|
|
1680
|
+
const dot = callee.lastIndexOf(".");
|
|
1681
|
+
const lastSeg = dot >= 0 ? callee.substring(dot + 1) : "";
|
|
1682
|
+
// `<url>.searchParams.set|append|delete(…)` mutates THROUGH the owning url, so `href` and
|
|
1683
|
+
// `search` stay true — the twin of JseRunner.kt's `receiver.endsWith(".searchParams")`
|
|
1684
|
+
// branch. Mutating the params dict on its own leaves the url advertising a query it no
|
|
1685
|
+
// longer has, and `href` is what callers pass to fetch/navigate.
|
|
1686
|
+
if (dot >= 0 && PARAM_VERBS.has(lastSeg)) {
|
|
1687
|
+
const receiver = callee.substring(0, dot);
|
|
1688
|
+
// A build without the JS-globals layer (__DSX_OPTIONAL_JS_GLOBALS__ false) can
|
|
1689
|
+
// never mint a {__url} dict, so the parent-walk is unreachable there; the same
|
|
1690
|
+
// define folds it, and core.ts's params/href plumbing tree-shakes behind it.
|
|
1691
|
+
if (globalThis
|
|
1692
|
+
.__DSX_OPTIONAL_JS_GLOBALS__ !== false && receiver.endsWith(".searchParams")) {
|
|
1693
|
+
const parent = receiver.substring(0, receiver.length - ".searchParams".length);
|
|
1694
|
+
const owner = readPath(this.env, scope, parent);
|
|
1695
|
+
const next = mutateURLSearchParams(owner, lastSeg, this.#parseArgs(toks.slice(1), scope));
|
|
1696
|
+
if (next !== null) {
|
|
1697
|
+
writePath(this.env, scope, parent, next);
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
// The statement form is the action body law with its answer discarded
|
|
1703
|
+
// (reference/jse.md): one hook, so a receiver that is not a writable
|
|
1704
|
+
// array keeps its pure meaning here exactly as it does inside an expression.
|
|
1705
|
+
if (globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false && dot >= 0 && ARRAY_MUTATORS.has(lastSeg) && this.arrayHook.accepts(callee.substring(0, dot), scope)) {
|
|
1706
|
+
this.mutateArray(callee.substring(0, dot), lastSeg, this.#parseArgs(toks.slice(1), scope), scope);
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
// dsx.* statement forms
|
|
1710
|
+
if (callee.startsWith("dsx.")) {
|
|
1711
|
+
await this.#dsxStatement(callee, toks, scope, false);
|
|
1712
|
+
return;
|
|
1713
|
+
}
|
|
1714
|
+
// THE BARE CALL OF A DECLARED ACTION IS RETIRED (S3 cut). `save()` in statement
|
|
1715
|
+
// position ran the `<action>`; `dsx.action.save()` is the spelling, handled above with
|
|
1716
|
+
// every other `dsx.` statement form. A bare `name()` now falls to "anything else:
|
|
1717
|
+
// evaluate as an expression" below, which answers null for a name nothing binds.
|
|
1718
|
+
// THE BARE CALL'S DETECTION WINDOW (Appendix E item 2). `name()` that matched no
|
|
1719
|
+
// `<action>` reached the expression evaluator, which read `name` as an identifier
|
|
1720
|
+
// nothing binds and answered null, so the documented fallback never ran on this lane.
|
|
1721
|
+
// Inside a try it is the same absence a missing module is and it throws the same
|
|
1722
|
+
// shape. The test is narrow on purpose and carries no roster: the call is an absence
|
|
1723
|
+
// only when it ANSWERED nothing AND its head is not a lambda the body holds, so an
|
|
1724
|
+
// expression builtin that returns a value is untouched, and the statement is
|
|
1725
|
+
// evaluated exactly once either way.
|
|
1726
|
+
if (dot < 0 && this.tryDepth > 0 && this.flow === null) {
|
|
1727
|
+
const answered = await this.evalMaybeAsync(toks, scope);
|
|
1728
|
+
if (this.flow === null && (answered === null || answered === undefined || answered === NSNull)
|
|
1729
|
+
&& !isLambda(this.evalSync([toks[0]], scope))) {
|
|
1730
|
+
this.flow = { kind: "throw", value: { code: ERROR_NOT_LOADED, call: callee } };
|
|
1731
|
+
}
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
// anything else: evaluate as an expression (await if it yields a promise)
|
|
1736
|
+
await this.evalMaybeAsync(toks, scope);
|
|
1737
|
+
}
|
|
1738
|
+
/** dsx.module / dsx.event / dsx.component / dsx.action / dsx.transition / dsx.log / dsx.error */
|
|
1739
|
+
async #dsxStatement(callee, toks, scope, awaited, waits = false) {
|
|
1740
|
+
const args = this.#parseArgs(toks.slice(1), scope);
|
|
1741
|
+
if (callee === "dsx.event") {
|
|
1742
|
+
const name = string(args[0]);
|
|
1743
|
+
// THE EMITTER'S IDENTITY TRAVELS WITH THE EVENT. Both native runners stamp
|
|
1744
|
+
// `__from = { type, name }` onto the payload of an event raised from inside an action
|
|
1745
|
+
// body (Stack.swift stampFrom, JseRunner.kt stampFrom) and read it back in the handler's
|
|
1746
|
+
// `from:` filter; this runner stamped nothing, so the identical `on:picked from:action`
|
|
1747
|
+
// markup filtered correctly on a phone and matched nothing at all on web. Never
|
|
1748
|
+
// overwrites a `__from` the author wrote, and an event raised outside any action is
|
|
1749
|
+
// unstamped - the same two rules the natives state.
|
|
1750
|
+
// A RUNNING CALL IS NEVER PASSED TO ANOTHER DOCUMENT (Article 14.2): an event whose payload carries one is
|
|
1751
|
+
// not raised, and the refusal settles like a failed call (constitution Article 14.2).
|
|
1752
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_DISPATCH__ !== false
|
|
1753
|
+
&& containsCallValue(args[1]))
|
|
1754
|
+
return await this.settleCall(notData("event"), "event", awaited, waits, () => null);
|
|
1755
|
+
const payload = stampFrom(isDict(args[1]) ? args[1] : {}, "action", this.#actionNames.at(-1));
|
|
1756
|
+
// a callback passed at the action call runs (native emitEventUp's callback path; payload
|
|
1757
|
+
// rides dsx.this) — but the wildcard/recorder and the bus still see EVERY event, callback
|
|
1758
|
+
// or not: native fires anyHandlers + publishNative "consumed or not" (Stack.swift /
|
|
1759
|
+
// JseRunner.kt), and emitEvent is the web wildcard analogue. So the callback is ADDITIVE,
|
|
1760
|
+
// never a suppressor of the broadcast.
|
|
1761
|
+
const cb = this.#actionEvents?.[name];
|
|
1762
|
+
if (globalThis.__DSX_OPTIONAL_LAMBDAS__ !== false && isLambda(cb))
|
|
1763
|
+
await this.runLambdaInline(cb, payload, name);
|
|
1764
|
+
// THE RELAY PAYLOAD LAW: the raising scope travels with a bare event, so the consumer's
|
|
1765
|
+
// on:<name> can read the row it came from. The BUS below stays payload only.
|
|
1766
|
+
this.env.emitEvent(name, payload, scope, this.#codeOwners.at(-1));
|
|
1767
|
+
DSXEvents.publish(name, payload);
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
// `dsx.send` AND `dsx.broadcast` ARE NOT DOCUMENT VERBS (system audit S4). A document
|
|
1771
|
+
// raises one event and it is `dsx.event`, which already reaches all three destinations:
|
|
1772
|
+
// the consumer's `on:<name>`, the app wide bus, and a native `ui.on` host when no
|
|
1773
|
+
// consumer claims it. The two extra spellings looked like aliases of it and were not:
|
|
1774
|
+
// this runner published both to the bus, while Stack.swift ran only the in process `ui.on`
|
|
1775
|
+
// handler for `send` and only the cross package bus for `broadcast`. One word, three
|
|
1776
|
+
// destinations, depending on the phone in the reader's hand. They are gone from the
|
|
1777
|
+
// document grammar on all three runners, with no alias and no warning release, and the
|
|
1778
|
+
// linter names them (`dsx-send-retired`, `dsx-broadcast-retired`). `dsx.broadcast` stays
|
|
1779
|
+
// what it always was on the MODULE bus: a verb on a native module's own `dsx` handle.
|
|
1780
|
+
// THE KERNEL'S OWN STATEMENT VERBS (`__DSX_OPTIONAL_STATEMENT_VERBS__`, cli embed/entry.ts
|
|
1781
|
+
// registryUsesStatementVerbs): `dsx.error`, `dsx.log`, `dsx.screen.settled`, `dsx.component.*` and `dsx.stop`.
|
|
1782
|
+
// A callee is the dotted token the body spells, so a slice whose text spells none of the five can take none of
|
|
1783
|
+
// these arms; with the flag folded they fall away whole, and with them the call settle `dsx.stop` shares.
|
|
1784
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ !== false && callee === "dsx.error") {
|
|
1785
|
+
// The AMBIENT error hat in markup (error-system.md §3.4) — a markup action never holds
|
|
1786
|
+
// a call to settle, so this is always the emission form: records to the ledger and fans
|
|
1787
|
+
// out (module.error hook, page channel + dsx mirror, global.dsx.* keys). NEVER unwinds
|
|
1788
|
+
// control flow — it is not a throw, it records; the statement after it still runs.
|
|
1789
|
+
const code = string(args[0]) || "error";
|
|
1790
|
+
const opts = isDict(args[1]) ? args[1] : {};
|
|
1791
|
+
ModuleRegistry.reportAmbientError(this.env.ownerScheme ?? "app", code, {
|
|
1792
|
+
message: opts["message"] === undefined || opts["message"] === null ? null : string(opts["message"]),
|
|
1793
|
+
recoverable: truthy(opts["recoverable"]),
|
|
1794
|
+
data: opts["data"],
|
|
1795
|
+
});
|
|
1796
|
+
return null;
|
|
1797
|
+
}
|
|
1798
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ !== false && callee === "dsx.log") {
|
|
1799
|
+
// The unified console primitive (logs corpus): console.log-shaped variadic args,
|
|
1800
|
+
// house formatting (JSE coercions + canonical JSON + credential masking), recorded
|
|
1801
|
+
// in the log ring attributed to the surface's owning scheme + one console mirror
|
|
1802
|
+
// line. Records, never unwinds, never throws.
|
|
1803
|
+
reportLog(this.env.ownerScheme ?? "app", "log", formatLogArgs(args));
|
|
1804
|
+
return null;
|
|
1805
|
+
}
|
|
1806
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ !== false && callee === "dsx.screen.settled") {
|
|
1807
|
+
// The DEFERRED-READINESS report (screen-lifecycle.md; corpus lifecycle/readiness.json):
|
|
1808
|
+
// "this screen has settled". Zero-arg, past tense — a REPORT, never a request. It is a
|
|
1809
|
+
// CALL and never collides with the reactive PROPERTIES `dsx.screen.ready` (Bool) /
|
|
1810
|
+
// `dsx.screen.phase` (String), which stay read-only state. The machine decides whether
|
|
1811
|
+
// anything fires (once per frame, an explicit settle always wins), so this records and
|
|
1812
|
+
// never unwinds — same shape as dsx.log. Outside a router frame there is nothing to
|
|
1813
|
+
// settle, which is a documented silent no-op (Article 7, fail-open).
|
|
1814
|
+
if (this.env.frameId !== undefined)
|
|
1815
|
+
RunnerScreenSeam.settled?.(this.env.frameId);
|
|
1816
|
+
return null;
|
|
1817
|
+
}
|
|
1818
|
+
if (callee === "dsx.wait") {
|
|
1819
|
+
// THE AWAITABLE DELAY. There was no
|
|
1820
|
+
// way to spell "and then, a moment later" in an action body on any runner: `setTimeout`
|
|
1821
|
+
// takes a lambda, and a lambda runs as its own top level entry, so the statements after
|
|
1822
|
+
// it are not the continuation of the body that scheduled it. This is that continuation.
|
|
1823
|
+
//
|
|
1824
|
+
// It is one of the awaitable verbs because the ONLY thing it does is suspend: an
|
|
1825
|
+
// unawaited `dsx.wait(50)` has nothing to observe, so it answers null at once rather
|
|
1826
|
+
// than scheduling a delay nobody is waiting on. The argument is read as milliseconds,
|
|
1827
|
+
// a negative or unreadable one is zero, and the ceiling is WAIT_BOUND_MS. The verb
|
|
1828
|
+
// answers null on every path, so a body may write `await dsx.wait(30)` as a statement
|
|
1829
|
+
// and never bind it.
|
|
1830
|
+
// `awaited` is true only through evalMaybeAsync's await routing, which is the
|
|
1831
|
+
// `__DSX_OPTIONAL_ASYNC_EXPRESSIONS__` block: with it folded the verb is the unawaited null below.
|
|
1832
|
+
if (!awaited || globalThis.__DSX_OPTIONAL_ASYNC_EXPRESSIONS__ === false)
|
|
1833
|
+
return null;
|
|
1834
|
+
const ms = Math.min(Math.max(safeInt(number(args[0]) ?? 0), 0), _a.WAIT_BOUND_MS);
|
|
1835
|
+
{
|
|
1836
|
+
const wait = new Promise((resolve) => setTimeout(resolve, ms));
|
|
1837
|
+
await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(wait) : wait);
|
|
1838
|
+
}
|
|
1839
|
+
return null;
|
|
1840
|
+
}
|
|
1841
|
+
// A callee is the dotted token the body spells, so a slice whose text never spells `dsx.transition`
|
|
1842
|
+
// (`__DSX_OPTIONAL_VIEW_TRANSITIONS__` false, registryUsesViewTransitions) can never take this arm.
|
|
1843
|
+
if (globalThis.__DSX_OPTIONAL_VIEW_TRANSITIONS__ !== false
|
|
1844
|
+
&& (callee === "dsx.transition" || callee === "dsx.transition.skip")) {
|
|
1845
|
+
return await this.transitionStatement(callee, args, awaited);
|
|
1846
|
+
}
|
|
1847
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ !== false && callee.startsWith("dsx.component.")) {
|
|
1848
|
+
const verb = callee.substring("dsx.component.".length);
|
|
1849
|
+
// FOUR VERBS, THE SAME FOUR ON EVERY RUNNER. `pop` was a fifth one here and nowhere
|
|
1850
|
+
// else: both native runners log it and no-op (Stack.swift, JseRunner.kt), so a document
|
|
1851
|
+
// that spelled it moved the stack on web and did nothing on a phone. Popping is the
|
|
1852
|
+
// router's word, `dsx.module.route.pop()`, and this list is the component's.
|
|
1853
|
+
// A RUNNING CALL IS NEVER PASSED TO ANOTHER DOCUMENT (Article 14.2): a presentation whose arguments carry one
|
|
1854
|
+
// is not made, and the refusal settles like a failed call (Article 28.13). Twins: JseRunner.kt, Stack.swift.
|
|
1855
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_DISPATCH__ !== false
|
|
1856
|
+
&& verb !== "dismiss" && containsCallValue(args))
|
|
1857
|
+
return await this.settleCall(notData("component"), "component", awaited, waits, () => null);
|
|
1858
|
+
if (["push", "present", "update", "dismiss"].includes(verb)) {
|
|
1859
|
+
this.env.component(verb, string(args[0] ?? ""), isDict(args[1]) ? args[1] : {});
|
|
1860
|
+
}
|
|
1861
|
+
else {
|
|
1862
|
+
// ONE SENTENCE, on every runner (Conformance/router/component-verbs.json
|
|
1863
|
+
// `refusalContains`): the three used to write three different lines for one law.
|
|
1864
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
1865
|
+
console.warn(`[dsx runner] dsx.component.${verb} is not a markup verb (push / present / update / dismiss); ignored`);
|
|
1866
|
+
}
|
|
1867
|
+
return null;
|
|
1868
|
+
}
|
|
1869
|
+
// A CONTEXT CALL (PROPOSED, proposals/context.md decision 6). The provider's body runs
|
|
1870
|
+
// against the PROVIDER's store and action table - otherwise `dsx.variable.*` inside it
|
|
1871
|
+
// would read the consumer's store, which is the whole point of the primitive being
|
|
1872
|
+
// ambient PROVIDER state - and it enters through `callAction(..., { entry: true })`,
|
|
1873
|
+
// the shape the WebMCP dispatch already uses: under `entry` a declared input NAMES A
|
|
1874
|
+
// PAYLOAD KEY rather than an expression to compute, which is exactly right across
|
|
1875
|
+
// documents. The consumer supplies the payload, evaluated in ITS scope by `parseArgs`,
|
|
1876
|
+
// and no expression of the provider's is ever evaluated in the consumer's scope.
|
|
1877
|
+
//
|
|
1878
|
+
// THE LEDGERS ARE THE CALLER'S, and they are swapped in and restored around the frame.
|
|
1879
|
+
// `callAction` deliberately does not take the entry lock (see runExclusive's header: an
|
|
1880
|
+
// entry lock across runners stalls for ENTRY_LOCK_BOUND_MS and then zeroes the
|
|
1881
|
+
// provider's ledgers), and `loopWork.count` is per-env and never reset by `callAction` -
|
|
1882
|
+
// so without this swap a context call would inherit whatever loop budget the provider
|
|
1883
|
+
// has already spent on its own in-flight entry, and would spend it further.
|
|
1884
|
+
if (globalThis
|
|
1885
|
+
.__DSX_OPTIONAL_CONTEXT__ !== false && callee.startsWith("dsx.context.")) {
|
|
1886
|
+
const spelling = callee.substring("dsx.context.".length);
|
|
1887
|
+
// A provider's action runs in the provider's document, so inputs that carry a running call are refused
|
|
1888
|
+
// before anything is looked up (Article 14.2), settled like a failed call. Twins: JseRunner.kt, Stack.swift.
|
|
1889
|
+
if (containsCallValue(args))
|
|
1890
|
+
return await this.settleCall(notData("context"), spelling, awaited, waits, () => null);
|
|
1891
|
+
const bound = this.env.contexts?.get(spelling);
|
|
1892
|
+
// A CALL ON A VALUE THE PLANE CARRIES (proposals/context-api-envelope.md Decision 2):
|
|
1893
|
+
// `dsx.context.feed()` or `dsx.context.feed.cancel()` on an enrolled <api> invokes the
|
|
1894
|
+
// provider's request and moves its envelope, which is a WRITE to the provider's state.
|
|
1895
|
+
// Refused by name with the `context_write` phrase, and nothing moves; the provider
|
|
1896
|
+
// enrols an <action> that calls its api, and the consumer calls that.
|
|
1897
|
+
if (bound === undefined) {
|
|
1898
|
+
const segs = spelling.split(".");
|
|
1899
|
+
const plane = this.env.store.jse.contexts;
|
|
1900
|
+
const value = plane?.get(`${segs[0]}.${segs[1] ?? ""}`) ?? plane?.get(segs[0]);
|
|
1901
|
+
if (value !== undefined) {
|
|
1902
|
+
console.warn(`[dsx runner] dsx.context is read-only: dsx.context.${spelling}() calls a value `
|
|
1903
|
+
+ "the provider owns, and an <api> invoke would move its envelope — expose an <action> on "
|
|
1904
|
+
+ "the provider that invokes it, and call that");
|
|
1905
|
+
return null;
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
if (bound === undefined) {
|
|
1909
|
+
// The universal feature-detection law: inside a try, a name nothing provides is the
|
|
1910
|
+
// SAME absence as a module that is not in this build, so one guard covers both.
|
|
1911
|
+
if (this.tryDepth > 0 && this.flow === null) {
|
|
1912
|
+
this.flow = { kind: "throw", value: { code: ERROR_NOT_LOADED, call: spelling } };
|
|
1913
|
+
return null;
|
|
1914
|
+
}
|
|
1915
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
1916
|
+
console.warn(`[dsx runner] no context provides ${spelling} — add it to <context use=> and provide the key above`);
|
|
1917
|
+
return null;
|
|
1918
|
+
}
|
|
1919
|
+
const argObj = isDict(args[0]) ? args[0] : {};
|
|
1920
|
+
const provider = bound.runner;
|
|
1921
|
+
const providerEnv = provider.env;
|
|
1922
|
+
let value = null;
|
|
1923
|
+
// ONE CALL IS ONE FRAME ON THE PROVIDER. Sibling consumers call in the same frame (every
|
|
1924
|
+
// tab of a set enrols on appear), each from its own runner; this runner awaits between
|
|
1925
|
+
// statements, so without the queue two calls interleaved and each read-modify-write lost
|
|
1926
|
+
// the other's write. Kotlin and Swift run a call to completion. The queue is the
|
|
1927
|
+
// provider's own and resets no ledger (unlike runExclusive), and it is bounded the same
|
|
1928
|
+
// way: a call suspended on a module that never settles releases the next one.
|
|
1929
|
+
await contextFrame(provider, async () => {
|
|
1930
|
+
const savedDepth = providerEnv.actionDepth;
|
|
1931
|
+
const savedLoop = providerEnv.loopWork;
|
|
1932
|
+
const savedBudget = providerEnv.callBudget;
|
|
1933
|
+
providerEnv.actionDepth = this.env.actionDepth;
|
|
1934
|
+
providerEnv.loopWork = this.env.loopWork;
|
|
1935
|
+
if (this.env.callBudget !== undefined)
|
|
1936
|
+
providerEnv.callBudget = this.env.callBudget;
|
|
1937
|
+
try {
|
|
1938
|
+
value = await provider.callAction(bound.name, {}, null, argObj, { entry: true });
|
|
1939
|
+
}
|
|
1940
|
+
finally {
|
|
1941
|
+
providerEnv.actionDepth = savedDepth;
|
|
1942
|
+
providerEnv.loopWork = savedLoop;
|
|
1943
|
+
providerEnv.callBudget = savedBudget;
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
// A THROW INSIDE THE PROVIDER'S BODY IS THE CALLER'S EXCEPTION, because the call is a
|
|
1947
|
+
// frame of the caller's entry: it moves onto this runner so the consumer's try/catch
|
|
1948
|
+
// is the one that sees it, and the provider is left clean rather than holding a flow
|
|
1949
|
+
// its own next entry would inherit.
|
|
1950
|
+
if (provider.threw()) {
|
|
1951
|
+
const thrown = provider.flow;
|
|
1952
|
+
provider.flow = null;
|
|
1953
|
+
this.flow = thrown;
|
|
1954
|
+
return null;
|
|
1955
|
+
}
|
|
1956
|
+
if (awaited)
|
|
1957
|
+
return value ?? null;
|
|
1958
|
+
return null;
|
|
1959
|
+
}
|
|
1960
|
+
if (globalThis.__DSX_OPTIONAL_NAMED_ACTIONS__ !== false && callee.startsWith("dsx.action.") && !isArgumentRead(callee)) {
|
|
1961
|
+
const name = callee.substring("dsx.action.".length);
|
|
1962
|
+
const argObj = isDict(args[0]) ? args[0] : {};
|
|
1963
|
+
// 2nd arg = event callbacks: `dsx.action.x(args, { done: () => … })`. They frame the
|
|
1964
|
+
// callee so an event it raises invokes the caller's callback (native store.actionEvents),
|
|
1965
|
+
// saved/restored so a nested action's callbacks don't leak into the caller's.
|
|
1966
|
+
const handlers = isDict(args[1]) ? args[1] : null;
|
|
1967
|
+
if (!awaited && this.entry !== null && this.env.actions.has(name)
|
|
1968
|
+
&& globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false) {
|
|
1969
|
+
await this.startUnawaited(name, argObj, scope, handlers);
|
|
1970
|
+
return null;
|
|
1971
|
+
}
|
|
1972
|
+
const savedEvents = this.#actionEvents;
|
|
1973
|
+
this.ownCallbacks(handlers);
|
|
1974
|
+
if (handlers !== null)
|
|
1975
|
+
this.#actionEvents = handlers;
|
|
1976
|
+
let value = null;
|
|
1977
|
+
try {
|
|
1978
|
+
value = await this.callAction(name, argObj, scope, {});
|
|
1979
|
+
}
|
|
1980
|
+
finally {
|
|
1981
|
+
this.#actionEvents = savedEvents;
|
|
1982
|
+
}
|
|
1983
|
+
// RETURNING ACTIONS (actions corpus): an AWAITED sibling call answers THE VALUE THE
|
|
1984
|
+
// SIBLING RETURNED, the way a function call reads, and a failed sibling throws the way a
|
|
1985
|
+
// thrown body already does. `return null` when it never returned.
|
|
1986
|
+
//
|
|
1987
|
+
// IT USED TO BIND THE MODULE ENVELOPE, `{ ok: true, data: <the return value> }`, and the
|
|
1988
|
+
// shape was invisible at the call site. An action that returns its own `{ ok, refusal }`
|
|
1989
|
+
// verdict then had TWO `ok` fields one level apart, and `if (!who.ok)` read the
|
|
1990
|
+
// envelope's, which is true whatever the action decided:
|
|
1991
|
+
//
|
|
1992
|
+
// PROBE 418 {"who":{"ok":true,"data":{"ok":true,"account":{...}}},"t":"object"}
|
|
1993
|
+
//
|
|
1994
|
+
// POST /v1/apps with no bearer token registered an app at 201 instead of refusing at 401,
|
|
1995
|
+
// and every line of the document read correctly. The envelope is defensible for a MODULE,
|
|
1996
|
+
// whose failure is a seam's and whose only error channel is that `ok`; it is not right for
|
|
1997
|
+
// an action in the same document, whose failure is already the document's own `throw`.
|
|
1998
|
+
// `dsx.module.*` keeps the envelope, and keeps it for the reason it has one.
|
|
1999
|
+
if (awaited && !this.threw())
|
|
2000
|
+
return value ?? null;
|
|
2001
|
+
return null;
|
|
2002
|
+
}
|
|
2003
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_CALLS__ !== false && callee.startsWith("dsx.module.")) {
|
|
2004
|
+
// The FULL dotted remainder rides to the ONE funnel — the bus FOLD resolves module
|
|
2005
|
+
// identity vs action path (OpenSource/Conformance/chains); the runner never assumes
|
|
2006
|
+
// the legacy scheme.method two-segment shape (a nested chain's call folds there).
|
|
2007
|
+
const rest = callee.substring("dsx.module.".length);
|
|
2008
|
+
// A CONTROL OF A CALL THIS DOCUMENT HOLDS (constitution Article 23.6; corpus held-calls/document-stop.json):
|
|
2009
|
+
// `dsx.module.<chain>.<action>.<control>(call, args)`, the spelling the page bridge and the package lanes
|
|
2010
|
+
// have (context-and-event-delivery.md). The call is the control's target, not its data, so it is not
|
|
2011
|
+
// refused here; the control's own arguments are data and a call in them is. Its second argument is the
|
|
2012
|
+
// control's arguments, never a callback map. A call this document did not start answers `call_ended`,
|
|
2013
|
+
// as `dsx.stop` does. It settles like a module call. Twins: JseRunner.kt, Stack.swift `heldControl`.
|
|
2014
|
+
// `self` names the owning package BEFORE the path is read as a control, as the natives resolve it before
|
|
2015
|
+
// theirs (JseRunner.kt packageOp, Stack.swift): `dsx.module.self.<action>.<control>(call, args)` is the
|
|
2016
|
+
// same control on every lane (corpus: the `owner` row).
|
|
2017
|
+
const owned = ownedPath(this.env, rest);
|
|
2018
|
+
if (ModuleRegistry.namesControl(args[0], owned)) {
|
|
2019
|
+
return await this.settleCall(controlCall(this.env, args, owned), owned, awaited, waits, () => null);
|
|
2020
|
+
}
|
|
2021
|
+
const authoredArgs = isDict(args[0]) ? args[0] : {};
|
|
2022
|
+
// A RUNNING CALL IS NEVER SENT (Article 14.2): a module call whose arguments carry one is not sent, and the
|
|
2023
|
+
// refusal settles like any failed call (constitution Article 14.2). Twins: JseRunner.kt, Stack.swift.
|
|
2024
|
+
if (containsCallValue(authoredArgs))
|
|
2025
|
+
return await this.settleCall(notData(rest), rest, awaited, waits, () => null);
|
|
2026
|
+
// Internal framing wins over any authored lookalike. ActionContext.args() hides
|
|
2027
|
+
// `__*` keys from whole-object reads while frame-aware modules may request the
|
|
2028
|
+
// exact key, the same wire contract used by the native statement runners.
|
|
2029
|
+
const argObj = this.env.frameId === undefined
|
|
2030
|
+
? authoredArgs
|
|
2031
|
+
: { ...authoredArgs, __frame: this.env.frameId };
|
|
2032
|
+
// A CALL THE DOCUMENT HOLDS (Conformance/held-calls/document-stop.json, constitution Article 14.2):
|
|
2033
|
+
// an unawaited call with its callback map answers the call's value, which a local or a declared
|
|
2034
|
+
// variable holds so the document can `dsx.stop` it; this surface's unmount stops it (Article 20.4).
|
|
2035
|
+
// The awaited form keeps its envelope.
|
|
2036
|
+
// The callback map is the second argument whenever it is an object, `{}` included (runtime.js `toHandler`:
|
|
2037
|
+
// an object is a handler map). The bound is the page bridge's (runtime.js `MAX_PENDING`): past it the call is
|
|
2038
|
+
// refused `pending_limit_exceeded`, nothing is sent, and the statement settles like any failed call.
|
|
2039
|
+
let held = null;
|
|
2040
|
+
const holding = !awaited && isDict(args[1]);
|
|
2041
|
+
if (holding && !this.env.store.canHoldCall()) {
|
|
2042
|
+
const refused = Promise.reject(new ModuleCallError("pending_limit_exceeded", `too many live calls held by this document (limit ${ReactiveStore.HELD_CALL_BOUND})`, null));
|
|
2043
|
+
return await this.settleCall(refused, rest, awaited, waits, () => null);
|
|
2044
|
+
}
|
|
2045
|
+
const hold = holding
|
|
2046
|
+
? (call) => { held = call; this.env.store.holdCall(call); }
|
|
2047
|
+
: undefined;
|
|
2048
|
+
const promise = this.callModuleFunnel(rest, argObj, this.moduleCallListener(args[1]), hold);
|
|
2049
|
+
return await this.settleCall(promise, rest, awaited, waits, () => held);
|
|
2050
|
+
}
|
|
2051
|
+
// `dsx.stop(call)`: stop listening to a call THIS document started and holds, through the bus's own
|
|
2052
|
+
// stop (its `onStop` runs, its stream ends; never a cancel). Stopping twice or after the call ended
|
|
2053
|
+
// is a no-op; any other value, a call another document started included, answers `call_ended`, the
|
|
2054
|
+
// refusal the page and the module bus give (context-and-event-delivery.md), so a mistaken stop is
|
|
2055
|
+
// never silent. It settles like a module call: the envelope when awaited.
|
|
2056
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ !== false && callee === "dsx.stop") {
|
|
2057
|
+
const target = args[0];
|
|
2058
|
+
const promise = this.env.store.holdsCall(target)
|
|
2059
|
+
? ModuleRegistry.stop(target)
|
|
2060
|
+
: Promise.reject(new ModuleCallError("call_ended", "Not a call this document started and holds.", null));
|
|
2061
|
+
return await this.settleCall(promise, "stop", awaited, waits, () => null);
|
|
2062
|
+
}
|
|
2063
|
+
return await this.#evalDsxRest(callee, toks, scope);
|
|
2064
|
+
}
|
|
2065
|
+
/** THE SETTLE OF A CALL STATEMENT, shared by `dsx.module.*` and `dsx.stop`: awaited it binds the
|
|
2066
|
+
* envelope and never throws; unawaited outside a `try` the handler goes on and a failure reports like
|
|
2067
|
+
* an unhandled rejection; otherwise it waits and a failure throws `{ code, call, message? }`. An
|
|
2068
|
+
* unawaited statement answers `answer()` (the held call's value, or null). */
|
|
2069
|
+
async settleCall(promise, rest, awaited, waits, answer) {
|
|
2070
|
+
// BLOCK-FORM FOLD. Every caller but `dsx.stop` settles a refused or a running call, and a call value exists only
|
|
2071
|
+
// where the bus dispatches (`__DSX_OPTIONAL_MODULE_DISPATCH__`, which module calls imply); `dsx.stop` is a
|
|
2072
|
+
// statement verb (`__DSX_OPTIONAL_STATEMENT_VERBS__`). With both folded no caller remains.
|
|
2073
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_DISPATCH__ === false
|
|
2074
|
+
&& globalThis.__DSX_OPTIONAL_STATEMENT_VERBS__ === false)
|
|
2075
|
+
return null;
|
|
2076
|
+
if (awaited) {
|
|
2077
|
+
// An awaited module call binds the ENVELOPE, never the raw payload, and never
|
|
2078
|
+
// throws — identical to the native runners (Stack.swift continueAwaitPackage /
|
|
2079
|
+
// JseRunner.kt): resolve → { ok:true, data }, error → { ok:false, error[, data] }.
|
|
2080
|
+
// The same shape `await fetch(...)` already binds, so a portable `.dsx` action
|
|
2081
|
+
// (`const r = await dsx.module.x.y(); r.ok ? r.data : r.error`) reads the same on
|
|
2082
|
+
// every renderer instead of hitting an undefined `.ok` and aborting on web.
|
|
2083
|
+
try {
|
|
2084
|
+
const data = await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(promise) : promise);
|
|
2085
|
+
return { ok: true, data: data ?? null };
|
|
2086
|
+
}
|
|
2087
|
+
catch (e) {
|
|
2088
|
+
// THE DETECTION WINDOW (Appendix E item 2). Inside a try, an absent module throws
|
|
2089
|
+
// rather than binding the envelope, because that is what the documented fallback
|
|
2090
|
+
// catches. The envelope stays the answer everywhere else, so a body that reads
|
|
2091
|
+
// `r.ok` outside a try reads exactly what it always did.
|
|
2092
|
+
if (e instanceof ModuleCallError && e.code === ERROR_NOT_LOADED && this.tryDepth > 0
|
|
2093
|
+
&& this.flow === null) {
|
|
2094
|
+
this.flow = { kind: "throw", value: { code: ERROR_NOT_LOADED, call: rest } };
|
|
2095
|
+
return null;
|
|
2096
|
+
}
|
|
2097
|
+
if (e instanceof ModuleCallError) {
|
|
2098
|
+
const env = { ok: false, error: e.code };
|
|
2099
|
+
// THE SENTENCE TRAVELS WITH THE CODE, and it did not used to.
|
|
2100
|
+
//
|
|
2101
|
+
// `{ ok: false, error }` was the whole refusal, so every seam that had something to
|
|
2102
|
+
// SAY had to smuggle it: `service_not_declared` carries the route and the entity as
|
|
2103
|
+
// `data` for exactly this reason (server/actions.ts says so at the throw), and a
|
|
2104
|
+
// transport refusal whose only useful half is a vendor's own explanation had no
|
|
2105
|
+
// channel at all. The non-ModuleCallError branch below has always carried a
|
|
2106
|
+
// `message`, so a body reading `r.message` was already reading one shape and getting
|
|
2107
|
+
// it on the accidental path and not on the typed one.
|
|
2108
|
+
//
|
|
2109
|
+
// It is ADDITIVE: `ok` and `error` are unchanged, `data` is unchanged, and nothing
|
|
2110
|
+
// that branched on the code branches differently. An empty message adds no key, so a
|
|
2111
|
+
// refusal that never had a sentence still answers the two fields it always did.
|
|
2112
|
+
if (typeof e.message === "string" && e.message !== "")
|
|
2113
|
+
env.message = e.message;
|
|
2114
|
+
if (e.data !== null && e.data !== undefined)
|
|
2115
|
+
env.data = e.data;
|
|
2116
|
+
return env;
|
|
2117
|
+
}
|
|
2118
|
+
return { ok: false, error: "error", message: String(e) };
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
// WITHOUT `await`, OUTSIDE A `try`, THE CALL IS SENT AND THE HANDLER GOES ON (JSE follows
|
|
2122
|
+
// JavaScript, Conformance/actions `unawaited-module-*`): its failure is reported like an
|
|
2123
|
+
// unhandled rejection. Inside a `try` the statement keeps waiting for its verdict, so the
|
|
2124
|
+
// try stays the feature-detection window it is documented to be.
|
|
2125
|
+
if (!awaited && !waits && this.tryDepth === 0 && this.entry !== null
|
|
2126
|
+
&& globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false) {
|
|
2127
|
+
const body = this.#entryBody;
|
|
2128
|
+
const sent = promise.then(() => undefined, (e) => {
|
|
2129
|
+
const current = this.#entryBody;
|
|
2130
|
+
this.#entryBody = body;
|
|
2131
|
+
this.#reportUncaught(failedCall(e, rest));
|
|
2132
|
+
this.#entryBody = current;
|
|
2133
|
+
});
|
|
2134
|
+
const root = this.entry.root ?? this.entry;
|
|
2135
|
+
const strands = root.strands ?? (root.strands = new Set());
|
|
2136
|
+
strands.add(sent);
|
|
2137
|
+
void sent.finally(() => strands.delete(sent));
|
|
2138
|
+
return answer();
|
|
2139
|
+
}
|
|
2140
|
+
// A FAILED CALL STOPS THE HANDLER UNLESS A `try` HANDLES IT
|
|
2141
|
+
// (jse.md "A failed module call"). The statement waits for the call's verdict
|
|
2142
|
+
// and a failure throws `{ code, call, message? }`: a `catch` sees it, and with none the
|
|
2143
|
+
// handler stops at that statement, so nothing after it runs (a failed Copy never shows
|
|
2144
|
+
// "Copied"). The uncaught throw reports through the ledger (origin "uncaught"), which a
|
|
2145
|
+
// development build surfaces and a release build sends as telemetry. It used to be
|
|
2146
|
+
// discarded outside a try, and a failed copy went on to say it had worked.
|
|
2147
|
+
try {
|
|
2148
|
+
await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(promise) : promise);
|
|
2149
|
+
}
|
|
2150
|
+
catch (e) {
|
|
2151
|
+
if (this.flow === null)
|
|
2152
|
+
this.flow = { kind: "throw", value: failedCall(e, rest) };
|
|
2153
|
+
return null;
|
|
2154
|
+
}
|
|
2155
|
+
return answer();
|
|
2156
|
+
}
|
|
2157
|
+
/** The `dsx.` statement forms after the verbs above: a method on a spelled value, or an unknown plane. */
|
|
2158
|
+
async #evalDsxRest(_callee, toks, scope) {
|
|
2159
|
+
// `dsx.state.set(name, value)` WAS HERE, and it was this runner's alone: no native runner
|
|
2160
|
+
// had it (both fell to the legacy package dispatcher on the reserved scheme `dsx` and
|
|
2161
|
+
// answered unknown_action), no corpus row pinned it, no document spelled it and no
|
|
2162
|
+
// reference taught it for markup. A document write to the app store is `dsx.global.x = v`,
|
|
2163
|
+
// which `writePath` has always routed to DSXState.set, on every runner.
|
|
2164
|
+
// A METHOD ON A SPELLED VALUE IS NOT A `dsx` VERB (S3 cut). `d1.setTime(172800000)` is
|
|
2165
|
+
// `dsx.variable.d1.setTime(172800000)` now, and a statement that begins `dsx.` reached
|
|
2166
|
+
// this function, which knew every verb and no methods - so the date mutated nowhere and
|
|
2167
|
+
// the corpus row `date-set-time-statement-persists` read the old instant back. The bare
|
|
2168
|
+
// form fell to the expression evaluator, which is where the value object mutation lives
|
|
2169
|
+
// (jse/core.ts, `d["__date"] = next`), so the spelled form falls there too. The verbs
|
|
2170
|
+
// above all returned before this line; an unknown `dsx.` plane normalizes to no path and
|
|
2171
|
+
// the expression answers null, which is what a read of the same spelling answers, and
|
|
2172
|
+
// `dsx-unknown-plane` names it before the build.
|
|
2173
|
+
return await this.evalMaybeAsync(toks, scope);
|
|
2174
|
+
}
|
|
2175
|
+
/** `dsx.transition(update, options?)` and `dsx.transition.skip()`, THE JSE DOOR ONTO VIEW
|
|
2176
|
+
* TRANSITIONS. The door itself is view-transition-door.ts; this is the runner's side of it
|
|
2177
|
+
* (the lambda run with its throw captured, the frame id) and the EMBED FOLD: a self-contained
|
|
2178
|
+
* widget whose markup never spells `dsx.transition` ships neither the door nor the pure folds
|
|
2179
|
+
* behind it (embed-entry.ts `viewTransitions`), and the call still runs the update and answers
|
|
2180
|
+
* the unsupported lane, so the law holds with the plane folded out. */
|
|
2181
|
+
async transitionStatement(callee, args, awaited) {
|
|
2182
|
+
// The one arm that calls this reads the same flag (dsxStatement), so with the plane folded nothing reaches here.
|
|
2183
|
+
if (globalThis.__DSX_OPTIONAL_VIEW_TRANSITIONS__ !== false) {
|
|
2184
|
+
return await transitionDoor(this.transitionDoorHost(), callee, args, awaited);
|
|
2185
|
+
}
|
|
2186
|
+
return null;
|
|
2187
|
+
}
|
|
2188
|
+
/** Run an update lambda and CONSUME a throw into a message: the transition owns the throw,
|
|
2189
|
+
* the calling action goes on (the browser skips the transition and rejects `finished`). */
|
|
2190
|
+
async runCapturingThrow(fn) {
|
|
2191
|
+
if (globalThis.__DSX_OPTIONAL_LAMBDAS__ === false)
|
|
2192
|
+
return null;
|
|
2193
|
+
if (fn === null)
|
|
2194
|
+
return null;
|
|
2195
|
+
const savedFlow = this.flow;
|
|
2196
|
+
await this.runLambdaInline(fn, {});
|
|
2197
|
+
if (!this.threw())
|
|
2198
|
+
return null;
|
|
2199
|
+
const thrown = this.#currentFlow().value;
|
|
2200
|
+
this.flow = savedFlow;
|
|
2201
|
+
return string(thrown);
|
|
2202
|
+
}
|
|
2203
|
+
transitionDoorHost() {
|
|
2204
|
+
// MEMBER FOLD, a STOPGAP for design 3.2b (Article 17.4, backlog row EMBED-MEMBER-FOLDS-STOPGAP-1120): esbuild keeps
|
|
2205
|
+
// every class member, so a member whose only callers sit behind a fold keeps its body unless the body folds too.
|
|
2206
|
+
// Removed when 3.2b moves the member out of the class. Its one caller, transitionStatement, sits under `__DSX_OPTIONAL_VIEW_TRANSITIONS__`.
|
|
2207
|
+
// Block form: an early return would keep `runCapturingThrow` and `letGo` counted.
|
|
2208
|
+
if (globalThis.__DSX_OPTIONAL_VIEW_TRANSITIONS__ !== false) {
|
|
2209
|
+
return { frameId: this.env.frameId, runUpdate: async (fn) => {
|
|
2210
|
+
try {
|
|
2211
|
+
return await this.runCapturingThrow(fn);
|
|
2212
|
+
}
|
|
2213
|
+
finally {
|
|
2214
|
+
// The compositor captures when the update settles, before the outer
|
|
2215
|
+
// action finishes awaiting the animation. Publish the callback's final
|
|
2216
|
+
// state at that boundary, including writes made before a thrown error.
|
|
2217
|
+
if (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false)
|
|
2218
|
+
letGo(runnerHolds.get(this) ?? null);
|
|
2219
|
+
}
|
|
2220
|
+
} };
|
|
2221
|
+
}
|
|
2222
|
+
return null;
|
|
2223
|
+
}
|
|
2224
|
+
#timerStatement(callee, toks, scope) {
|
|
2225
|
+
if (globalThis.__DSX_OPTIONAL_LAMBDAS__ === false)
|
|
2226
|
+
return;
|
|
2227
|
+
const args = this.#parseArgs(toks.slice(1), scope);
|
|
2228
|
+
const fn = args[0];
|
|
2229
|
+
if (!isLambda(fn))
|
|
2230
|
+
return;
|
|
2231
|
+
const interval = callee === "setInterval";
|
|
2232
|
+
let ms = safeInt(number(args[1]) ?? 0);
|
|
2233
|
+
if (interval)
|
|
2234
|
+
ms = Math.max(ms, 250); // min interval — the reference floor
|
|
2235
|
+
const key = args.length > 2 ? string(args[2]) : `__anon_${this.env.timers.size}_${Math.random().toString(36).slice(2)}`;
|
|
2236
|
+
const existing = this.env.timers.get(key);
|
|
2237
|
+
if (existing) {
|
|
2238
|
+
(existing.interval ? clearInterval : clearTimeout)(existing.id);
|
|
2239
|
+
this.env.timers.delete(key);
|
|
2240
|
+
}
|
|
2241
|
+
const frame = this.env.frameId;
|
|
2242
|
+
const fire = () => {
|
|
2243
|
+
// a page out of view (FrameTimers.hold) does no timer work: the tick is kept and runs once when it comes back
|
|
2244
|
+
if (frame !== undefined && FrameTimers.defer(frame, key, fire))
|
|
2245
|
+
return;
|
|
2246
|
+
JSE.afterRender(() => {
|
|
2247
|
+
void this.invokeLambdaAsAction(fn, scope);
|
|
2248
|
+
});
|
|
2249
|
+
};
|
|
2250
|
+
const id = interval ? setInterval(fire, ms) : setTimeout(() => { this.env.timers.delete(key); fire(); }, ms);
|
|
2251
|
+
this.env.timers.set(key, { id, interval });
|
|
2252
|
+
}
|
|
2253
|
+
/** Timer/handler lambdas run as ACTION bodies (statements, store writes allowed) — a fresh
|
|
2254
|
+
* top-level entry, so it takes the same exclusive lock as run() (a timer must never fire
|
|
2255
|
+
* into the middle of a suspended handler's ledger). */
|
|
2256
|
+
async invokeLambdaAsAction(fn, scope) {
|
|
2257
|
+
if (globalThis.__DSX_OPTIONAL_LAMBDAS__ === false)
|
|
2258
|
+
return;
|
|
2259
|
+
if (fn.native) {
|
|
2260
|
+
fn.native([], scope);
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
await this.#runExclusive(async () => {
|
|
2264
|
+
// A CAPTURED NAME IS A BLOCK LOCAL (S3 cut). A lambda is written inside the block that
|
|
2265
|
+
// declared the names it closes over, so a `const next = 'b'` the caller declared is a
|
|
2266
|
+
// local wherever the lambda body reads it. The captured VALUES arrive through the
|
|
2267
|
+
// spread; the LEDGER does not, because it is a non-enumerable symbol, so it is rebuilt
|
|
2268
|
+
// here exactly as `callAction` and `JSE.callLambda` rebuild theirs. Without it every
|
|
2269
|
+
// free name in a timer body, a handler body or a `dsx.transition` update read null.
|
|
2270
|
+
const merged = { ...fn.captured, ...scope };
|
|
2271
|
+
for (const n of Object.keys(fn.captured))
|
|
2272
|
+
declareLocal(merged, n);
|
|
2273
|
+
for (const n of scopeLocalNames(scope))
|
|
2274
|
+
declareLocal(merged, n);
|
|
2275
|
+
const walker = new StmtWalker(fn.body);
|
|
2276
|
+
await this.runStatements(walker, merged, false);
|
|
2277
|
+
});
|
|
2278
|
+
}
|
|
2279
|
+
/** Run an action-event CALLBACK lambda inline within the CURRENT entry — it fires from
|
|
2280
|
+
* inside a running action (dsx.event), so it must NOT take the entry lock (that would
|
|
2281
|
+
* deadlock on the very entry it runs under); it nests under the shared 32-frame action
|
|
2282
|
+
* depth instead, like the native emitEventUp. The payload rides dsx.this. */
|
|
2283
|
+
/** THE CALL'S OWN HANDLERS (reference/jse.md): `dsx.api.<as>(args, { success,
|
|
2284
|
+
* error, message, progress })`, the action call's callback dict on the api call. Each callback
|
|
2285
|
+
* runs with the event's payload in `dsx.this`, additive to the tag's `on:*`. */
|
|
2286
|
+
/** A MODULE CALL'S OWN CALLBACKS (Conformance/actions
|
|
2287
|
+
* `module-late-event-*`): `dsx.module.x.y(args, { name: (e) => … })` runs `name` for every event
|
|
2288
|
+
* the handler raises for this call, before or after it settled, awaited or not, while the
|
|
2289
|
+
* calling component is mounted. A callback's throw is reported like an uncaught one. */
|
|
2290
|
+
moduleCallListener(handlers) {
|
|
2291
|
+
// BLOCK-FORM FOLD: the one caller is the `__DSX_OPTIONAL_MODULE_CALLS__` arm of dsxStatement.
|
|
2292
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_CALLS__ === false
|
|
2293
|
+
|| !isDict(handlers))
|
|
2294
|
+
return undefined;
|
|
2295
|
+
const table = handlers;
|
|
2296
|
+
const store = this.env.store;
|
|
2297
|
+
let chain = Promise.resolve();
|
|
2298
|
+
return (name, value) => {
|
|
2299
|
+
const cb = table[name];
|
|
2300
|
+
if (!isLambda(cb) || store.isDisposed)
|
|
2301
|
+
return;
|
|
2302
|
+
const payload = isDict(value) ? value : { value: value ?? NSNull };
|
|
2303
|
+
chain = chain.then(async () => {
|
|
2304
|
+
if (store.isDisposed)
|
|
2305
|
+
return;
|
|
2306
|
+
const saved = this.flow;
|
|
2307
|
+
this.flow = null;
|
|
2308
|
+
await this.runLambdaInline(cb, payload, name);
|
|
2309
|
+
const f = this.#currentFlow();
|
|
2310
|
+
if (f !== null && f.kind === "throw")
|
|
2311
|
+
this.#reportUncaught(f.value);
|
|
2312
|
+
this.flow = saved;
|
|
2313
|
+
}).catch(() => { });
|
|
2314
|
+
};
|
|
2315
|
+
}
|
|
2316
|
+
apiCallListener(handlers) {
|
|
2317
|
+
// BLOCK-FORM FOLD: both callers hold an `<api>` handle, which `__DSX_OPTIONAL_APIS__` false never yields.
|
|
2318
|
+
if (globalThis.__DSX_OPTIONAL_APIS__ === false
|
|
2319
|
+
|| !isDict(handlers))
|
|
2320
|
+
return undefined;
|
|
2321
|
+
const table = handlers;
|
|
2322
|
+
// the call's callbacks run IN ORDER, one after another, as its events arrived
|
|
2323
|
+
let chain = Promise.resolve();
|
|
2324
|
+
return (name, payload) => {
|
|
2325
|
+
const cb = table[name];
|
|
2326
|
+
if (isLambda(cb))
|
|
2327
|
+
chain = chain.then(() => this.runLambdaInline(cb, payload, name)).catch(() => { });
|
|
2328
|
+
return chain;
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
async runLambdaInline(fn, payload, event) {
|
|
2332
|
+
if (globalThis.__DSX_OPTIONAL_LAMBDAS__ === false)
|
|
2333
|
+
return;
|
|
2334
|
+
if (fn.native) {
|
|
2335
|
+
fn.native([], payload);
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
if (this.env.actionDepth >= 32) {
|
|
2339
|
+
console.warn("[dsx runner] event callback depth (32) exceeded — contained");
|
|
2340
|
+
return;
|
|
2341
|
+
}
|
|
2342
|
+
// The twin of `invokeLambdaAsAction`'s rebuild, and for the same reason (S3 cut): the
|
|
2343
|
+
// payload keys are NOT locals (they are `dsx.this.<key>`), but every name the callback
|
|
2344
|
+
// CAPTURED from the block that wrote it is.
|
|
2345
|
+
const scope = bindScopeThis({ ...fn.captured, ...payload }, payload);
|
|
2346
|
+
// A CALLBACK RUNS FOR AN EVENT, and reads it as `dsx.event.name` / `dsx.event.data` (D59 step 0).
|
|
2347
|
+
if (event !== undefined)
|
|
2348
|
+
bindScopeEvent(scope, event, payload);
|
|
2349
|
+
for (const n of Object.keys(fn.captured))
|
|
2350
|
+
declareLocal(scope, n);
|
|
2351
|
+
const savedFlow = this.flow;
|
|
2352
|
+
this.flow = null;
|
|
2353
|
+
this.env.actionDepth += 1;
|
|
2354
|
+
// A callback's code is its writer's (see `codeOwners`); one handed in from outside any action keeps the
|
|
2355
|
+
// running action as its owner.
|
|
2356
|
+
const owner = this.lambdaOwners.get(fn) ?? this.#codeOwners.at(-1);
|
|
2357
|
+
if (owner !== undefined)
|
|
2358
|
+
this.#codeOwners.push(owner);
|
|
2359
|
+
try {
|
|
2360
|
+
await this.runStatements(new StmtWalker(fn.body), scope, false);
|
|
2361
|
+
}
|
|
2362
|
+
finally {
|
|
2363
|
+
if (owner !== undefined)
|
|
2364
|
+
this.#codeOwners.pop();
|
|
2365
|
+
this.env.actionDepth -= 1;
|
|
2366
|
+
if (!this.threw())
|
|
2367
|
+
this.flow = savedFlow;
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
/**
|
|
2371
|
+
* THE ACTION BODY'S ARRAY LAW (reference/jse.md). The one hook every
|
|
2372
|
+
* evaluation this runner performs installs, and the statement arm consults: a mutator on a
|
|
2373
|
+
* dotted path whose value is an array (or nothing, read as `[]`) mutates through `writePath`
|
|
2374
|
+
* and answers JavaScript's value. The router verb, module methods and a declared action named
|
|
2375
|
+
* like a verb stay calls, and any other value keeps its pure reading. Twins: Stack.swift
|
|
2376
|
+
* `arrayHook`, JseRunner.kt `arrayHook`.
|
|
2377
|
+
*/
|
|
2378
|
+
arrayHook = globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false ? {
|
|
2379
|
+
accepts: (path, item) => {
|
|
2380
|
+
const head = path + ".";
|
|
2381
|
+
if (head.startsWith("dsx.component.") || head.startsWith("dsx.module.") || head.startsWith("dsx.action."))
|
|
2382
|
+
return false;
|
|
2383
|
+
const v = readPath(this.env, (item ?? {}), path);
|
|
2384
|
+
return v === null || v === undefined || v === NSNull || Array.isArray(v);
|
|
2385
|
+
},
|
|
2386
|
+
apply: (path, verb, args, item) => this.mutateArray(path, verb, args, (item ?? {})),
|
|
2387
|
+
} : { accepts: () => false, apply: () => null };
|
|
2388
|
+
mutateArray(path, verb, args, scope) {
|
|
2389
|
+
// the whole law folds out of a widget whose slice names no mutator (the two callers above are
|
|
2390
|
+
// behind the same flag, so this is never reached there)
|
|
2391
|
+
if (globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false) {
|
|
2392
|
+
// the verb is one pure function (jse.ts `arrayVerb`), shared with a lambda's own locals
|
|
2393
|
+
const r = arrayVerb(readPath(this.env, scope, path), verb, args, this.env.store.jse);
|
|
2394
|
+
if (r === null)
|
|
2395
|
+
return null;
|
|
2396
|
+
writePath(this.env, scope, path, r.array);
|
|
2397
|
+
return r.value;
|
|
2398
|
+
}
|
|
2399
|
+
return null;
|
|
2400
|
+
}
|
|
2401
|
+
// ── expression plumbing ────────────────────────────────────────────────────────────
|
|
2402
|
+
/** AN EXPRESSION-POSITION INCREMENT IN AN ACTION BODY (JSE-VS-JS item 11):
|
|
2403
|
+
* `dsx.variable.m = dsx.variable.n++` writes n as the statement `dsx.variable.n++` would
|
|
2404
|
+
* (writePath: an authored local stays local, a `dsx.` path is the store) and answers the old
|
|
2405
|
+
* value; `++` in front answers the new one. A `[expr]` link evaluates once, to the same
|
|
2406
|
+
* dotted segment the indexed assignment writes. */
|
|
2407
|
+
bumpPath(target, op, prefix, scope) {
|
|
2408
|
+
if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ === false)
|
|
2409
|
+
return null;
|
|
2410
|
+
let path = target[0].v;
|
|
2411
|
+
let j = 1;
|
|
2412
|
+
while (j < target.length) {
|
|
2413
|
+
const a = target[j];
|
|
2414
|
+
if (a.kind === "op" && a.v === ".") {
|
|
2415
|
+
path += "." + target[j + 1].v;
|
|
2416
|
+
j += 2;
|
|
2417
|
+
continue;
|
|
2418
|
+
}
|
|
2419
|
+
let d = 1;
|
|
2420
|
+
let k = j + 1;
|
|
2421
|
+
while (k < target.length) {
|
|
2422
|
+
const tk = target[k];
|
|
2423
|
+
if (tk.kind === "op" && (tk.v === "[" || tk.v === "(" || tk.v === "{"))
|
|
2424
|
+
d += 1;
|
|
2425
|
+
if (tk.kind === "op" && (tk.v === "]" || tk.v === ")" || tk.v === "}")) {
|
|
2426
|
+
d -= 1;
|
|
2427
|
+
if (d === 0)
|
|
2428
|
+
break;
|
|
2429
|
+
}
|
|
2430
|
+
k += 1;
|
|
2431
|
+
}
|
|
2432
|
+
const idxVal = this.evalSync(target.slice(j + 1, k), scope);
|
|
2433
|
+
const n = number(idxVal);
|
|
2434
|
+
path += "." + (n !== null && Number.isFinite(n) && Math.trunc(n) === n ? String(safeInt(n)) : string(idxVal));
|
|
2435
|
+
j = k + 1;
|
|
2436
|
+
}
|
|
2437
|
+
const n = bumpNumbers(readPath(this.env, scope, path), op);
|
|
2438
|
+
writePath(this.env, scope, path, n.next);
|
|
2439
|
+
return prefix ? n.next : n.old;
|
|
2440
|
+
}
|
|
2441
|
+
evalSync(toks, scope) {
|
|
2442
|
+
if (toks.length === 0)
|
|
2443
|
+
return null;
|
|
2444
|
+
// An evaluation door, exactly like JSE.eval's: an action statement's expression spends
|
|
2445
|
+
// the same step and wall clock ledger, and a refused one answers null.
|
|
2446
|
+
const store = this.env.store.jse;
|
|
2447
|
+
const owned = beginEvaluation(store);
|
|
2448
|
+
const p = new Parser(toks, store, scope);
|
|
2449
|
+
if (globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false) {
|
|
2450
|
+
p.bump = (target, op, prefix) => this.bumpPath(target, op, prefix, scope);
|
|
2451
|
+
}
|
|
2452
|
+
// Assignment callbacks need the owning action scope even without array mutators.
|
|
2453
|
+
if (globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false) {
|
|
2454
|
+
p.mutate = this.arrayHook;
|
|
2455
|
+
}
|
|
2456
|
+
if (globalThis.__DSX_OPTIONAL_ARRAY_MUTATORS__ !== false
|
|
2457
|
+
|| globalThis.__DSX_OPTIONAL_LAMBDAS__ !== false) {
|
|
2458
|
+
// A LAMBDA CALLED FROM HERE IS ACTION CONTEXT (reference/jse.md):
|
|
2459
|
+
// its mutators write, and a captured authored local of this body is this body's binding.
|
|
2460
|
+
const priorLambda = store.actionLambda;
|
|
2461
|
+
store.actionLambda = {
|
|
2462
|
+
hook: this.arrayHook,
|
|
2463
|
+
isLocal: (name) => isLocal(scope, name),
|
|
2464
|
+
read: (name) => scope[name],
|
|
2465
|
+
binding: (name) => bindingsOf(scope)?.get(name),
|
|
2466
|
+
applyLocal: (path, verb, args) => this.arrayHook.apply(path, verb, args, scope),
|
|
2467
|
+
// a captured local, or a `dsx.` path, written from inside the lambda (JSE-VS-JS item 12)
|
|
2468
|
+
write: (path, value) => writePath(this.env, scope, path, value),
|
|
2469
|
+
};
|
|
2470
|
+
try {
|
|
2471
|
+
const v = p.expression();
|
|
2472
|
+
return endEvaluation(store, owned) === null ? v : null;
|
|
2473
|
+
}
|
|
2474
|
+
finally {
|
|
2475
|
+
store.actionLambda = priorLambda;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
const v = p.expression();
|
|
2479
|
+
return endEvaluation(store, owned) === null ? v : null;
|
|
2480
|
+
}
|
|
2481
|
+
/** Evaluate statement-position expressions: strips a leading `await`, routes
|
|
2482
|
+
* `fetch(…)` / `dsx.module…` / `dsx.event…` to their async implementations, and
|
|
2483
|
+
* awaits any Promise the expression yields. */
|
|
2484
|
+
async evalMaybeAsync(rawToks, scope) {
|
|
2485
|
+
// THE FOLD IS A BLOCK, NOT AN EARLY RETURN. `if (folded) return …;` left the combinator loops
|
|
2486
|
+
// and the call routing below it in every bundle: esbuild drops the declarations after an
|
|
2487
|
+
// unconditional return but keeps the statements that read them (measured: 887 dead bytes in
|
|
2488
|
+
// the Demo EmbedCard widget). An `if (false) { … }` block is dropped whole.
|
|
2489
|
+
if (globalThis.__DSX_OPTIONAL_ASYNC_EXPRESSIONS__ !== false) {
|
|
2490
|
+
let toks = rawToks;
|
|
2491
|
+
let awaited = false;
|
|
2492
|
+
if (toks.length > 0 && isIdentTok(toks[0], "await")) {
|
|
2493
|
+
awaited = true;
|
|
2494
|
+
toks = toks.slice(1);
|
|
2495
|
+
}
|
|
2496
|
+
// THE COMBINATORS OVER AWAITABLE ELEMENTS (logic parity C2): `await Promise.all([
|
|
2497
|
+
// dsx.module.a.b(…), fetch(…) ])` starts each element through this same door, concurrently,
|
|
2498
|
+
// so a module element is SENT and settles its envelope. The elements used to be evaluated as
|
|
2499
|
+
// plain expressions, where a module call answers null, so nothing was sent; both natives
|
|
2500
|
+
// already started module elements (JseRunner.kt / Stack.swift startOp).
|
|
2501
|
+
const combinator = awaited && toks.length >= 3 && toks[0].kind === "ident"
|
|
2502
|
+
&& /^Promise\.(all|allSettled|race|any)$/.test(toks[0].v) && isOpTok(toks[1], "(") && isOpTok(toks[2], "[")
|
|
2503
|
+
? toks[0].v.substring(8) : null;
|
|
2504
|
+
if (combinator !== null) {
|
|
2505
|
+
let depth = 0;
|
|
2506
|
+
let end = -1;
|
|
2507
|
+
for (let i = 2; i < toks.length; i++) {
|
|
2508
|
+
const t = toks[i];
|
|
2509
|
+
if (t.kind === "op" && ["(", "[", "{"].includes(t.v))
|
|
2510
|
+
depth += 1;
|
|
2511
|
+
else if (t.kind === "op" && [")", "]", "}"].includes(t.v)) {
|
|
2512
|
+
depth -= 1;
|
|
2513
|
+
if (depth === 0) {
|
|
2514
|
+
end = i;
|
|
2515
|
+
break;
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
const elems = [];
|
|
2520
|
+
let cur = [];
|
|
2521
|
+
depth = 0;
|
|
2522
|
+
for (const t of toks.slice(3, end < 0 ? toks.length : end)) {
|
|
2523
|
+
if (t.kind === "op" && ["(", "[", "{"].includes(t.v))
|
|
2524
|
+
depth += 1;
|
|
2525
|
+
if (t.kind === "op" && [")", "]", "}"].includes(t.v))
|
|
2526
|
+
depth -= 1;
|
|
2527
|
+
if (t.kind === "op" && t.v === "," && depth === 0) {
|
|
2528
|
+
elems.push(cur);
|
|
2529
|
+
cur = [];
|
|
2530
|
+
continue;
|
|
2531
|
+
}
|
|
2532
|
+
cur.push(t);
|
|
2533
|
+
}
|
|
2534
|
+
if (cur.length > 0)
|
|
2535
|
+
elems.push(cur);
|
|
2536
|
+
// each element is a strand of this entry, and the combinator's own wait is a suspension
|
|
2537
|
+
const frame = globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false;
|
|
2538
|
+
const entry = this.entry;
|
|
2539
|
+
const started = elems.map((el) => {
|
|
2540
|
+
if (!frame || entry === null)
|
|
2541
|
+
return this.evalMaybeAsync([rawToks[0], ...el], scope);
|
|
2542
|
+
entry.running += 1;
|
|
2543
|
+
return this.evalMaybeAsync([rawToks[0], ...el], scope).finally(() => strandStops(this, entry));
|
|
2544
|
+
});
|
|
2545
|
+
const settle = (p) => (frame ? this.suspend(p) : p);
|
|
2546
|
+
switch (combinator) {
|
|
2547
|
+
case "all": return await settle(Promise.all(started));
|
|
2548
|
+
case "allSettled": return (await settle(Promise.allSettled(started))).map((r) => (r.status === "fulfilled" ? { status: "fulfilled", value: r.value ?? NSNull } : { status: "rejected", reason: string(r.reason) }));
|
|
2549
|
+
case "race": return started.length === 0 ? null : await settle(Promise.race(started));
|
|
2550
|
+
default: return started.length === 0 ? null : await settle(Promise.any(started).catch(() => null));
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
if (toks.length >= 2 && toks[0].kind === "ident" && isOpTok(toks[1], "(")) {
|
|
2554
|
+
const callee = toks[0].v;
|
|
2555
|
+
// THE INVOKE FACE in expression position: `const r = await dsx.api.orders(args?)`
|
|
2556
|
+
// answers the handle's own promise; `dsx.api.orders.cancel()` answers nothing.
|
|
2557
|
+
// folded out of a widget that declares no <socket> (`__DSX_OPTIONAL_SOCKETS__`) or no <api>
|
|
2558
|
+
// (`__DSX_OPTIONAL_APIS__`): neither handle table can hold anything there
|
|
2559
|
+
const socketCall = globalThis.__DSX_OPTIONAL_SOCKETS__ !== false ? socketCallTarget(callee, this.env.sockets) : null;
|
|
2560
|
+
if (socketCall !== null)
|
|
2561
|
+
return runSocketCall(socketCall, this.#parseArgs(toks.slice(1), scope));
|
|
2562
|
+
const apiCall = globalThis.__DSX_OPTIONAL_APIS__ !== false ? apiCallTarget(callee, this.env.apis) : null;
|
|
2563
|
+
if (apiCall !== null) {
|
|
2564
|
+
if (apiCall.cancel) {
|
|
2565
|
+
apiCall.handle.cancel();
|
|
2566
|
+
return null;
|
|
2567
|
+
}
|
|
2568
|
+
const callArgs = this.#parseArgs(toks.slice(1), scope);
|
|
2569
|
+
const p = apiCall.handle.call(isDict(callArgs[0]) ? callArgs[0] : undefined, this.apiCallListener(callArgs[1]));
|
|
2570
|
+
if (awaited) {
|
|
2571
|
+
try {
|
|
2572
|
+
return await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(p) : p);
|
|
2573
|
+
}
|
|
2574
|
+
catch {
|
|
2575
|
+
return null;
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
void p.catch(() => { });
|
|
2579
|
+
return null;
|
|
2580
|
+
}
|
|
2581
|
+
if (callee === "fetch") {
|
|
2582
|
+
const args = this.#parseArgs(toks.slice(1), scope);
|
|
2583
|
+
const fetched = this.fetchFunnel(string(args[0]), isDict(args[1]) ? args[1] : {});
|
|
2584
|
+
return await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(fetched) : fetched);
|
|
2585
|
+
}
|
|
2586
|
+
// THE ONE AWAITABLE SET (system audit S8), and the verbs that answer nothing beside it,
|
|
2587
|
+
// as two tables rather than one flat list of every `dsx.` spelling. AWAITABLE names the
|
|
2588
|
+
// six verbs that ANSWER something - a module call, an action call, a context call, an
|
|
2589
|
+
// event request, a transition and the `<api>` call (claimed above, by `apiCallTarget`). VOID names the
|
|
2590
|
+
// rest: they record and continue, `await` in front of one is the lint error
|
|
2591
|
+
// `await-on-void-verb`, and at run time the verb still runs exactly once and the
|
|
2592
|
+
// expression answers null. Both native runners had hand written matchers for the
|
|
2593
|
+
// awaitable forms and NOTHING for the void ones, so an awaited `dsx.log` fell to their
|
|
2594
|
+
// expression evaluators and did nothing at all while this runner recorded it; the arm in
|
|
2595
|
+
// Stack.swift runVerb and its Kotlin twin close that, against the same two tables.
|
|
2596
|
+
// A CONTEXT CALL JOINED THE SET (composition/context.json
|
|
2597
|
+
// `call`): it fell to the expression evaluator here, which never called the provider, so
|
|
2598
|
+
// `const v = await dsx.context.get()` bound null and ran nothing.
|
|
2599
|
+
const awaitableDsx = callee.startsWith("dsx.module.") || (callee.startsWith("dsx.action.") && !isArgumentRead(callee)) ||
|
|
2600
|
+
callee.startsWith("dsx.context.") ||
|
|
2601
|
+
callee === "dsx.event" || callee === "dsx.transition" || callee === "dsx.wait" || callee === "dsx.stop";
|
|
2602
|
+
const voidDsx = callee.startsWith("dsx.component.") || callee === "dsx.error" ||
|
|
2603
|
+
callee === "dsx.log" || callee === "dsx.screen.settled" ||
|
|
2604
|
+
callee === "dsx.transition.skip";
|
|
2605
|
+
if (awaitableDsx)
|
|
2606
|
+
return await this.#dsxStatement(callee, toks, scope, awaited);
|
|
2607
|
+
if (voidDsx) {
|
|
2608
|
+
await this.#dsxStatement(callee, toks, scope, false);
|
|
2609
|
+
return null;
|
|
2610
|
+
}
|
|
2611
|
+
// THE BARE CALL IN EXPRESSION POSITION IS RETIRED TOO (S3 cut). `await x({ … })` and
|
|
2612
|
+
// `const v = await x()` used to reach the declared `<action>` here, so the bare form
|
|
2613
|
+
// and `dsx.action.x()` answered the same thing. One spelling now: `await` on a bare
|
|
2614
|
+
// name is an ordinary expression, nothing runs and the binding is null. The three
|
|
2615
|
+
// await matchers agree - this one, Stack.swift's `matchAwaitAction` and JseRunner.kt's
|
|
2616
|
+
// - and the actions corpus pins all three.
|
|
2617
|
+
}
|
|
2618
|
+
// an INTERIOR await (not statement-leading) cannot suspend — the evaluator coerces
|
|
2619
|
+
// any live Promise it meets to null; tell the author to restructure
|
|
2620
|
+
if (toks.some((t) => t.kind === "ident" && t.v === "await")) {
|
|
2621
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
2622
|
+
console.warn("[dsx runner] interior await is not supported — restructure as `const x = await …` first");
|
|
2623
|
+
}
|
|
2624
|
+
const v = this.evalSync(toks, scope);
|
|
2625
|
+
if (awaited && v instanceof Promise) {
|
|
2626
|
+
try {
|
|
2627
|
+
return await (globalThis.__DSX_OPTIONAL_ACTION_FRAME__ !== false ? this.suspend(v) : v);
|
|
2628
|
+
}
|
|
2629
|
+
catch (e) {
|
|
2630
|
+
this.flow = { kind: "throw", value: String(e) };
|
|
2631
|
+
return null;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
if (v instanceof Promise) {
|
|
2635
|
+
v.catch(() => { });
|
|
2636
|
+
return null;
|
|
2637
|
+
} // un-awaited promise — drop
|
|
2638
|
+
return v;
|
|
2639
|
+
}
|
|
2640
|
+
return this.evalSync(rawToks, scope);
|
|
2641
|
+
}
|
|
2642
|
+
/** Parse a call's `( … )` argument list from a token slice starting at `(`. */
|
|
2643
|
+
#parseArgs(toks, scope) {
|
|
2644
|
+
if (toks.length === 0 || !isOpTok(toks[0], "("))
|
|
2645
|
+
return [];
|
|
2646
|
+
// find the matching close paren
|
|
2647
|
+
let d = 0;
|
|
2648
|
+
let end = -1;
|
|
2649
|
+
for (let i = 0; i < toks.length; i++) {
|
|
2650
|
+
const t = toks[i];
|
|
2651
|
+
if (t.kind === "op" && t.v === "(")
|
|
2652
|
+
d += 1;
|
|
2653
|
+
else if (t.kind === "op" && t.v === ")") {
|
|
2654
|
+
d -= 1;
|
|
2655
|
+
if (d === 0) {
|
|
2656
|
+
end = i;
|
|
2657
|
+
break;
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
const inner = toks.slice(1, end < 0 ? toks.length : end);
|
|
2662
|
+
// split top-level commas
|
|
2663
|
+
const parts = [];
|
|
2664
|
+
let cur = [];
|
|
2665
|
+
let depth = 0;
|
|
2666
|
+
for (const t of inner) {
|
|
2667
|
+
if (t.kind === "op" && ["(", "[", "{"].includes(t.v))
|
|
2668
|
+
depth += 1;
|
|
2669
|
+
if (t.kind === "op" && [")", "]", "}"].includes(t.v))
|
|
2670
|
+
depth -= 1;
|
|
2671
|
+
if (t.kind === "op" && t.v === "," && depth === 0) {
|
|
2672
|
+
parts.push(cur);
|
|
2673
|
+
cur = [];
|
|
2674
|
+
continue;
|
|
2675
|
+
}
|
|
2676
|
+
cur.push(t);
|
|
2677
|
+
}
|
|
2678
|
+
if (cur.length > 0)
|
|
2679
|
+
parts.push(cur);
|
|
2680
|
+
// `...expr` splices the coerced iterable (call-position spread, wave 3)
|
|
2681
|
+
const out = [];
|
|
2682
|
+
for (const p of parts) {
|
|
2683
|
+
if (p.length > 0 && isOpTok(p[0], "..."))
|
|
2684
|
+
out.push(...spreadValues(this.evalSync(p.slice(1), scope)));
|
|
2685
|
+
else
|
|
2686
|
+
out.push(this.evalSync(p, scope));
|
|
2687
|
+
}
|
|
2688
|
+
return out;
|
|
2689
|
+
}
|
|
2690
|
+
/** THE ONE network funnel. A surface reaches the platform fetch through every guard
|
|
2691
|
+
* `runnerFetch` already applies. A host that runs bodies it did not write binds
|
|
2692
|
+
* `env.egress`, and a refused URL answers the invalid-request shape (status -2) WITHOUT
|
|
2693
|
+
* the request ever leaving the process — which is the property that matters. The refusal
|
|
2694
|
+
* stays distinguishable from an unreachable host (status 0) on purpose: the allowlist is
|
|
2695
|
+
* the author's own declaration, so hiding it from them buys nothing and costs every
|
|
2696
|
+
* debugging session. */
|
|
2697
|
+
fetchFunnel(url, opts) {
|
|
2698
|
+
// BLOCK-FORM FOLD: both callers (`fetch(` and the `fetch:` verb) spell the word `__DSX_OPTIONAL_FETCH__` reads.
|
|
2699
|
+
if (globalThis.__DSX_OPTIONAL_FETCH__ !== false) {
|
|
2700
|
+
const gate = this.env.egress;
|
|
2701
|
+
if (gate !== undefined && !gate(url))
|
|
2702
|
+
return Promise.resolve(REFUSED_FETCH);
|
|
2703
|
+
// Keep the optional-fetch seam in the action path. Calling runnerFetchFull directly
|
|
2704
|
+
// bypasses the embed define and retains the whole bounded network machine in widgets
|
|
2705
|
+
// that never author fetch (the strict G10 size gate catches that regression).
|
|
2706
|
+
return runnerFetch(url, opts, this.env.fetchTransport).then(responseShape);
|
|
2707
|
+
}
|
|
2708
|
+
return Promise.resolve(REFUSED_FETCH);
|
|
2709
|
+
}
|
|
2710
|
+
/** THE ONE module funnel: the env's override when a host bound one (the server's
|
|
2711
|
+
* request-scoped table), the global registry otherwise. Both tiers charge the same
|
|
2712
|
+
* call budget, so an escalated body cannot buy calls the interpreter would refuse. */
|
|
2713
|
+
/** The ONE module funnel. Reachable from compile/jstier.ts, which builds the JS tier
|
|
2714
|
+
* executor's env out of this runner's routing rather than making every bundle carry it. */
|
|
2715
|
+
callModuleFunnel(chain, args, events, held) {
|
|
2716
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_CALLS__ === false)
|
|
2717
|
+
return Promise.resolve(null);
|
|
2718
|
+
chain = ownedPath(this.env, chain);
|
|
2719
|
+
const budget = chargeCall(this.env, chain);
|
|
2720
|
+
if (budget !== null)
|
|
2721
|
+
return budget;
|
|
2722
|
+
// `dsx.module.global.apply` (proposals/cloud-state.md section 6) is answered HERE, by the
|
|
2723
|
+
// calling surface: the variable it names lives in this runner's store and in no other, and
|
|
2724
|
+
// the write lands synchronously (I5). Declared in Mandatory/State's manifest (K7).
|
|
2725
|
+
if (chain === STATE_APPLY_CHAIN) {
|
|
2726
|
+
const variable = typeof args["variable"] === "string" ? args["variable"] : "";
|
|
2727
|
+
const refusal = this.env.store.apply(variable, args["value"] ?? NSNull, args["origin"]);
|
|
2728
|
+
return refusal === ""
|
|
2729
|
+
? Promise.resolve({ variable, origin: args["origin"] ?? "remote" })
|
|
2730
|
+
: Promise.reject(new ModuleCallError(refusal, stateApplyMessage(refusal, variable)));
|
|
2731
|
+
}
|
|
2732
|
+
const override = this.env.callModule;
|
|
2733
|
+
if (override !== undefined)
|
|
2734
|
+
return override(chain, args, events);
|
|
2735
|
+
// The calling component's sockets travel with the call (audio-revamp section 5.7): a module
|
|
2736
|
+
// reaches a <socket> only through a call that names it, so sockets stay component-scoped.
|
|
2737
|
+
const sockets = this.env.sockets;
|
|
2738
|
+
return ModuleRegistry.call(chain, args, {
|
|
2739
|
+
...(events === undefined ? {} : { events }),
|
|
2740
|
+
...(held === undefined ? {} : { call: held }),
|
|
2741
|
+
...(sockets === undefined ? {} : { sockets: (as) => sockets.get(as)?.port?.() ?? null }),
|
|
2742
|
+
});
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
_a = ActionRunner;
|
|
2746
|
+
/** `dsx.module.self.<action>` names the OWNING package (Skills/cross-module-calls.md: portable
|
|
2747
|
+
* components never hard-code their own scheme). The natives resolve it in the runner
|
|
2748
|
+
* (JseRunner.kt packageOp, Stack.swift); the web never did, so a package component's
|
|
2749
|
+
* `self` call was the unknown scheme `self` and failed where the natives answered.
|
|
2750
|
+
* Outside a package there is no owner, and `self` stays the absence it is. */
|
|
2751
|
+
function ownedPath(env, chain) {
|
|
2752
|
+
if ((chain === "self" || chain.startsWith("self.")) && env.ownerScheme !== undefined && env.ownerScheme !== "") {
|
|
2753
|
+
return env.ownerScheme + chain.substring(4);
|
|
2754
|
+
}
|
|
2755
|
+
return chain;
|
|
2756
|
+
}
|
|
2757
|
+
/** Charges one module call to the entry's budget: the refusal when the budget is spent, else null. A control is
|
|
2758
|
+
* a module call too, so it is charged the same (an escalated body cannot buy controls the interpreter refuses). */
|
|
2759
|
+
function chargeCall(env, chain) {
|
|
2760
|
+
const budget = env.callBudget;
|
|
2761
|
+
return budget !== undefined && ++budget.count > budget.cap
|
|
2762
|
+
? Promise.reject(new ModuleCallError("budget_exceeded", chain)) : null;
|
|
2763
|
+
}
|
|
2764
|
+
/** A CONTROL OF A CALL THIS DOCUMENT HOLDS, `dsx.module.<chain>.<action>.<control>(call, args)` with `path` the
|
|
2765
|
+
* dotted path after `dsx.module.` (`self` resolved). The refusals come in one order on every lane: a control's
|
|
2766
|
+
* arguments are one object or nothing, so a second argument that is not an object, or a third argument, is
|
|
2767
|
+
* `invalid_param`, and so is an object that carries a call (Article 14.2); a call this document did not start
|
|
2768
|
+
* is `call_ended`, as `dsx.stop` answers; then the bus answers (the platform refusal, `call_ended` for an ended
|
|
2769
|
+
* call, `unknown_control`). Twins: JseRunner.kt and Stack.swift `heldControl`. */
|
|
2770
|
+
function controlCall(env, args, path) {
|
|
2771
|
+
if (args.length > 2 || (args.length === 2 && !isDict(args[1]))) {
|
|
2772
|
+
return Promise.reject(new ModuleCallError("invalid_param", `A control takes one object of arguments (${path}).`, null));
|
|
2773
|
+
}
|
|
2774
|
+
const controlArgs = isDict(args[1]) ? args[1] : {};
|
|
2775
|
+
if (containsCallValue(controlArgs))
|
|
2776
|
+
return notData(path);
|
|
2777
|
+
if (!env.store.holdsCall(args[0])) {
|
|
2778
|
+
return Promise.reject(new ModuleCallError("call_ended", "Not a call this document started and holds.", null));
|
|
2779
|
+
}
|
|
2780
|
+
return chargeCall(env, path) ?? ModuleRegistry.control(args[0], path, controlArgs);
|
|
2781
|
+
}
|
|
2782
|
+
/** The value a failed module call throws: its code, the call it was, and the sentence. */
|
|
2783
|
+
/** THE REFUSAL OF A RUNNING CALL WHERE DATA GOES (constitution Article 14.2):
|
|
2784
|
+
* `invalid_param`, settled like any failed call. `what` names the refused operation. */
|
|
2785
|
+
function notData(what) {
|
|
2786
|
+
return Promise.reject(new ModuleCallError("invalid_param", `A running call is not data: it is never persisted, sent or passed to another document (${what}).`, null));
|
|
2787
|
+
}
|
|
2788
|
+
/** The child attributes each consumer store has refused, per call value: a binding that renders again says it once. */
|
|
2789
|
+
const REFUSED_INPUTS = new WeakMap();
|
|
2790
|
+
/** THE ATTRIBUTES THAT ASK YES OR NO and may read a variable that holds a running call:
|
|
2791
|
+
* the seams that refuse a held call on an element's attribute skip them, and the element reads the value as it did
|
|
2792
|
+
* before that rule. How a call reads as yes or no is not decided here. `visible-if`, the other such attribute, is
|
|
2793
|
+
* consumed by the mount and never reaches the seam. Twins: JseRunner.kt and Stack.swift `HELD_CALL_YES_NO`. */
|
|
2794
|
+
export const HELD_CALL_YES_NO = new Set(["disabled-if"]);
|
|
2795
|
+
/** Whether `tag`'s `name` is a yes/no attribute the element reads with a held call in it (`HELD_CALL_YES_NO`): only on
|
|
2796
|
+
* a tag that is neither dotted nor capitalised. Any other tag (a child document, a native component `<scheme.Name>`,
|
|
2797
|
+
* a lower-case tag written with its scheme) refuses every held call, as dev's rule had it before the ruling.
|
|
2798
|
+
* Twins: JseRunner.kt and Stack.swift `heldCallYesNoRead`. */
|
|
2799
|
+
export function heldCallYesNoRead(tag, name) {
|
|
2800
|
+
return HELD_CALL_YES_NO.has(name) && !tag.includes(".") && !/^[A-Z]/.test(tag);
|
|
2801
|
+
}
|
|
2802
|
+
/** A CHILD COMPONENT'S ATTRIBUTE THAT WOULD CARRY A RUNNING CALL (constitution Article 14.2: a running call is
|
|
2803
|
+
* never passed to another document). The renderer has bound `name` to `value` in the consumer's `store`; when the
|
|
2804
|
+
* value carries a call at any depth the binding is refused: the answer is true, the renderer leaves the attribute
|
|
2805
|
+
* out so the child sees it absent, and the refusal is reported as a failed call outside a `try` is (Article 28.13):
|
|
2806
|
+
* one `invalid_param` entry in the error log (origin `uncaught`) naming the attribute, once per call and attribute
|
|
2807
|
+
* in that store, however often the binding renders. Twins: JseRunner.kt and Stack.swift `refusesHeldAttribute`. */
|
|
2808
|
+
export function refusesHeldAttribute(store, scheme, name, value) {
|
|
2809
|
+
// A CALL VALUE IS MINTED ONLY INSIDE THE BUS'S DISPATCH (bus.ts dispatchSegments, `markCallValue`), which folds
|
|
2810
|
+
// with `__DSX_OPTIONAL_MODULE_DISPATCH__`: with it folded no value can carry a call, and nothing is ever refused.
|
|
2811
|
+
if (globalThis.__DSX_OPTIONAL_MODULE_DISPATCH__ === false)
|
|
2812
|
+
return false;
|
|
2813
|
+
const call = findCallValue(value);
|
|
2814
|
+
if (call === null)
|
|
2815
|
+
return false;
|
|
2816
|
+
let calls = REFUSED_INPUTS.get(store);
|
|
2817
|
+
if (calls === undefined) {
|
|
2818
|
+
calls = new WeakMap();
|
|
2819
|
+
REFUSED_INPUTS.set(store, calls);
|
|
2820
|
+
}
|
|
2821
|
+
let names = calls.get(call);
|
|
2822
|
+
if (names === undefined) {
|
|
2823
|
+
names = new Set();
|
|
2824
|
+
calls.set(call, names);
|
|
2825
|
+
}
|
|
2826
|
+
if (!names.has(name)) {
|
|
2827
|
+
names.add(name);
|
|
2828
|
+
ModuleRegistry.reportAmbientError(scheme, "invalid_param", {
|
|
2829
|
+
message: `A running call is not data: it is never persisted, sent or passed to another document (attribute ${name}).`,
|
|
2830
|
+
recoverable: false, data: { call: "attribute", attribute: name }, origin: "uncaught",
|
|
2831
|
+
});
|
|
2832
|
+
}
|
|
2833
|
+
return true;
|
|
2834
|
+
}
|
|
2835
|
+
/** A WRITE THAT WOULD CARRY A RUNNING CALL OUT OF ITS DOCUMENT (Article 14.2): to
|
|
2836
|
+
* `dsx.global` (at any depth) the write is not made; to a persisted variable the variable holds it (Article 14.2)
|
|
2837
|
+
* and its save is refused, so this makes that write itself. The answer names the refused operation
|
|
2838
|
+
* (`global` or `variable`), and the caller settles it like a failed call; null when the write is ordinary. Twins:
|
|
2839
|
+
* JseRunner.kt and Stack.swift `write`. */
|
|
2840
|
+
function callDataRefusal(env, scope, rawPath, value) {
|
|
2841
|
+
if (!rawPath.startsWith("dsx.") || !containsCallValue(value))
|
|
2842
|
+
return null;
|
|
2843
|
+
const path = JSE.normalizeScope(rawPath);
|
|
2844
|
+
if (path === "global" || path.startsWith("global."))
|
|
2845
|
+
return "global";
|
|
2846
|
+
const head = path.split(".")[0] ?? "";
|
|
2847
|
+
if (head === "" || env.store.persistedSlot(head) === "")
|
|
2848
|
+
return null;
|
|
2849
|
+
writePath(env, scope, rawPath, value);
|
|
2850
|
+
return "variable";
|
|
2851
|
+
}
|
|
2852
|
+
function failedCall(e, call) {
|
|
2853
|
+
if (e instanceof ModuleCallError) {
|
|
2854
|
+
const value = { code: e.code, call };
|
|
2855
|
+
if (typeof e.message === "string" && e.message !== "")
|
|
2856
|
+
value["message"] = e.message;
|
|
2857
|
+
if (e.data !== null && e.data !== undefined)
|
|
2858
|
+
value["data"] = e.data;
|
|
2859
|
+
return value;
|
|
2860
|
+
}
|
|
2861
|
+
return { code: "error", call, message: String(e) };
|
|
2862
|
+
}
|
|
2863
|
+
/** Two-way `bind=` writes from input elements — the SAME routing as action
|
|
2864
|
+
* assignments (global./route./cookie./surface), exported for @despia-native/dom. */
|
|
2865
|
+
export function writeBound(env, path, value) {
|
|
2866
|
+
if (writesDerived(env.store, path))
|
|
2867
|
+
return;
|
|
2868
|
+
writePath(env, env.item ?? {}, path, value);
|
|
2869
|
+
}
|
|
2870
|
+
/** A BOUND WRITE INTO A DERIVED NAME WRITES NOTHING (Conformance/state/derived-write-back.json).
|
|
2871
|
+
* A stored value wins over a `<variable computed>` formula on every lane's read ladder, so a
|
|
2872
|
+
* dismissed sheet over `isOpen = entry != null` stored `false` and never presented again. A
|
|
2873
|
+
* derived name is SwiftUI's get-only binding: the door stands down and the author's handler
|
|
2874
|
+
* clears what the formula reads. An author ASSIGNMENT is not a door and still stores. Twins:
|
|
2875
|
+
* State.kt `StackStore.writeBound`, DSXState.swift `StackStore.writeBound`. */
|
|
2876
|
+
function writesDerived(store, path) {
|
|
2877
|
+
const key = JSE.normalizeScope(path);
|
|
2878
|
+
const head = /^[^.[]+/.exec(key)?.[0] ?? "";
|
|
2879
|
+
if (!store.jse.computed.has(head))
|
|
2880
|
+
return false;
|
|
2881
|
+
const stored = store.jse.vars.get(head);
|
|
2882
|
+
return stored === undefined || stored === null; // the read ladder's own test (jse.ts lookup)
|
|
2883
|
+
}
|
|
2884
|
+
/** A ROW'S OWN FIELD written into the bound array (`bind="dsx.this.name"` in a row, the row
|
|
2885
|
+
* write dom/src/mount.ts makes for a collection over a plain path). `arrayPath` is the
|
|
2886
|
+
* collection's bind, already normalized. A path-shaped computed collection still has no
|
|
2887
|
+
* storage of its own: its handler writes the stored owner, just like writeBound. */
|
|
2888
|
+
export function writeRow(env, arrayPath, index, field, value) {
|
|
2889
|
+
if (refusesContextWrite(arrayPath) || writesDerived(env.store, arrayPath))
|
|
2890
|
+
return;
|
|
2891
|
+
env.store.setPath(`${arrayPath}.${index}.${field}`, value);
|
|
2892
|
+
}
|
|
2893
|
+
/** THE WHOLE BOUND ARRAY replaced, the write a reorder drop makes (List.swift's `setBound`). */
|
|
2894
|
+
export function writeRows(env, arrayPath, rows) {
|
|
2895
|
+
if (refusesContextWrite(arrayPath) || writesDerived(env.store, arrayPath))
|
|
2896
|
+
return;
|
|
2897
|
+
env.store.setPath(arrayPath, rows);
|
|
2898
|
+
}
|
|
2899
|
+
/** A REORDER DROP THAT DECLARES ITS MOVE (context.md 9.9; composition/context.json `writeBack`).
|
|
2900
|
+
* A collection bound to `dsx.context.*` with a non-empty `on:move` moves the provider's rows
|
|
2901
|
+
* through the consumer's own code (the provider's action), so the bind's write-back is the
|
|
2902
|
+
* declared path's to skip: nothing is written and nothing is said, and `on:move` fires. The
|
|
2903
|
+
* linter allows exactly this form (89008e4b7); without `on:move` the drop is still refused by
|
|
2904
|
+
* `writeRows`. Kotlin `contextDeclaredDrop`, Swift `StackContextFold.declaredDrop`. */
|
|
2905
|
+
export function declaredDrop(arrayPath, onMove) {
|
|
2906
|
+
if (arrayPath !== "context" && !arrayPath.startsWith("context."))
|
|
2907
|
+
return false;
|
|
2908
|
+
return (onMove ?? "").trim() !== "";
|
|
2909
|
+
}
|
|
2910
|
+
/** A COLLECTION OVER THE PLANE READS ITS ROWS AND NEVER MOVES THEM (proposals/modularity.md
|
|
2911
|
+
* §7.5 step 4). The row write and the reorder drop reached `setPath` past the refusal
|
|
2912
|
+
* `writePath` makes for a field, and minted a consumer key named `context`: a write that
|
|
2913
|
+
* succeeds and changes nothing. Same phrase, same one line, nothing written. */
|
|
2914
|
+
function refusesContextWrite(path) {
|
|
2915
|
+
if (path !== "context" && !path.startsWith("context."))
|
|
2916
|
+
return false;
|
|
2917
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
2918
|
+
console.warn(`[dsx runner] dsx.context is read-only: dsx.${path} - a collection over the plane reads its rows; expose an <action> on the provider and call it`);
|
|
2919
|
+
return true;
|
|
2920
|
+
}
|
|
2921
|
+
// ── fetch (the runner's network face) ────────────────────────────────────────────────
|
|
2922
|
+
/** wired by the host for tests / SSR proxying; defaults to the platform fetch. */
|
|
2923
|
+
export const RunnerFetchSeam = {
|
|
2924
|
+
impl: null,
|
|
2925
|
+
};
|
|
2926
|
+
const MAX_RUNNER_RESPONSE_BYTES = 16 * 1024 * 1024;
|
|
2927
|
+
const MAX_RUNNER_REQUEST_BYTES = 4 * 1024 * 1024;
|
|
2928
|
+
const MAX_RUNNER_REQUEST_NODES = 250_000;
|
|
2929
|
+
const MAX_RUNNER_REQUEST_DEPTH = 128;
|
|
2930
|
+
const MAX_RUNNER_URL_BYTES = 16 * 1024;
|
|
2931
|
+
const MAX_RUNNER_HEADER_BYTES = 64 * 1024;
|
|
2932
|
+
const MAX_RUNNER_HEADER_COUNT = 100;
|
|
2933
|
+
class RunnerFetchError extends Error {
|
|
2934
|
+
code;
|
|
2935
|
+
constructor(code) {
|
|
2936
|
+
super(code);
|
|
2937
|
+
this.code = code;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
function runnerUtf8Bytes(value, limit) {
|
|
2941
|
+
let bytes = 0;
|
|
2942
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2943
|
+
const code = value.charCodeAt(index);
|
|
2944
|
+
if (code <= 0x7f)
|
|
2945
|
+
bytes += 1;
|
|
2946
|
+
else if (code <= 0x7ff)
|
|
2947
|
+
bytes += 2;
|
|
2948
|
+
else if (code >= 0xd800 && code <= 0xdbff) {
|
|
2949
|
+
const low = value.charCodeAt(index + 1);
|
|
2950
|
+
if (low >= 0xdc00 && low <= 0xdfff) {
|
|
2951
|
+
bytes += 4;
|
|
2952
|
+
index += 1;
|
|
2953
|
+
}
|
|
2954
|
+
else
|
|
2955
|
+
bytes += 3;
|
|
2956
|
+
}
|
|
2957
|
+
else
|
|
2958
|
+
bytes += 3;
|
|
2959
|
+
if (bytes > limit)
|
|
2960
|
+
return bytes;
|
|
2961
|
+
}
|
|
2962
|
+
return bytes;
|
|
2963
|
+
}
|
|
2964
|
+
function runnerEscapedJsonBytes(value, limit) {
|
|
2965
|
+
let bytes = 2;
|
|
2966
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
2967
|
+
const code = value.charCodeAt(index);
|
|
2968
|
+
if (code === 0x22 || code === 0x5c)
|
|
2969
|
+
bytes += 2;
|
|
2970
|
+
else if (code <= 0x1f)
|
|
2971
|
+
bytes += 6;
|
|
2972
|
+
else if (code <= 0x7f)
|
|
2973
|
+
bytes += 1;
|
|
2974
|
+
else if (code <= 0x7ff)
|
|
2975
|
+
bytes += 2;
|
|
2976
|
+
else if (code >= 0xd800 && code <= 0xdbff) {
|
|
2977
|
+
const low = value.charCodeAt(index + 1);
|
|
2978
|
+
if (low >= 0xdc00 && low <= 0xdfff) {
|
|
2979
|
+
bytes += 4;
|
|
2980
|
+
index += 1;
|
|
2981
|
+
}
|
|
2982
|
+
else
|
|
2983
|
+
bytes += 6;
|
|
2984
|
+
}
|
|
2985
|
+
else if (code >= 0xdc00 && code <= 0xdfff)
|
|
2986
|
+
bytes += 6;
|
|
2987
|
+
else
|
|
2988
|
+
bytes += 3;
|
|
2989
|
+
if (bytes > limit)
|
|
2990
|
+
return bytes;
|
|
2991
|
+
}
|
|
2992
|
+
return bytes;
|
|
2993
|
+
}
|
|
2994
|
+
/** Bound authored fetch bodies before JSON.stringify can recurse or allocate an
|
|
2995
|
+
* unbounded intermediate value on the UI thread. */
|
|
2996
|
+
function prepareRunnerBody(rawBody) {
|
|
2997
|
+
// a null or undefined body is no body, as in JavaScript (JSE's null is the NSNull sentinel)
|
|
2998
|
+
if (rawBody === undefined || rawBody === null || rawBody === NSNull)
|
|
2999
|
+
return undefined;
|
|
3000
|
+
if (typeof rawBody === "string") {
|
|
3001
|
+
if (rawBody.length > MAX_RUNNER_REQUEST_BYTES
|
|
3002
|
+
|| runnerUtf8Bytes(rawBody, MAX_RUNNER_REQUEST_BYTES) > MAX_RUNNER_REQUEST_BYTES) {
|
|
3003
|
+
throw new RunnerFetchError("request_too_large");
|
|
3004
|
+
}
|
|
3005
|
+
return rawBody;
|
|
3006
|
+
}
|
|
3007
|
+
const stack = [{ value: rawBody, depth: 0 }];
|
|
3008
|
+
const ancestors = new Set();
|
|
3009
|
+
let nodes = 0;
|
|
3010
|
+
let bytes = 0;
|
|
3011
|
+
const add = (count) => {
|
|
3012
|
+
bytes += count;
|
|
3013
|
+
if (bytes > MAX_RUNNER_REQUEST_BYTES)
|
|
3014
|
+
throw new RunnerFetchError("request_too_large");
|
|
3015
|
+
};
|
|
3016
|
+
while (stack.length > 0) {
|
|
3017
|
+
const frame = stack.pop();
|
|
3018
|
+
if (frame.exit !== undefined) {
|
|
3019
|
+
ancestors.delete(frame.exit);
|
|
3020
|
+
continue;
|
|
3021
|
+
}
|
|
3022
|
+
nodes += 1;
|
|
3023
|
+
if (nodes > MAX_RUNNER_REQUEST_NODES || frame.depth > MAX_RUNNER_REQUEST_DEPTH) {
|
|
3024
|
+
throw new RunnerFetchError("request_too_complex");
|
|
3025
|
+
}
|
|
3026
|
+
const next = frame.value;
|
|
3027
|
+
if (next === null || next === undefined || next === NSNull)
|
|
3028
|
+
add(4);
|
|
3029
|
+
else if (typeof next === "string")
|
|
3030
|
+
add(runnerEscapedJsonBytes(next, MAX_RUNNER_REQUEST_BYTES - bytes));
|
|
3031
|
+
else if (typeof next === "number")
|
|
3032
|
+
add(Number.isFinite(next) ? String(next).length : 4);
|
|
3033
|
+
else if (typeof next === "boolean")
|
|
3034
|
+
add(next ? 4 : 5);
|
|
3035
|
+
else if (Array.isArray(next)) {
|
|
3036
|
+
if (ancestors.has(next))
|
|
3037
|
+
throw new RunnerFetchError("invalid_request");
|
|
3038
|
+
ancestors.add(next);
|
|
3039
|
+
add(2 + Math.max(0, next.length - 1));
|
|
3040
|
+
stack.push({ depth: frame.depth, exit: next });
|
|
3041
|
+
for (let index = next.length - 1; index >= 0; index -= 1) {
|
|
3042
|
+
stack.push({ value: next[index], depth: frame.depth + 1 });
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
else if (isDict(next)) {
|
|
3046
|
+
if (ancestors.has(next))
|
|
3047
|
+
throw new RunnerFetchError("invalid_request");
|
|
3048
|
+
ancestors.add(next);
|
|
3049
|
+
const entries = Object.entries(next);
|
|
3050
|
+
add(2 + Math.max(0, entries.length - 1));
|
|
3051
|
+
stack.push({ depth: frame.depth, exit: next });
|
|
3052
|
+
for (let index = entries.length - 1; index >= 0; index -= 1) {
|
|
3053
|
+
const [key, entryValue] = entries[index];
|
|
3054
|
+
add(runnerEscapedJsonBytes(key, MAX_RUNNER_REQUEST_BYTES - bytes) + 1);
|
|
3055
|
+
stack.push({ value: entryValue, depth: frame.depth + 1 });
|
|
3056
|
+
}
|
|
3057
|
+
}
|
|
3058
|
+
else
|
|
3059
|
+
throw new RunnerFetchError("invalid_request");
|
|
3060
|
+
}
|
|
3061
|
+
const encoded = JSON.stringify(rawBody, (_key, value) => (value === NSNull ? null : value));
|
|
3062
|
+
if (encoded === undefined)
|
|
3063
|
+
throw new RunnerFetchError("invalid_request");
|
|
3064
|
+
if (runnerUtf8Bytes(encoded, MAX_RUNNER_REQUEST_BYTES) > MAX_RUNNER_REQUEST_BYTES) {
|
|
3065
|
+
throw new RunnerFetchError("request_too_large");
|
|
3066
|
+
}
|
|
3067
|
+
return encoded;
|
|
3068
|
+
}
|
|
3069
|
+
function validateRunnerRequest(url, headers) {
|
|
3070
|
+
if (runnerUtf8Bytes(url, MAX_RUNNER_URL_BYTES) > MAX_RUNNER_URL_BYTES) {
|
|
3071
|
+
throw new RunnerFetchError("request_too_large");
|
|
3072
|
+
}
|
|
3073
|
+
const entries = Object.entries(headers).filter(([name]) => !name.startsWith("__"));
|
|
3074
|
+
if (entries.length > MAX_RUNNER_HEADER_COUNT)
|
|
3075
|
+
throw new RunnerFetchError("request_too_large");
|
|
3076
|
+
let bytes = 0;
|
|
3077
|
+
for (const [name, value] of entries) {
|
|
3078
|
+
bytes += runnerUtf8Bytes(name, MAX_RUNNER_HEADER_BYTES - bytes)
|
|
3079
|
+
+ runnerUtf8Bytes(string(value), MAX_RUNNER_HEADER_BYTES - bytes) + 4;
|
|
3080
|
+
if (bytes > MAX_RUNNER_HEADER_BYTES)
|
|
3081
|
+
throw new RunnerFetchError("request_too_large");
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
async function readRunnerResponse(res, signal) {
|
|
3085
|
+
const advertised = Number(res.headers.get("content-length"));
|
|
3086
|
+
if (Number.isFinite(advertised) && advertised > MAX_RUNNER_RESPONSE_BYTES) {
|
|
3087
|
+
void res.body?.cancel("response_too_large").catch(() => { });
|
|
3088
|
+
throw new RunnerFetchError("response_too_large");
|
|
3089
|
+
}
|
|
3090
|
+
if (res.body === null)
|
|
3091
|
+
return new Uint8Array();
|
|
3092
|
+
const reader = res.body.getReader();
|
|
3093
|
+
const chunks = [];
|
|
3094
|
+
const abort = () => { void reader.cancel("timeout").catch(() => { }); };
|
|
3095
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
3096
|
+
let size = 0;
|
|
3097
|
+
try {
|
|
3098
|
+
for (;;) {
|
|
3099
|
+
if (signal.aborted)
|
|
3100
|
+
throw new RunnerFetchError("timeout");
|
|
3101
|
+
const { done, value } = await reader.read();
|
|
3102
|
+
if (signal.aborted)
|
|
3103
|
+
throw new RunnerFetchError("timeout");
|
|
3104
|
+
if (done)
|
|
3105
|
+
break;
|
|
3106
|
+
size += value.byteLength;
|
|
3107
|
+
if (size > MAX_RUNNER_RESPONSE_BYTES) {
|
|
3108
|
+
void reader.cancel("response_too_large").catch(() => { });
|
|
3109
|
+
throw new RunnerFetchError("response_too_large");
|
|
3110
|
+
}
|
|
3111
|
+
chunks.push(value);
|
|
3112
|
+
}
|
|
3113
|
+
const body = new Uint8Array(size);
|
|
3114
|
+
let offset = 0;
|
|
3115
|
+
for (const chunk of chunks) {
|
|
3116
|
+
body.set(chunk, offset);
|
|
3117
|
+
offset += chunk.byteLength;
|
|
3118
|
+
}
|
|
3119
|
+
return body;
|
|
3120
|
+
}
|
|
3121
|
+
finally {
|
|
3122
|
+
signal.removeEventListener("abort", abort);
|
|
3123
|
+
chunks.length = 0;
|
|
3124
|
+
reader.releaseLock();
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
function runnerHttpsDowngrade(requestUrl, responseUrl) {
|
|
3128
|
+
if (responseUrl.length === 0)
|
|
3129
|
+
return false;
|
|
3130
|
+
try {
|
|
3131
|
+
const base = typeof location !== "undefined" ? location.href : undefined;
|
|
3132
|
+
return new URL(requestUrl, base).protocol === "https:" && new URL(responseUrl).protocol === "http:";
|
|
3133
|
+
}
|
|
3134
|
+
catch {
|
|
3135
|
+
return false;
|
|
3136
|
+
}
|
|
3137
|
+
}
|
|
3138
|
+
/**
|
|
3139
|
+
* THE NETWORK MACHINE IS OPTIONAL (the `__DSX_OPTIONAL_JS_GLOBALS__` precedent in jse/core.ts).
|
|
3140
|
+
*
|
|
3141
|
+
* `runnerFetchFull` below is ~9 KB of source — the request guards, the body encoder with its
|
|
3142
|
+
* node/depth/byte ceilings, the header validator, the response reader and the https-downgrade
|
|
3143
|
+
* check. All of it is mandatory for a body that reaches the network and DEAD WEIGHT for one
|
|
3144
|
+
* that does not, which is most self-contained embeds: a card that renders a component has no
|
|
3145
|
+
* `fetch(` and no `fetch:` verb anywhere in its bodies.
|
|
3146
|
+
*
|
|
3147
|
+
* The bundler folds the flag and drops the whole machine with its helpers, because this is its
|
|
3148
|
+
* only reference. A build that does not set the flag keeps everything, so the default is the
|
|
3149
|
+
* full runtime and only a build that has PROVEN the absence pays nothing.
|
|
3150
|
+
*/
|
|
3151
|
+
const runnerFetch = globalThis
|
|
3152
|
+
.__DSX_OPTIONAL_FETCH__ !== false
|
|
3153
|
+
? (url, opts, transport) => runnerFetchFull(url, opts, false, 15_000, transport)
|
|
3154
|
+
: () => Promise.resolve(REFUSED_FETCH);
|
|
3155
|
+
/** THE RESPONSE SHAPE every fetch answers (jse.md fetch companions, the natives' `__response`):
|
|
3156
|
+
* `ok` / `status` / `headers.get()` / `json()` / `text()`. The raw text rides as `text` (derived
|
|
3157
|
+
* from `data` when a host transport answered only that), headers carry their marker. */
|
|
3158
|
+
function responseShape(r) {
|
|
3159
|
+
const data = r["data"];
|
|
3160
|
+
const text = typeof r["text"] === "string" ? r["text"]
|
|
3161
|
+
: typeof data === "string" ? data : data === undefined || data === null || data === NSNull ? "" : JSON.stringify(data);
|
|
3162
|
+
const headers = { __headers: true };
|
|
3163
|
+
if (isDict(r["headers"])) {
|
|
3164
|
+
for (const [k, v] of Object.entries(r["headers"]))
|
|
3165
|
+
if (!k.startsWith("__"))
|
|
3166
|
+
headers[k.toLowerCase()] = v;
|
|
3167
|
+
}
|
|
3168
|
+
return { ...r, __response: true, text, headers };
|
|
3169
|
+
}
|
|
3170
|
+
/** Shared bounded wire transport for runner hosts. It does not invoke RunnerFetchSeam. */
|
|
3171
|
+
export function runnerFetchTransport(url, opts, timeoutMs = 15_000) {
|
|
3172
|
+
const boundedMs = Number.isFinite(timeoutMs) ? Math.max(1, Math.min(15_000, timeoutMs)) : 15_000;
|
|
3173
|
+
return runnerFetchFull(url, opts, true, boundedMs);
|
|
3174
|
+
}
|
|
3175
|
+
async function runnerFetchFull(url, opts, transportOnly = false, timeoutMs = 15_000, transport) {
|
|
3176
|
+
const method = string(opts["method"] ?? "GET") || "GET";
|
|
3177
|
+
const headers = {};
|
|
3178
|
+
if (isDict(opts["headers"])) {
|
|
3179
|
+
for (const [k, v] of Object.entries(opts["headers"])) {
|
|
3180
|
+
if (!k.startsWith("__"))
|
|
3181
|
+
headers[k] = string(v);
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
let body;
|
|
3185
|
+
try {
|
|
3186
|
+
validateRunnerRequest(url, isDict(opts["headers"]) ? opts["headers"] : {});
|
|
3187
|
+
body = prepareRunnerBody(opts["body"]);
|
|
3188
|
+
// a GET or HEAD with a real body is refused before sending, as the Fetch standard refuses it
|
|
3189
|
+
if (body !== undefined && (method.toUpperCase() === "GET" || method.toUpperCase() === "HEAD")) {
|
|
3190
|
+
throw new RunnerFetchError("invalid_request");
|
|
3191
|
+
}
|
|
3192
|
+
if (body !== undefined && typeof opts["body"] !== "string"
|
|
3193
|
+
&& !Object.keys(headers).some((k) => k.toLowerCase() === "content-type")) {
|
|
3194
|
+
headers["Content-Type"] = "application/json";
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
catch (error) {
|
|
3198
|
+
return { ok: false, status: -2, data: null, error: error.code ?? "invalid_request" };
|
|
3199
|
+
}
|
|
3200
|
+
// Host seams receive the authored shape for backwards compatibility, but only
|
|
3201
|
+
// after the same request guard as the real transport has accepted it.
|
|
3202
|
+
if (!transportOnly) {
|
|
3203
|
+
const selected = transport ?? RunnerFetchSeam.impl;
|
|
3204
|
+
if (selected)
|
|
3205
|
+
return selected(url, opts);
|
|
3206
|
+
}
|
|
3207
|
+
const controller = new AbortController();
|
|
3208
|
+
let timer;
|
|
3209
|
+
let received;
|
|
3210
|
+
const timeout = new Promise((resolve) => {
|
|
3211
|
+
timer = setTimeout(() => {
|
|
3212
|
+
controller.abort();
|
|
3213
|
+
if (received?.body && !received.body.locked)
|
|
3214
|
+
void received.body.cancel("timeout").catch(() => { });
|
|
3215
|
+
resolve({ ok: false, status: -1, aborted: true, data: null, error: "timeout" });
|
|
3216
|
+
}, timeoutMs);
|
|
3217
|
+
});
|
|
3218
|
+
const request = async () => {
|
|
3219
|
+
let res;
|
|
3220
|
+
try {
|
|
3221
|
+
res = await fetch(url, { method, headers, body, signal: controller.signal,
|
|
3222
|
+
...(opts["redirect"] === "error" ? { redirect: "error" } : {}) });
|
|
3223
|
+
received = res;
|
|
3224
|
+
if (controller.signal.aborted) {
|
|
3225
|
+
void res.body?.cancel("timeout").catch(() => { });
|
|
3226
|
+
return { ok: false, status: -1, aborted: true, data: null, error: "timeout" };
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
catch {
|
|
3230
|
+
return controller.signal.aborted
|
|
3231
|
+
? { ok: false, status: -1, aborted: true, data: null, error: "timeout" }
|
|
3232
|
+
: { ok: false, status: 0, data: null, error: "network" };
|
|
3233
|
+
}
|
|
3234
|
+
const outHeaders = {};
|
|
3235
|
+
res.headers.forEach((value, key) => { outHeaders[key] = value; });
|
|
3236
|
+
if (runnerHttpsDowngrade(url, res.url)) {
|
|
3237
|
+
void res.body?.cancel("insecure_redirect").catch(() => { });
|
|
3238
|
+
return { ok: false, status: -2, data: null, headers: outHeaders, error: "insecure_redirect" };
|
|
3239
|
+
}
|
|
3240
|
+
try {
|
|
3241
|
+
const contentType = (res.headers.get("content-type") ?? "").toLowerCase();
|
|
3242
|
+
const bytes = await readRunnerResponse(res, controller.signal);
|
|
3243
|
+
const text = new TextDecoder().decode(bytes);
|
|
3244
|
+
const data = contentType.includes("json") ? (text.length > 0 ? JSON.parse(text) : null) : text;
|
|
3245
|
+
return { ok: res.ok, status: res.status, data, text, headers: outHeaders };
|
|
3246
|
+
}
|
|
3247
|
+
catch (error) {
|
|
3248
|
+
if (controller.signal.aborted)
|
|
3249
|
+
return { ok: false, status: -1, aborted: true, data: null, headers: outHeaders, error: "timeout" };
|
|
3250
|
+
return { ok: false, status: -2, data: null, headers: outHeaders,
|
|
3251
|
+
error: error instanceof RunnerFetchError ? error.code : "invalid_response" };
|
|
3252
|
+
}
|
|
3253
|
+
};
|
|
3254
|
+
try {
|
|
3255
|
+
return await Promise.race([request(), timeout]);
|
|
3256
|
+
}
|
|
3257
|
+
finally {
|
|
3258
|
+
if (timer !== undefined)
|
|
3259
|
+
clearTimeout(timer);
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
// ── statement token walker (shared shape with JSEval) ────────────────────────────────
|
|
3263
|
+
class StmtWalker {
|
|
3264
|
+
i = 0;
|
|
3265
|
+
t;
|
|
3266
|
+
constructor(t) {
|
|
3267
|
+
this.t = t;
|
|
3268
|
+
}
|
|
3269
|
+
cur() { return this.i < this.t.length ? this.t[this.i] : null; }
|
|
3270
|
+
capture(stops) {
|
|
3271
|
+
const out = [];
|
|
3272
|
+
let d = 0;
|
|
3273
|
+
for (;;) {
|
|
3274
|
+
const tk = this.cur();
|
|
3275
|
+
if (tk === null)
|
|
3276
|
+
break;
|
|
3277
|
+
if (tk.kind === "op") {
|
|
3278
|
+
const o = tk.v;
|
|
3279
|
+
if (["(", "[", "{"].includes(o)) {
|
|
3280
|
+
d += 1;
|
|
3281
|
+
out.push(tk);
|
|
3282
|
+
this.i += 1;
|
|
3283
|
+
continue;
|
|
3284
|
+
}
|
|
3285
|
+
if ([")", "]", "}"].includes(o)) {
|
|
3286
|
+
if (d === 0)
|
|
3287
|
+
break;
|
|
3288
|
+
d -= 1;
|
|
3289
|
+
out.push(tk);
|
|
3290
|
+
this.i += 1;
|
|
3291
|
+
continue;
|
|
3292
|
+
}
|
|
3293
|
+
if (d === 0 && stops.has(o))
|
|
3294
|
+
break;
|
|
3295
|
+
}
|
|
3296
|
+
out.push(tk);
|
|
3297
|
+
this.i += 1;
|
|
3298
|
+
}
|
|
3299
|
+
return out;
|
|
3300
|
+
}
|
|
3301
|
+
captureParen() {
|
|
3302
|
+
// MEMBER FOLD, the stopgap store.ts canHoldCall names (Article 17.4, EMBED-MEMBER-FOLDS-STOPGAP-1120): the only callers are the if, while, do, for,
|
|
3303
|
+
// switch, try and function arms of `statement` and their module functions, each behind one of these four flags.
|
|
3304
|
+
if (globalThis.__DSX_OPTIONAL_IF_STATEMENTS__ !== false
|
|
3305
|
+
|| globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false
|
|
3306
|
+
|| globalThis.__DSX_OPTIONAL_BLOCK_CONTROL__ !== false
|
|
3307
|
+
|| globalThis.__DSX_OPTIONAL_STATEMENTS__ !== false) {
|
|
3308
|
+
const out = [];
|
|
3309
|
+
if (!isOpTok(this.cur() ?? undefined, "("))
|
|
3310
|
+
return out;
|
|
3311
|
+
this.i += 1;
|
|
3312
|
+
let d = 1;
|
|
3313
|
+
for (;;) {
|
|
3314
|
+
const tk = this.cur();
|
|
3315
|
+
if (tk === null)
|
|
3316
|
+
break;
|
|
3317
|
+
if (tk.kind === "op" && tk.v === "(")
|
|
3318
|
+
d += 1;
|
|
3319
|
+
else if (tk.kind === "op" && tk.v === ")") {
|
|
3320
|
+
d -= 1;
|
|
3321
|
+
if (d === 0) {
|
|
3322
|
+
this.i += 1;
|
|
3323
|
+
break;
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
out.push(tk);
|
|
3327
|
+
this.i += 1;
|
|
3328
|
+
}
|
|
3329
|
+
return out;
|
|
3330
|
+
}
|
|
3331
|
+
return [];
|
|
3332
|
+
}
|
|
3333
|
+
skipBranch() {
|
|
3334
|
+
// the same member fold as captureParen
|
|
3335
|
+
if (globalThis.__DSX_OPTIONAL_IF_STATEMENTS__ !== false
|
|
3336
|
+
|| globalThis.__DSX_OPTIONAL_BLOCK_ITERATION__ !== false
|
|
3337
|
+
|| globalThis.__DSX_OPTIONAL_BLOCK_CONTROL__ !== false
|
|
3338
|
+
|| globalThis.__DSX_OPTIONAL_STATEMENTS__ !== false) {
|
|
3339
|
+
if (isOpTok(this.cur() ?? undefined, "{")) {
|
|
3340
|
+
let d = 0;
|
|
3341
|
+
for (;;) {
|
|
3342
|
+
const tk = this.cur();
|
|
3343
|
+
if (tk === null)
|
|
3344
|
+
return;
|
|
3345
|
+
if (tk.kind === "op" && tk.v === "{")
|
|
3346
|
+
d += 1;
|
|
3347
|
+
else if (tk.kind === "op" && tk.v === "}") {
|
|
3348
|
+
d -= 1;
|
|
3349
|
+
this.i += 1;
|
|
3350
|
+
if (d === 0)
|
|
3351
|
+
return;
|
|
3352
|
+
continue;
|
|
3353
|
+
}
|
|
3354
|
+
this.i += 1;
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
else {
|
|
3358
|
+
// A ONE-STATEMENT BRANCH ENDS AT ITS OWN `;`, not at a brace of an argument inside it:
|
|
3359
|
+
// `for (const x of xs) await dsx.module.a.b({ x: x }); next()` stopped at the object
|
|
3360
|
+
// literal's `}`, so the walk resumed mid-statement and `next()` never ran (logic parity
|
|
3361
|
+
// A2, actions `await-depth-brace-less-*`).
|
|
3362
|
+
let depth = 0;
|
|
3363
|
+
for (;;) {
|
|
3364
|
+
const tk = this.cur();
|
|
3365
|
+
if (tk === null)
|
|
3366
|
+
return;
|
|
3367
|
+
if (tk.kind === "op" && (tk.v === "(" || tk.v === "[" || tk.v === "{"))
|
|
3368
|
+
depth += 1;
|
|
3369
|
+
else if (tk.kind === "op" && (tk.v === ")" || tk.v === "]" || tk.v === "}")) {
|
|
3370
|
+
if (depth === 0)
|
|
3371
|
+
return;
|
|
3372
|
+
depth -= 1;
|
|
3373
|
+
}
|
|
3374
|
+
else if (tk.kind === "op" && tk.v === ";" && depth === 0) {
|
|
3375
|
+
this.i += 1;
|
|
3376
|
+
return;
|
|
3377
|
+
}
|
|
3378
|
+
this.i += 1;
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
}
|
|
3383
|
+
skipFunction() {
|
|
3384
|
+
// the same member fold: its one caller is the `function` arm under `__DSX_OPTIONAL_STATEMENTS__`
|
|
3385
|
+
if (globalThis.__DSX_OPTIONAL_STATEMENTS__ !== false) {
|
|
3386
|
+
for (;;) {
|
|
3387
|
+
const tk = this.cur();
|
|
3388
|
+
if (tk === null)
|
|
3389
|
+
return;
|
|
3390
|
+
if (tk.kind === "op" && tk.v === "{")
|
|
3391
|
+
break;
|
|
3392
|
+
this.i += 1;
|
|
3393
|
+
}
|
|
3394
|
+
this.skipBranch();
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
/** One private budget guard for the foldable loop arms. */
|
|
3399
|
+
function budgetExceeded(r) {
|
|
3400
|
+
r.env.loopWork.count += 1;
|
|
3401
|
+
const cap = r.env.loopCap ?? LOOP_CAP;
|
|
3402
|
+
if (r.env.loopWork.count > cap) {
|
|
3403
|
+
console.warn(`[dsx runner] loop budget (${cap}) exceeded — loop contained`);
|
|
3404
|
+
return true;
|
|
3405
|
+
}
|
|
3406
|
+
// The wall clock is checked HERE and nowhere else for the same reason the loop count is:
|
|
3407
|
+
// this is the one point every iteration passes through. A deadline enforced only by the
|
|
3408
|
+
// caller racing a promise abandons the response while the body keeps burning the isolate.
|
|
3409
|
+
const deadline = r.env.deadlineAt;
|
|
3410
|
+
return deadline !== undefined && Date.now() > deadline;
|
|
3411
|
+
}
|
|
3412
|
+
/** The tail of the in-flight `dsx.context.*` call INTO each provider runner (see the call site).
|
|
3413
|
+
* Module level, keyed by runner: as a class method it rode every widget,
|
|
3414
|
+
* and a slice with no `<context>` never reaches the call site (__DSX_OPTIONAL_CONTEXT__). */
|
|
3415
|
+
const contextTails = new WeakMap();
|
|
3416
|
+
/** Run one context call into `provider` after the one before it has finished (bounded by
|
|
3417
|
+
* ENTRY_LOCK_BOUND_MS). No ledger is touched here: the caller lends its own. */
|
|
3418
|
+
async function contextFrame(provider, work) {
|
|
3419
|
+
const prior = contextTails.get(provider) ?? Promise.resolve();
|
|
3420
|
+
let release;
|
|
3421
|
+
contextTails.set(provider, new Promise((r) => { release = r; }));
|
|
3422
|
+
let bound;
|
|
3423
|
+
await Promise.race([prior, new Promise((r) => { bound = setTimeout(r, ActionRunner.ENTRY_LOCK_BOUND_MS); })]);
|
|
3424
|
+
clearTimeout(bound);
|
|
3425
|
+
try {
|
|
3426
|
+
await work();
|
|
3427
|
+
}
|
|
3428
|
+
finally {
|
|
3429
|
+
release();
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
/** The one named crossing: an ActionRunner read as the arm seam above. */
|
|
3433
|
+
function arm(runner) {
|
|
3434
|
+
return runner;
|
|
3435
|
+
}
|
|
3436
|
+
/** (Module level, the RunnerArmSeam pattern below: a class method is never
|
|
3437
|
+
* tree-shaken, and this arm cost every widget its bytes.) AN AWAITED CALL AT THE HEAD OF A STATEMENT CALL'S ARGUMENT (actions corpus
|
|
3438
|
+
* `await-in-call-argument-*`, backlog jse-await-in-call-args). `list.push(await
|
|
3439
|
+
* dsx.action.x())` used to reach the synchronous evaluator, which refused the await
|
|
3440
|
+
* (jse_await_position) while the call still ran with null, so the list gained a null. The
|
|
3441
|
+
* runner owns this position as it owns a declarator: the arguments up to the last awaited one
|
|
3442
|
+
* evaluate LEFT TO RIGHT (the awaited ones through the await door), each lands in a hidden
|
|
3443
|
+
* local, and the call then runs with those locals in their place. An await anywhere deeper in
|
|
3444
|
+
* an argument still refuses by name. The twins: JseRunner.kt and Stack.swift
|
|
3445
|
+
* `awaitedArgsCall`. Answers true when it ran the statement. */
|
|
3446
|
+
async function awaitedArgsCall(runner, toks, scope) {
|
|
3447
|
+
const r = arm(runner);
|
|
3448
|
+
if (toks.length < 4 || toks[0].kind !== "ident" || toks[0].v === "await" || !isOpTok(toks[1], "("))
|
|
3449
|
+
return false;
|
|
3450
|
+
const argsList = [];
|
|
3451
|
+
let cur = [];
|
|
3452
|
+
let depth = 0;
|
|
3453
|
+
let close = -1;
|
|
3454
|
+
for (let i = 1; i < toks.length; i++) {
|
|
3455
|
+
const t = toks[i];
|
|
3456
|
+
if (t.kind === "op" && (t.v === "(" || t.v === "[" || t.v === "{")) {
|
|
3457
|
+
depth += 1;
|
|
3458
|
+
if (depth === 1)
|
|
3459
|
+
continue;
|
|
3460
|
+
}
|
|
3461
|
+
else if (t.kind === "op" && (t.v === ")" || t.v === "]" || t.v === "}")) {
|
|
3462
|
+
depth -= 1;
|
|
3463
|
+
if (depth === 0) {
|
|
3464
|
+
close = i;
|
|
3465
|
+
break;
|
|
3466
|
+
}
|
|
3467
|
+
}
|
|
3468
|
+
else if (depth === 1 && t.kind === "op" && t.v === ",") {
|
|
3469
|
+
argsList.push(cur);
|
|
3470
|
+
cur = [];
|
|
3471
|
+
continue;
|
|
3472
|
+
}
|
|
3473
|
+
cur.push(t);
|
|
3474
|
+
}
|
|
3475
|
+
if (close !== toks.length - 1)
|
|
3476
|
+
return false;
|
|
3477
|
+
if (cur.length > 0)
|
|
3478
|
+
argsList.push(cur);
|
|
3479
|
+
let last = -1;
|
|
3480
|
+
argsList.forEach((a, k) => { if (a.length > 1 && isIdentTok(a[0], "await"))
|
|
3481
|
+
last = k; });
|
|
3482
|
+
if (last < 0)
|
|
3483
|
+
return false;
|
|
3484
|
+
const temps = [];
|
|
3485
|
+
const call = [toks[0], toks[1]];
|
|
3486
|
+
for (let k = 0; k < argsList.length; k++) {
|
|
3487
|
+
if (k > 0)
|
|
3488
|
+
call.push({ kind: "op", v: "," });
|
|
3489
|
+
if (k > last) {
|
|
3490
|
+
call.push(...argsList[k]);
|
|
3491
|
+
continue;
|
|
3492
|
+
}
|
|
3493
|
+
const v = await r.evalMaybeAsync(argsList[k], scope);
|
|
3494
|
+
if (r.flow !== null) {
|
|
3495
|
+
dropTemps(scope, temps);
|
|
3496
|
+
return true;
|
|
3497
|
+
}
|
|
3498
|
+
const name = `__dsx_await_arg_${awaitArgSeq++}`;
|
|
3499
|
+
temps.push(name);
|
|
3500
|
+
scope[name] = v ?? NSNull;
|
|
3501
|
+
declareLocal(scope, name);
|
|
3502
|
+
call.push({ kind: "ident", v: name });
|
|
3503
|
+
}
|
|
3504
|
+
call.push(toks[close]);
|
|
3505
|
+
try {
|
|
3506
|
+
await r.leafStatement(call, scope);
|
|
3507
|
+
}
|
|
3508
|
+
finally {
|
|
3509
|
+
dropTemps(scope, temps);
|
|
3510
|
+
}
|
|
3511
|
+
return true;
|
|
3512
|
+
}
|
|
3513
|
+
let awaitArgSeq = 0;
|
|
3514
|
+
function dropTemps(scope, temps) {
|
|
3515
|
+
const set = scope[JSE_SCOPE_LOCALS];
|
|
3516
|
+
for (const n of temps) {
|
|
3517
|
+
delete scope[n];
|
|
3518
|
+
set?.delete(n);
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
// -- THE STATEMENT RUNNER'S FOLDABLE ARMS ------------------------------------------------
|
|
3522
|
+
//
|
|
3523
|
+
// Each of the three groups below is dispatched behind an inlined `__DSX_OPTIONAL_*` read in
|
|
3524
|
+
// `statement()`, and each lives at module level rather than on ActionRunner for one reason:
|
|
3525
|
+
// esbuild cannot drop a class method. The guard alone folds the DISPATCH and leaves the
|
|
3526
|
+
// bodies, which is what shipped until — the evaluator's copy of block control
|
|
3527
|
+
// was folded out of every widget while the runner's copy was still in the bundle. Measured
|
|
3528
|
+
// on the EmbedCard slice, the G10 widget law's own subject: the five block arms are 822
|
|
3529
|
+
// gzip bytes and the effect verbs another 687.
|
|
3530
|
+
//
|
|
3531
|
+
// Nothing about the language moves here. Unfolded — every full app, SSR, every test — the
|
|
3532
|
+
// dispatch reads `true !== false` and calls exactly the function the method used to be.
|
|
3533
|
+
async function ifStmt(runner, w, scope, topLevel) {
|
|
3534
|
+
const r = arm(runner);
|
|
3535
|
+
w.i += 1;
|
|
3536
|
+
const c = w.captureParen();
|
|
3537
|
+
const cond = truthy(r.evalSync(c, scope));
|
|
3538
|
+
await runBranch(runner, w, scope, cond, topLevel);
|
|
3539
|
+
if (isIdentTok(w.cur() ?? undefined, "else")) {
|
|
3540
|
+
w.i += 1;
|
|
3541
|
+
if (isIdentTok(w.cur() ?? undefined, "if")) {
|
|
3542
|
+
if (cond) {
|
|
3543
|
+
skipIfChain(w);
|
|
3544
|
+
return;
|
|
3545
|
+
}
|
|
3546
|
+
await ifStmt(runner, w, scope, topLevel);
|
|
3547
|
+
}
|
|
3548
|
+
else {
|
|
3549
|
+
await runBranch(runner, w, scope, !cond, topLevel);
|
|
3550
|
+
}
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
async function runBranch(runner, w, scope, execute, topLevel) {
|
|
3554
|
+
const r = arm(runner);
|
|
3555
|
+
if (!execute) {
|
|
3556
|
+
w.skipBranch();
|
|
3557
|
+
return;
|
|
3558
|
+
}
|
|
3559
|
+
if (isOpTok(w.cur() ?? undefined, "{")) {
|
|
3560
|
+
const start = w.i;
|
|
3561
|
+
w.i += 1;
|
|
3562
|
+
openBlock(scope);
|
|
3563
|
+
try {
|
|
3564
|
+
await r.runStatements(w, scope, topLevel);
|
|
3565
|
+
}
|
|
3566
|
+
finally {
|
|
3567
|
+
closeBlock(scope);
|
|
3568
|
+
}
|
|
3569
|
+
if (isOpTok(w.cur() ?? undefined, "}")) {
|
|
3570
|
+
w.i += 1;
|
|
3571
|
+
}
|
|
3572
|
+
else {
|
|
3573
|
+
// a flow signal stopped execution MID-block (statements remain after a
|
|
3574
|
+
// throw/return) — realign the walker to the block's end, so the owning
|
|
3575
|
+
// construct (try's catch, if's else) still sees what follows. The natives
|
|
3576
|
+
// are immune by construction (they capture the branch text first).
|
|
3577
|
+
w.i = start;
|
|
3578
|
+
w.skipBranch();
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
else {
|
|
3582
|
+
await r.statement(w, scope, topLevel);
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
async function whileStmt(runner, w, scope) {
|
|
3586
|
+
const r = arm(runner);
|
|
3587
|
+
w.i += 1;
|
|
3588
|
+
const c = w.captureParen();
|
|
3589
|
+
const bodyStart = w.i;
|
|
3590
|
+
for (;;) {
|
|
3591
|
+
if (!truthy(r.evalSync(c, scope))) {
|
|
3592
|
+
w.i = bodyStart;
|
|
3593
|
+
w.skipBranch();
|
|
3594
|
+
return;
|
|
3595
|
+
}
|
|
3596
|
+
if (budgetExceeded(r)) {
|
|
3597
|
+
w.i = bodyStart;
|
|
3598
|
+
w.skipBranch();
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3601
|
+
w.i = bodyStart;
|
|
3602
|
+
await runBranch(runner, w, scope, true, false);
|
|
3603
|
+
if (r.flow?.kind === "break") {
|
|
3604
|
+
r.flow = null;
|
|
3605
|
+
w.i = bodyStart;
|
|
3606
|
+
w.skipBranch();
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3609
|
+
if (r.flow?.kind === "continue")
|
|
3610
|
+
r.flow = null;
|
|
3611
|
+
if (r.flow !== null) {
|
|
3612
|
+
w.i = bodyStart;
|
|
3613
|
+
w.skipBranch();
|
|
3614
|
+
return;
|
|
3615
|
+
}
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
/** `do { … } while (cond)` — body-first, budgeted, break/continue honored. */
|
|
3619
|
+
async function doWhileStmt(runner, w, scope) {
|
|
3620
|
+
const r = arm(runner);
|
|
3621
|
+
w.i += 1; // 'do'
|
|
3622
|
+
const bodyStart = w.i;
|
|
3623
|
+
w.skipBranch();
|
|
3624
|
+
let cond = [];
|
|
3625
|
+
if (isIdentTok(w.cur() ?? undefined, "while")) {
|
|
3626
|
+
w.i += 1;
|
|
3627
|
+
cond = w.captureParen();
|
|
3628
|
+
}
|
|
3629
|
+
const afterLoop = w.i;
|
|
3630
|
+
for (;;) {
|
|
3631
|
+
if (budgetExceeded(r))
|
|
3632
|
+
break;
|
|
3633
|
+
w.i = bodyStart;
|
|
3634
|
+
await runBranch(runner, w, scope, true, false);
|
|
3635
|
+
if (r.flow?.kind === "break") {
|
|
3636
|
+
r.flow = null;
|
|
3637
|
+
break;
|
|
3638
|
+
}
|
|
3639
|
+
if (r.flow?.kind === "continue")
|
|
3640
|
+
r.flow = null;
|
|
3641
|
+
if (r.flow !== null)
|
|
3642
|
+
break;
|
|
3643
|
+
if (!truthy(r.evalSync(cond, scope)))
|
|
3644
|
+
break;
|
|
3645
|
+
}
|
|
3646
|
+
w.i = afterLoop;
|
|
3647
|
+
}
|
|
3648
|
+
async function forStmt(runner, w, scope) {
|
|
3649
|
+
// THE LOOP'S OWN FRAME (sweep 6): the head's `let`/`const` belong to the loop, not the body
|
|
3650
|
+
// around it, and each iteration gets a fresh binding of them (forStmtIn rebinds).
|
|
3651
|
+
openBlock(scope);
|
|
3652
|
+
try {
|
|
3653
|
+
await forStmtIn(runner, w, scope);
|
|
3654
|
+
}
|
|
3655
|
+
finally {
|
|
3656
|
+
closeBlock(scope);
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
async function forStmtIn(runner, w, scope) {
|
|
3660
|
+
const r = arm(runner);
|
|
3661
|
+
w.i += 1;
|
|
3662
|
+
const header = w.captureParen();
|
|
3663
|
+
// for (const x of arr) — detect a top-level `of`
|
|
3664
|
+
const ofIdx = header.findIndex((t, i) => i > 0 && t.kind === "ident" && t.v === "of");
|
|
3665
|
+
const bodyStart = w.i;
|
|
3666
|
+
if (ofIdx >= 0) {
|
|
3667
|
+
let nameIdx = 0;
|
|
3668
|
+
if (isIdentTok(header[0], "const") || isIdentTok(header[0], "let") || isIdentTok(header[0], "var"))
|
|
3669
|
+
nameIdx = 1;
|
|
3670
|
+
// loop var: an ident, or a flat `[a, b]` / `{a, b}` pattern (parseDeclarators reads it)
|
|
3671
|
+
const decls = parseDeclarators(header.slice(nameIdx, ofIdx));
|
|
3672
|
+
const pattern = decls.length > 0 ? decls[0].pattern : null;
|
|
3673
|
+
const arr = spreadValues(r.evalSync(header.slice(ofIdx + 1), scope)); // arrays, strings, Set, Map
|
|
3674
|
+
for (const e of arr) {
|
|
3675
|
+
if (budgetExceeded(r))
|
|
3676
|
+
break;
|
|
3677
|
+
if (pattern !== null) {
|
|
3678
|
+
bindPattern(pattern, e, (n, val) => { newBinding(scope, n); scope[n] = val ?? NSNull; declareLocal(scope, n); }, (toks) => r.evalSync(toks, scope));
|
|
3679
|
+
}
|
|
3680
|
+
w.i = bodyStart;
|
|
3681
|
+
await runBranch(runner, w, scope, true, false);
|
|
3682
|
+
if (r.flow?.kind === "break") {
|
|
3683
|
+
r.flow = null;
|
|
3684
|
+
break;
|
|
3685
|
+
}
|
|
3686
|
+
if (r.flow?.kind === "continue")
|
|
3687
|
+
r.flow = null;
|
|
3688
|
+
if (r.flow !== null)
|
|
3689
|
+
break;
|
|
3690
|
+
}
|
|
3691
|
+
w.i = bodyStart;
|
|
3692
|
+
w.skipBranch();
|
|
3693
|
+
return;
|
|
3694
|
+
}
|
|
3695
|
+
// top-level semicolons — the classic-for splitter AND the for…in gate below
|
|
3696
|
+
const semis = [];
|
|
3697
|
+
let depth = 0;
|
|
3698
|
+
header.forEach((t, i) => {
|
|
3699
|
+
if (t.kind === "op" && ["(", "[", "{"].includes(t.v))
|
|
3700
|
+
depth += 1;
|
|
3701
|
+
if (t.kind === "op" && [")", "]", "}"].includes(t.v))
|
|
3702
|
+
depth -= 1;
|
|
3703
|
+
if (t.kind === "op" && t.v === ";" && depth === 0)
|
|
3704
|
+
semis.push(i);
|
|
3705
|
+
});
|
|
3706
|
+
// for (const k in obj) — dict OWN keys ("__"-internal skipped) / array indices
|
|
3707
|
+
// 0..n-1; ONLY when the header has NO top-level `;`, because a classic for's
|
|
3708
|
+
// condition may contain the `in` OPERATOR (`for (i = 0; 'a' in d; ++i)`).
|
|
3709
|
+
if (semis.length === 0) {
|
|
3710
|
+
let d2 = 0;
|
|
3711
|
+
let inIdx = -1;
|
|
3712
|
+
for (let i = 1; i < header.length; i++) {
|
|
3713
|
+
const t = header[i];
|
|
3714
|
+
if (t.kind === "op" && ["(", "[", "{"].includes(t.v))
|
|
3715
|
+
d2 += 1;
|
|
3716
|
+
else if (t.kind === "op" && [")", "]", "}"].includes(t.v))
|
|
3717
|
+
d2 -= 1;
|
|
3718
|
+
else if (d2 === 0 && t.kind === "ident" && t.v === "in") {
|
|
3719
|
+
inIdx = i;
|
|
3720
|
+
break;
|
|
3721
|
+
}
|
|
3722
|
+
}
|
|
3723
|
+
if (inIdx >= 0) {
|
|
3724
|
+
let nameIdx = 0;
|
|
3725
|
+
if (isIdentTok(header[0], "const") || isIdentTok(header[0], "let") || isIdentTok(header[0], "var"))
|
|
3726
|
+
nameIdx = 1;
|
|
3727
|
+
const decls = parseDeclarators(header.slice(nameIdx, inIdx));
|
|
3728
|
+
const pattern = decls.length > 0 ? decls[0].pattern : null;
|
|
3729
|
+
const keys = forInKeys(r.evalSync(header.slice(inIdx + 1), scope));
|
|
3730
|
+
for (const k of keys) {
|
|
3731
|
+
if (budgetExceeded(r))
|
|
3732
|
+
break;
|
|
3733
|
+
if (pattern !== null) {
|
|
3734
|
+
bindPattern(pattern, k, (n, val) => { newBinding(scope, n); scope[n] = val ?? NSNull; declareLocal(scope, n); }, (toks) => r.evalSync(toks, scope));
|
|
3735
|
+
}
|
|
3736
|
+
w.i = bodyStart;
|
|
3737
|
+
await runBranch(runner, w, scope, true, false);
|
|
3738
|
+
if (r.flow?.kind === "break") {
|
|
3739
|
+
r.flow = null;
|
|
3740
|
+
break;
|
|
3741
|
+
}
|
|
3742
|
+
if (r.flow?.kind === "continue")
|
|
3743
|
+
r.flow = null;
|
|
3744
|
+
if (r.flow !== null)
|
|
3745
|
+
break;
|
|
3746
|
+
}
|
|
3747
|
+
w.i = bodyStart;
|
|
3748
|
+
w.skipBranch();
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
}
|
|
3752
|
+
// classic for(init; cond; step)
|
|
3753
|
+
const init = semis.length > 0 ? header.slice(0, semis[0]) : header;
|
|
3754
|
+
const cond = semis.length > 1 ? header.slice(semis[0] + 1, semis[1]) : [];
|
|
3755
|
+
const step = semis.length > 1 ? header.slice(semis[1] + 1) : [];
|
|
3756
|
+
if (init.length > 0) {
|
|
3757
|
+
const iw = new StmtWalker(init);
|
|
3758
|
+
await r.statement(iw, scope, false);
|
|
3759
|
+
}
|
|
3760
|
+
const heads = blockNames(scope);
|
|
3761
|
+
for (;;) {
|
|
3762
|
+
for (const n of heads)
|
|
3763
|
+
rebind(scope, n);
|
|
3764
|
+
if (cond.length > 0 && !truthy(r.evalSync(cond, scope)))
|
|
3765
|
+
break;
|
|
3766
|
+
if (budgetExceeded(r))
|
|
3767
|
+
break;
|
|
3768
|
+
w.i = bodyStart;
|
|
3769
|
+
await runBranch(runner, w, scope, true, false);
|
|
3770
|
+
if (r.flow?.kind === "break") {
|
|
3771
|
+
r.flow = null;
|
|
3772
|
+
break;
|
|
3773
|
+
}
|
|
3774
|
+
if (r.flow?.kind === "continue")
|
|
3775
|
+
r.flow = null;
|
|
3776
|
+
if (r.flow !== null)
|
|
3777
|
+
break;
|
|
3778
|
+
if (step.length > 0)
|
|
3779
|
+
await r.leafStatement(jsSugar(step), scope);
|
|
3780
|
+
}
|
|
3781
|
+
w.i = bodyStart;
|
|
3782
|
+
w.skipBranch();
|
|
3783
|
+
}
|
|
3784
|
+
const BLOCK_ITERATION_RUN_IMPL = { whileStmt, doWhileStmt, forStmt };
|
|
3785
|
+
// These walkers belong only to if/switch arms. Generic block/function skipping stays
|
|
3786
|
+
// on StmtWalker because declarations and loops reach it independently.
|
|
3787
|
+
/** skip a full `if (…) branch [else if … else branch]` chain */
|
|
3788
|
+
function skipIfChain(w) {
|
|
3789
|
+
if (!isIdentTok(w.cur() ?? undefined, "if"))
|
|
3790
|
+
return;
|
|
3791
|
+
w.i += 1;
|
|
3792
|
+
w.captureParen();
|
|
3793
|
+
w.skipBranch();
|
|
3794
|
+
if (isIdentTok(w.cur() ?? undefined, "else")) {
|
|
3795
|
+
w.i += 1;
|
|
3796
|
+
if (isIdentTok(w.cur() ?? undefined, "if"))
|
|
3797
|
+
skipIfChain(w);
|
|
3798
|
+
else
|
|
3799
|
+
w.skipBranch();
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
/** inside a switch body: skip one statement of a non-matching case */
|
|
3803
|
+
function skipCaseStatement(w) {
|
|
3804
|
+
const tk = w.cur();
|
|
3805
|
+
if (tk === null)
|
|
3806
|
+
return;
|
|
3807
|
+
if (isIdentTok(tk, "case") || isIdentTok(tk, "default") || isOpTok(tk, "}")) {
|
|
3808
|
+
// handled by the switch loop
|
|
3809
|
+
if (isIdentTok(tk, "case")) {
|
|
3810
|
+
w.i += 1;
|
|
3811
|
+
w.capture(new Set([":"]));
|
|
3812
|
+
if (isOpTok(w.cur() ?? undefined, ":"))
|
|
3813
|
+
w.i += 1;
|
|
3814
|
+
}
|
|
3815
|
+
else if (isIdentTok(tk, "default")) {
|
|
3816
|
+
w.i += 1;
|
|
3817
|
+
if (isOpTok(w.cur() ?? undefined, ":"))
|
|
3818
|
+
w.i += 1;
|
|
3819
|
+
}
|
|
3820
|
+
return;
|
|
3821
|
+
}
|
|
3822
|
+
if (isOpTok(tk, "{")) {
|
|
3823
|
+
w.skipBranch();
|
|
3824
|
+
return;
|
|
3825
|
+
}
|
|
3826
|
+
if (isIdentTok(tk, "if")) {
|
|
3827
|
+
skipIfChain(w);
|
|
3828
|
+
return;
|
|
3829
|
+
}
|
|
3830
|
+
w.capture(new Set([";"]));
|
|
3831
|
+
if (isOpTok(w.cur() ?? undefined, ";"))
|
|
3832
|
+
w.i += 1;
|
|
3833
|
+
}
|
|
3834
|
+
function skipToBlockEnd(w) {
|
|
3835
|
+
let d = 1;
|
|
3836
|
+
for (;;) {
|
|
3837
|
+
const tk = w.cur();
|
|
3838
|
+
if (tk === null)
|
|
3839
|
+
return;
|
|
3840
|
+
if (tk.kind === "op" && tk.v === "{")
|
|
3841
|
+
d += 1;
|
|
3842
|
+
else if (tk.kind === "op" && tk.v === "}") {
|
|
3843
|
+
d -= 1;
|
|
3844
|
+
w.i += 1;
|
|
3845
|
+
if (d === 0)
|
|
3846
|
+
return;
|
|
3847
|
+
continue;
|
|
3848
|
+
}
|
|
3849
|
+
w.i += 1;
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
async function switchStmt(runner, w, scope) {
|
|
3853
|
+
const r = arm(runner);
|
|
3854
|
+
w.i += 1;
|
|
3855
|
+
const subject = r.evalSync(w.captureParen(), scope);
|
|
3856
|
+
if (!isOpTok(w.cur() ?? undefined, "{"))
|
|
3857
|
+
return;
|
|
3858
|
+
w.i += 1;
|
|
3859
|
+
openBlock(scope);
|
|
3860
|
+
try {
|
|
3861
|
+
await switchBody(runner, w, scope, subject);
|
|
3862
|
+
}
|
|
3863
|
+
finally {
|
|
3864
|
+
closeBlock(scope);
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
async function switchBody(runner, w, scope, subject) {
|
|
3868
|
+
const r = arm(runner);
|
|
3869
|
+
let matched = false;
|
|
3870
|
+
for (;;) {
|
|
3871
|
+
const tk = w.cur();
|
|
3872
|
+
if (tk === null)
|
|
3873
|
+
return;
|
|
3874
|
+
if (isOpTok(tk, "}")) {
|
|
3875
|
+
w.i += 1;
|
|
3876
|
+
break;
|
|
3877
|
+
}
|
|
3878
|
+
if (isIdentTok(tk, "case")) {
|
|
3879
|
+
w.i += 1;
|
|
3880
|
+
const caseToks = w.capture(new Set([":"]));
|
|
3881
|
+
if (isOpTok(w.cur() ?? undefined, ":"))
|
|
3882
|
+
w.i += 1;
|
|
3883
|
+
if (!matched)
|
|
3884
|
+
matched = JSE.equals(subject, r.evalSync(caseToks, scope));
|
|
3885
|
+
continue;
|
|
3886
|
+
}
|
|
3887
|
+
if (isIdentTok(tk, "default")) {
|
|
3888
|
+
w.i += 1;
|
|
3889
|
+
if (isOpTok(w.cur() ?? undefined, ":"))
|
|
3890
|
+
w.i += 1;
|
|
3891
|
+
matched = true;
|
|
3892
|
+
continue;
|
|
3893
|
+
}
|
|
3894
|
+
if (matched) {
|
|
3895
|
+
const before = w.i;
|
|
3896
|
+
await r.statement(w, scope, false);
|
|
3897
|
+
if (r.flow?.kind === "break") {
|
|
3898
|
+
r.flow = null;
|
|
3899
|
+
skipToBlockEnd(w);
|
|
3900
|
+
return;
|
|
3901
|
+
}
|
|
3902
|
+
if (r.flow !== null) {
|
|
3903
|
+
skipToBlockEnd(w);
|
|
3904
|
+
return;
|
|
3905
|
+
}
|
|
3906
|
+
if (w.i === before)
|
|
3907
|
+
w.i += 1;
|
|
3908
|
+
}
|
|
3909
|
+
else {
|
|
3910
|
+
skipCaseStatement(w);
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
}
|
|
3914
|
+
async function tryStmt(runner, w, scope) {
|
|
3915
|
+
const r = arm(runner);
|
|
3916
|
+
w.i += 1;
|
|
3917
|
+
r.tryDepth += 1;
|
|
3918
|
+
try {
|
|
3919
|
+
await runBranch(runner, w, scope, true, false);
|
|
3920
|
+
}
|
|
3921
|
+
finally {
|
|
3922
|
+
r.tryDepth -= 1; // the CATCH and FINALLY branches are outside the detection window
|
|
3923
|
+
}
|
|
3924
|
+
const threw = r.flow?.kind === "throw" ? r.flow : null;
|
|
3925
|
+
if (threw)
|
|
3926
|
+
r.flow = null;
|
|
3927
|
+
if (isIdentTok(w.cur() ?? undefined, "catch")) {
|
|
3928
|
+
w.i += 1;
|
|
3929
|
+
let errName = "";
|
|
3930
|
+
if (isOpTok(w.cur() ?? undefined, "(")) {
|
|
3931
|
+
const p = w.captureParen();
|
|
3932
|
+
if (p.length > 0 && p[0].kind === "ident")
|
|
3933
|
+
errName = p[0].v;
|
|
3934
|
+
}
|
|
3935
|
+
if (threw) {
|
|
3936
|
+
openBlock(scope);
|
|
3937
|
+
try {
|
|
3938
|
+
if (errName.length > 0) {
|
|
3939
|
+
newBinding(scope, errName);
|
|
3940
|
+
scope[errName] = threw.value ?? NSNull;
|
|
3941
|
+
declareLocal(scope, errName);
|
|
3942
|
+
}
|
|
3943
|
+
await runBranch(runner, w, scope, true, false);
|
|
3944
|
+
}
|
|
3945
|
+
finally {
|
|
3946
|
+
closeBlock(scope);
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
else {
|
|
3950
|
+
w.skipBranch();
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
else if (threw) {
|
|
3954
|
+
r.flow = threw; // no catch — rethrow upward
|
|
3955
|
+
}
|
|
3956
|
+
if (isIdentTok(w.cur() ?? undefined, "finally")) {
|
|
3957
|
+
w.i += 1;
|
|
3958
|
+
const saved = r.flow;
|
|
3959
|
+
r.flow = null;
|
|
3960
|
+
await runBranch(runner, w, scope, true, false);
|
|
3961
|
+
if (r.flow === null)
|
|
3962
|
+
r.flow = saved;
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
const BLOCK_CONTROL_RUN_IMPL = { switchStmt, tryStmt };
|
|
3966
|
+
/** fetch: / remove: / animate: effect verbs. */
|
|
3967
|
+
async function effectVerb(runner, verb, toks, scope) {
|
|
3968
|
+
const r = arm(runner);
|
|
3969
|
+
if (verb === "animate") {
|
|
3970
|
+
// animate: key = expr — assign (view transitions ride the CSS layer on web)
|
|
3971
|
+
if (toks.length >= 2 && toks[0].kind === "ident" && isOpTok(toks[1], "=")) {
|
|
3972
|
+
writePath(r.env, scope, toks[0].v, await r.evalMaybeAsync(toks.slice(2), scope));
|
|
3973
|
+
}
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
if (verb === "remove") {
|
|
3977
|
+
// remove: arr where <pred> | remove: arr = <value> [key=<field>]
|
|
3978
|
+
if (toks.length === 0 || toks[0].kind !== "ident")
|
|
3979
|
+
return;
|
|
3980
|
+
const path = toks[0].v;
|
|
3981
|
+
const base = readPath(r.env, scope, path);
|
|
3982
|
+
const rows = Array.isArray(base) ? base : [];
|
|
3983
|
+
if (isIdentTok(toks[1], "where")) {
|
|
3984
|
+
const pred = toks.slice(2);
|
|
3985
|
+
const kept = rows.filter((row) => {
|
|
3986
|
+
const rowScope = isDict(row) ? { ...scope, ...row } : scope;
|
|
3987
|
+
return !truthy(r.evalSync(pred, rowScope));
|
|
3988
|
+
});
|
|
3989
|
+
writePath(r.env, scope, path, kept);
|
|
3990
|
+
return;
|
|
3991
|
+
}
|
|
3992
|
+
if (isOpTok(toks[1], "=")) {
|
|
3993
|
+
// value match on a key field (default id): key=<field> suffix
|
|
3994
|
+
let valueToks = toks.slice(2);
|
|
3995
|
+
let field = "id";
|
|
3996
|
+
const kIdx = valueToks.findIndex((t, i) => t.kind === "ident" && t.v === "key" && isOpTok(valueToks[i + 1], "="));
|
|
3997
|
+
if (kIdx >= 0) {
|
|
3998
|
+
const f = valueToks[kIdx + 2];
|
|
3999
|
+
if (f && f.kind === "ident")
|
|
4000
|
+
field = f.v;
|
|
4001
|
+
valueToks = valueToks.slice(0, kIdx);
|
|
4002
|
+
}
|
|
4003
|
+
const value = r.evalSync(valueToks, scope);
|
|
4004
|
+
const kept = rows.filter((row) => !(isDict(row) && JSE.equals(row[field], value)));
|
|
4005
|
+
writePath(r.env, scope, path, kept);
|
|
4006
|
+
}
|
|
4007
|
+
return;
|
|
4008
|
+
}
|
|
4009
|
+
if (verb === "fetch") {
|
|
4010
|
+
// fetch: dest = METHOD url [body=expr] [headers=expr]
|
|
4011
|
+
//
|
|
4012
|
+
// THE DEST IS ONE IDENT TOKEN, AND IT MUST BE SPELLED. Two facts hold this line up and
|
|
4013
|
+
// neither is obvious from it. (1) The envelope is written through `writePath`, which
|
|
4014
|
+
// since the S3 cut refuses a bare non-`dsx.` path and says so by name, so `fetch: feed =
|
|
4015
|
+
// …` logs "bare write: spell dsx.variable.feed" three or four times and writes NOTHING:
|
|
4016
|
+
// the dest has to be `dsx.variable.<name>`. (2) That spelling survives the guard below
|
|
4017
|
+
// only because the tokenizer hands a dotted path back as a SINGLE ident token, so
|
|
4018
|
+
// `dsx.variable.feed` is `toks[0]` whole rather than `dsx` followed by two `.` runs. A
|
|
4019
|
+
// tokenizer change that split dotted paths would make every spelled dest fall out of
|
|
4020
|
+
// this guard silently and the verb would do nothing at all, which is the failure this
|
|
4021
|
+
// note exists to make visible. Pinned by Conformance/lint/cases/shared/fetch-verb.dsx.
|
|
4022
|
+
if (toks.length < 3 || toks[0].kind !== "ident" || !isOpTok(toks[1], "="))
|
|
4023
|
+
return;
|
|
4024
|
+
const dest = toks[0].v;
|
|
4025
|
+
let i = 2;
|
|
4026
|
+
let method = "GET";
|
|
4027
|
+
if (toks[i] && toks[i].kind === "ident" && /^[A-Z]+$/.test(toks[i].v)) {
|
|
4028
|
+
method = toks[i].v;
|
|
4029
|
+
i += 1;
|
|
4030
|
+
}
|
|
4031
|
+
// url = everything to `body=`/`headers=` (interpolated string or expression)
|
|
4032
|
+
const stop = (t, k) => t.kind === "ident" && (t.v === "body" || t.v === "headers") && isOpTok(toks[k + 1], "=");
|
|
4033
|
+
const urlToks = [];
|
|
4034
|
+
while (i < toks.length && !stop(toks[i], i)) {
|
|
4035
|
+
urlToks.push(toks[i]);
|
|
4036
|
+
i += 1;
|
|
4037
|
+
}
|
|
4038
|
+
let bodyExpr = [];
|
|
4039
|
+
let headersExpr = [];
|
|
4040
|
+
while (i < toks.length) {
|
|
4041
|
+
const t = toks[i];
|
|
4042
|
+
if (t.kind === "ident" && t.v === "body" && isOpTok(toks[i + 1], "=")) {
|
|
4043
|
+
i += 2;
|
|
4044
|
+
while (i < toks.length && !stop(toks[i], i)) {
|
|
4045
|
+
bodyExpr.push(toks[i]);
|
|
4046
|
+
i += 1;
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
else if (t.kind === "ident" && t.v === "headers" && isOpTok(toks[i + 1], "=")) {
|
|
4050
|
+
i += 2;
|
|
4051
|
+
while (i < toks.length && !stop(toks[i], i)) {
|
|
4052
|
+
headersExpr.push(toks[i]);
|
|
4053
|
+
i += 1;
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
else
|
|
4057
|
+
i += 1;
|
|
4058
|
+
}
|
|
4059
|
+
let url = string(r.evalSync(urlToks, scope));
|
|
4060
|
+
if (url.length === 0 && looksLikeBareUrl(urlToks))
|
|
4061
|
+
url = rebuildBareUrl(urlToks);
|
|
4062
|
+
writePath(r.env, scope, `${dest}.loading`, true);
|
|
4063
|
+
writePath(r.env, scope, `${dest}.error`, null);
|
|
4064
|
+
try {
|
|
4065
|
+
const res = await r.fetchFunnel(url, {
|
|
4066
|
+
method,
|
|
4067
|
+
body: bodyExpr.length > 0 ? r.evalSync(bodyExpr, scope) : undefined,
|
|
4068
|
+
headers: headersExpr.length > 0 ? r.evalSync(headersExpr, scope) : undefined,
|
|
4069
|
+
});
|
|
4070
|
+
r.env.store.batch(() => {
|
|
4071
|
+
writePath(r.env, scope, `${dest}.loading`, false);
|
|
4072
|
+
if (isDict(res) && truthy(res["ok"])) {
|
|
4073
|
+
writePath(r.env, scope, `${dest}.data`, res["data"] ?? null);
|
|
4074
|
+
}
|
|
4075
|
+
else {
|
|
4076
|
+
const status = number(isDict(res) ? res["status"] : 0) ?? 0;
|
|
4077
|
+
writePath(r.env, scope, `${dest}.error`, status > 0 ? `http ${status}` : "network");
|
|
4078
|
+
}
|
|
4079
|
+
});
|
|
4080
|
+
}
|
|
4081
|
+
catch {
|
|
4082
|
+
r.env.store.batch(() => {
|
|
4083
|
+
writePath(r.env, scope, `${dest}.loading`, false);
|
|
4084
|
+
writePath(r.env, scope, `${dest}.error`, "network");
|
|
4085
|
+
});
|
|
4086
|
+
}
|
|
4087
|
+
return;
|
|
4088
|
+
}
|
|
4089
|
+
if (globalThis.__DSX_OPTIONAL_DEV_LINES__ !== false)
|
|
4090
|
+
console.warn(`[dsx runner] verb ${verb}: not carried to web v1`);
|
|
4091
|
+
}
|
|
4092
|
+
const EFFECT_VERB_RUN_IMPL = { effectVerb };
|
|
4093
|
+
export { tokenize };
|
|
4094
|
+
//# sourceMappingURL=runner.js.map
|