Commit 645767c
authored
[kyo-config] FlagPlatform: browser-safe process probe (#1832)
## Problem
`Flag` crashes on Scala.js in browsers. `FlagPlatform.env`/`envNames`
bind the `process` global to a `val` before their `typeof` guard runs:
```scala
val proc = js.Dynamic.global.process
if (js.typeOf(proc) == "undefined" || ...) ...
```
Scala.js compiles the first line to a bare `process` identifier read. In
Node that yields the process object, but in a browser (no bundler shim)
it throws `ReferenceError: process is not defined` before the guard on
the next line ever executes. Any browser app that resolves a flag during
startup dies with that error.
This is the same defect #1823 fixed in `kyo-core`'s
`SystemPlatformSpecific`. That PR carried both modules; the merge took
the `kyo-core` half, so `kyo-config` still has the crashing pattern.
This is the remaining half.
## Solution
Keep the `typeof` guard inline on the global selection, which Scala.js
compiles to a plain `typeof process` expression (safe on undeclared
identifiers by JS semantics), and only bind the `val` after the guard
passes — the same idiom `osName()`/`osArch()` and the merged
`System.env` already use. Extracted as a `hasProcess` probe since both
readers need it.
## Tests
`FlagPlatformTest` gains the missing-global topology, reproduced by
deleting `process` from the global object for the duration of the read:
`process` then becomes an *undeclared* identifier, which is exactly the
state that makes a bare read throw while `typeof process` still answers
`"undefined"`. Restoring it in a `finally` keeps the test runner (which
talks over `process.stdout`) alive even when an assertion fails.
Both new cases fail with `ReferenceError: process is not defined`
against the current code and pass with the fix. `envNames` had no
coverage at all before, so its Node-path case comes along.
`SystemPlatformSpecificJsWasmTest` is new and adds the same coverage for
the guard #1823 already merged — `env`, `osName` and `osArch` all read
`process` and none of them had a test for the browser topology.
## Notes
No behavior change on Node: the same values are returned for present,
absent and null variables.
The two modules are deliberately separate concerns here: `kyo-config`
carries the fix, `kyo-core` only gains test coverage for code already on
`main`.1 parent 92448b6 commit 645767c
3 files changed
Lines changed: 97 additions & 8 deletions
File tree
- kyo-config/js-wasm/src
- main/scala/kyo
- test/scala/kyo
- kyo-core/js-wasm/src/test/scala/kyo/internal
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
17 | 24 | | |
18 | 25 | | |
19 | | - | |
20 | | - | |
| 26 | + | |
21 | 27 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
25 | 35 | | |
26 | 36 | | |
27 | 37 | | |
28 | 38 | | |
29 | | - | |
30 | | - | |
31 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
32 | 45 | | |
33 | 46 | | |
34 | 47 | | |
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
14 | 27 | | |
15 | 28 | | |
16 | 29 | | |
| |||
23 | 36 | | |
24 | 37 | | |
25 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
26 | 54 | | |
27 | 55 | | |
28 | 56 | | |
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments