fix(node:perf_hooks): measure/observe validation + eventLoopUtilization diffs#3517
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3088
Closes #3008
Closes #3010
Closes #3011
Implementation
All changes are in the
node:perf_hooksruntime (crates/perry-runtime/src/perf_hooks.rs) plus the twoeventLoopUtilizationcall sites. No new HIR variants.#3088 —
performance.measure(name)string validation.measurepreviously string-coerced the name likemark. It now requires a real string (heap or SSO); every non-string (undefined,null, number, boolean, object, array, symbol) throwsTypeErrorwith Node'sERR_INVALID_ARG_TYPEmessage, including theReceived ...suffix (undefined,null,type number (0),type boolean (true),an instance of Object,an instance of Array,type symbol (Symbol(s))).mark()name coercion is unchanged (mark(1).name === "1").#3008 — User Timing option/timestamp validation.
mark({ startTime }): negative numeric value throwsERR_PERFORMANCE_INVALID_TIMESTAMP(-1 is not a valid timestamp); non-numeric throws theERR_INVALID_ARG_TYPEstartTime message with the received value.measure(name, options):{ start, end, duration }all present throwsERR_PERFORMANCE_MEASURE_INVALID_OPTIONS; negative numericdurationthrows the invalid-timestamp error; a stringstart/endthat doesn't name an existing mark now throws (SyntaxError: The "X" performance mark has not been set) instead of silently resolving to 0. Positional missing-mark resolution switched fromTypeErrortoSyntaxErrorto match Node'serr.name. Valid{start,end}/{start,duration}/{duration,end}still succeed.#3010 —
PerformanceObserver.observe()option validation. Non-object/non-undefined options throwERR_INVALID_ARG_TYPE; neitherentryTypesnortypespecified throwsERR_MISSING_ARGS; both specified throwsERR_INVALID_ARG_VALUE;entryTypespresent but not an array throws themust be string[]message. Lenient unknown-but-well-typed names (entryTypes: [],["bogus"],type: "bogus") still succeed and observe nothing.#3011 — two-argument
eventLoopUtilizationdiffs.js_perf_event_loop_utilizationnow takes(util1, util2): zero-arg = cumulative, one-arg = current − util1, two-arg = util1 − util2. Updated the dynamic dispatch (native_module_dispatch.rs), static codegen (lower_call/native/perf_hooks.rs), and the FFI decl (runtime_decls/stdlib_ffi.rs) to pass/accept the second argument.Validation
test-files/test_gap_perfhooks_3088_3008_3010_3011.tsis byte-identical tonode --experimental-strip-typesunder the DEFAULT auto-optimize compile. The eventLoopUtilization assertions check object shape/keys (active,idle,utilization), value ranges, and types — never raw timestamps. Validation cases printerr.name + ": " + err.message.Guards:
./scripts/check_file_size.sh(OK),cargo fmt --all -- --check(clean),cargo test --release -p perry-runtime perf(2 pass),cargo test --release -p perry-hir(all pass). No new#[no_mangle]functions were added, so no keepalive anchors were needed.