Skip to content

perf(objects): add fastNullObject helper - #233

Merged
John-David Dalton (jdalton) merged 3 commits into
mainfrom
perf/fast-null-options
Sep 28, 2026
Merged

John-David Dalton (jdalton) merged 3 commits into
mainfrom
perf/fast-null-options

Conversation

@jdalton

@jdalton John-David Dalton (jdalton) commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Adds fastNullObject in src/objects/options.mts: shallow-copies own enumerable properties and sets the copy's prototype to null using the captured ObjectSetPrototypeOf primordial. The result keeps V8 fast properties, unlike a { __proto__: null, ...o } literal, which lands in dictionary mode. The input is never mutated.

getGlobMatcher now uses it for its options snapshot; a suppression on the call site records that the pollution guard lives inside the helper.

Verified with a V8 probe on Node 26.10: the null-proto literal reports dictionary elements, the helper result reports fast properties. Focused coverage is 100% statements/functions/lines (3 tests).


Note

Low Risk
Small additive utility with one internal consumer and focused tests; behavior change is limited to how options objects are copied for glob matching.

Overview
Introduces fastNullObject as a public @socketsecurity/lib/objects/options export: it shallow-copies optional input and sets the copy’s prototype to null via the captured ObjectSetPrototypeOf primordial, aiming to keep V8 fast properties instead of the dictionary-mode object that { __proto__: null, ...options } tends to create.

getGlobMatcher now normalizes its options argument with fastNullObject instead of an inline null-prototype spread; an oxlint suppression documents that the pollution guard lives in the helper.

Unit tests cover inherited keys, an own __proto__ property treated as data (not prototype mutation), and omitted options.

Reviewed by Cursor Bugbot for commit e821022. Configure here.

@jdalton
John-David Dalton (jdalton) merged commit 1fd25bc into main Sep 28, 2026
9 of 11 checks passed
@jdalton
John-David Dalton (jdalton) deleted the perf/fast-null-options branch September 28, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant