mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-12-05 05:45:00 +00:00
In codemode scripts, `console.*` showed `NaN`, `Infinity`, and
`-Infinity` as `null`. A thrown non-Error value such as `throw NaN` was
also reported with the message `null`. Both go through `format()` in the
script prelude, which passes every value that is not a string or an
Error to `JSON.stringify`. `JSON.stringify` turns non-finite numbers
into `"null"`. `text()` already printed these values correctly, so the
two output paths disagreed and the model saw `avg null` where it should
have seen `avg NaN`.
`format()` now calls `String()` on numbers. Objects still print as JSON,
so `NaN` inside an object still prints as `null`, as `JSON.stringify`
and `text()` do.
**Testing**
- Added a regression test to `packages/codemode/test/sandbox.test.ts`.
It runs on the worker, inline, and remote backends and checks console
output, `text()`, and `throw NaN`. All three backend runs fail without
the fix and pass with it. The whole file passes (156 tests).
- `npm run check` passes.
- Script `console.log("avg", 0/0, 1/0, -1/0, -0); text(0/0);`: the
console line was `avg null null null 0` before the fix and is `avg NaN
Infinity -Infinity 0` after it. The `text()` item is `NaN` in both
cases.
- `throw NaN`: the error message was `null` before and is `NaN` after.
Fixes #11901
Requested by @badlogic
Co-authored-by: triagent <triagent@localhost>
|
||
|---|---|---|
| .. | ||
| runtime | ||
| cloudflare-modules.d.ts | ||
| cloudflare.ts | ||
| declarations.ts | ||
| identifier.ts | ||
| index.ts | ||
| portable.ts | ||
| source.ts | ||
| types.ts | ||
| wasm.ts | ||