perf(objects): add fastNullObject helper - #233
Merged
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.
Adds
fastNullObjectinsrc/objects/options.mts: shallow-copies own enumerable properties and sets the copy's prototype to null using the capturedObjectSetPrototypeOfprimordial. The result keeps V8 fast properties, unlike a{ __proto__: null, ...o }literal, which lands in dictionary mode. The input is never mutated.getGlobMatchernow 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
fastNullObjectas a public@socketsecurity/lib/objects/optionsexport: it shallow-copies optional input and sets the copy’s prototype tonullvia the capturedObjectSetPrototypeOfprimordial, aiming to keep V8 fast properties instead of the dictionary-mode object that{ __proto__: null, ...options }tends to create.getGlobMatchernow normalizes its options argument withfastNullObjectinstead 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.