Degrade gracefully when the JS AST source is unavailable #1
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "Sophie/phosphorus.osl:fix/jsfunc-null-js-source"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
jsFuncdeclared its parameter asstring js, so it hard-failed themoment
import("./src/js/ast.js")returned anything else.In a built bundle that is always. fpp only emits
importswitch casesfor
.osland.rwlfiles, soimport("./src/js/ast.js")falls throughthe switch and returns
null. The typed parameter then rejects it andSetup dies before the browser draws anything:
The JS AST generator is already optional --
jsVersion = canUseJs ? js.ast nulland every caller guards on
rtr.ast.jsVersion == nullbefore falling backto the OSL tokeniser. jsFunc just wasn't allowed to report "unavailable".
Accept an untyped source, and return null when it is missing/empty or when
eval()yields nothing (e.g. the app has no javascript permission).js.astis then null,
jsVersionis null, and the OSL AST generator takes over.Verified in originOS: the committed build now boots to the chromeLike
layout with a working tab bar and url bar.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Two follow-ups this PR deliberately does not cover:
fpp should inline non-
.oslimports. The real reasonimport("./src/js/ast.js")returns null is that fpp only emits switch cases for.osl/.rwl. Until that is fixed the built bundles silently lose the JS AST fast path and fall back to the OSL tokeniser. This PR only makes that fallback survivable instead of fatal.A separate originOS/OSL runtime bug also crashed phosphorus, after this one.
Promise.new(...)spawns a worker on its own Scratch target but hands it the sameosl_clone[windowId]scope object as the main thread, andself(__self__) lives on that shared object. So the worker runningshared.config.net.refresh()overwroteselfwhile the RWL parser was mid-tokenise(), andself.tokensread back as null:That is fixed on the originOS side by giving each target its own
selfslot; no phosphorus change is needed for it.`jsFunc` declared its parameter as `string js`, so it hard-failed the moment `import("./src/js/ast.js")` returned anything else. In a built bundle that is always. fpp only emits `import` switch cases for `.osl` and `.rwl` files, so `import("./src/js/ast.js")` falls through the switch and returns `null`. The typed parameter then rejects it and Setup dies before the browser draws anything: type: Initial value for "js" must be of type string in: phosphorus.osl -> Setup -> jsFunc() The JS AST generator is already optional -- `jsVersion = canUseJs ? js.ast null` and every caller guards on `rtr.ast.jsVersion == null` before falling back to the OSL tokeniser. jsFunc just wasn't allowed to report "unavailable". Accept an untyped source, and return null when it is missing/empty or when `eval()` yields nothing (e.g. the app has no javascript permission). `js.ast` is then null, `jsVersion` is null, and the OSL AST generator takes over. Verified in originOS: the committed build now boots to the chromeLike layout with a working tab bar and url bar. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>seems fine, will have to check on 619 tho