Skip to content

fix(process): validate CPU snapshots and listener limits#3496

Merged
proggeramlug merged 2 commits into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-process-validation-readback
May 31, 2026
Merged

fix(process): validate CPU snapshots and listener limits#3496
proggeramlug merged 2 commits into
PerryTS:mainfrom
andrewtdiz:codex/node-compat-process-validation-readback

Conversation

@andrewtdiz
Copy link
Copy Markdown
Contributor

Summary

  • validate process.cpuUsage(previousValue) and process.threadCpuUsage(previousValue) snapshot inputs with Node-shaped error behavior and delta results
  • preserve threadCpuUsage(previousValue) through HIR/codegen and dynamic process namespace dispatch
  • validate process.exit(code) for accepted integer numbers/string-integers and invalid numeric values
  • preserve fractional and Infinity process.setMaxListeners() readback, validate invalid values, and return the process namespace object
  • update process parity docs for the covered CPU usage APIs

Batched Issues

Closes #3040
Closes #2927
Closes #3041
Closes #3049

These share the process runtime validation/readback path and one deterministic parity surface.

Tests Added

  • test-parity/node-suite/process/cpu/usage-prev-validation.ts
  • test-parity/node-suite/process/events/max-listeners-validation.ts
  • test-parity/node-suite/process/methods/exit-validation.ts

Verification

  • pre-fix focused validation suite failed on the three new fixtures as expected: test-parity/reports/parity_report_20260531_002702.json
  • post-fix focused validation suite passed 4/4: test-parity/reports/parity_report_20260531_003800.json
  • post-fix/rebase full process parity suite passed 81/81: test-parity/reports/parity_report_20260531_004456.json
  • TMPDIR="$PWD/target/tmp" CARGO_BUILD_JOBS=1 RUSTC_WRAPPER= cargo check -p perry-runtime -p perry-codegen -p perry-api-manifest -p perry-codegen-js -p perry-codegen-wasm passed with existing warnings
  • cargo fmt --all -- --check
  • git diff --check HEAD
  • ./scripts/check_file_size.sh

Known Limitations

  • threadCpuUsage still follows Perry's existing host-clock approximation for the user/system split; this PR fixes validation and previous-value delta semantics.

Non-goals

  • process.execve, process IPC channel behavior, worker CPU APIs, and broader EventEmitter warning behavior.

# Conflicts:
#	crates/perry-runtime/src/os.rs
#	crates/perry-runtime/src/process.rs
#	docs/runtime-parity-gaps.md
@proggeramlug proggeramlug merged commit 4603f15 into PerryTS:main May 31, 2026
10 of 11 checks passed
proggeramlug pushed a commit that referenced this pull request May 31, 2026
`crates/perry-runtime/src/process.rs` reached 2047 LOC on main after the
node:process argument-validation batch (#3493/#3516/#3518/#3496) landed
without a split, tripping the whole-tree file-size gate and turning every
open PR's `lint` check red. Add it to the allowlist with a rationale,
mirroring the existing entries; the per-concern split is tracked under
#1435.
proggeramlug added a commit that referenced this pull request May 31, 2026
…3149) (#3530)

* fix(es5): Object(value) plain-call coercion returns a fresh object (#3149)

Bug 1 of #3149. `Object()` / `Object(undefined)` / `Object(null)` called
as a plain function (not `new`) returned `undefined` — the bare-call path
fell through to the generic dispatcher. Per ECMAScript §20.1.1.1 these
yield a fresh ordinary `{}`; an existing object/array/function passes
through unchanged; a primitive coerces to an object (typeof "object").

Adds an `Expr::ObjectCoerce(value)` HIR variant (mirroring `StringCoerce`)
lowered from the shadow-safe bare `Object(...)` call, a `js_object_coerce`
runtime helper (nullish/primitive -> fresh `{}`, pointer passes through),
and codegen emission + the operand-recursing collector/walker arms. The
`new Object(null)` path already worked via `js_new_function_construct`.

Gap test `test_gap_3149_object_coerce.ts` is byte-identical to
`node --experimental-strip-types`.

Bug 2 (function-declaration reassignment) is intentionally deferred — see
the follow-up issue; it needs mutable-binding-slot routing across the
FuncRef read / call / `new` lowering sites and human review before landing.

* chore(lint): allowlist process.rs in the file-size gate

`crates/perry-runtime/src/process.rs` reached 2047 LOC on main after the
node:process argument-validation batch (#3493/#3516/#3518/#3496) landed
without a split, tripping the whole-tree file-size gate and turning every
open PR's `lint` check red. Add it to the allowlist with a rationale,
mirroring the existing entries; the per-concern split is tracked under
#1435.

* docs: regenerate API reference + .d.ts to match the manifest

The committed artifacts were one batch stale relative to
crates/perry-api-manifest/src/entries.rs: #3528 (util.debuglog factory)
dropped the `util.debug` / `sys.debug` alias from the manifest but the
merge didn't regenerate docs, leaving main red on the api-docs-drift
gate (committed docs claim 1996 entries; manifest has 1994). Re-run of
`./scripts/regen_api_docs.sh` — no manifest change in this PR, purely a
catch-up regeneration.

---------

Co-authored-by: Ralph Küpper <ralph@skelpo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants