Merge master into production#45
Merged
Merged
Conversation
Two small robustness fixes: 1. `Bitmap.fromBuffer` previously stored the result of `buf.slice(...)`, which in Node returns a Buffer that shares memory with the source. If the source buffer was mutated after parsing (e.g. a radio driver reusing its receive buffer across frames), the bits read from an already-parsed Bitmap would change. Wrap the slice in `Buffer.from(...)` so the Bitmap owns its bytes. 2. `Struct`'s constructor used `!defs[key]` to validate field names. That check walks the prototype chain, so `defs.constructor` resolves to `Object` (truthy) and `constructor` is accepted as a valid field name, silently overwriting the instance's `.constructor` reference. Use `Object.prototype.hasOwnProperty.call(defs, key)` instead so only declared own-property fields are accepted. Other prototype-chain keys (`toString`, `valueOf`, ...) are also now correctly rejected. Tests added for both. Neither change affects behavior for any correct caller.
Address Copilot review feedback on #44: the throw path previously used `this.constructor.name` for the error prefix. If a struct legitimately declares a `constructor` field and the caller sets it before an unexpected key is encountered, `this.constructor` is already the user-supplied value and `.name` would crash or be undefined. Switch to the closed-over `name` parameter, which is lexically bound and cannot be shadowed by instance assignments. Adds a regression test for the edge case.
…sages Followup to the previous commit. Closed-over `name` was correct on the shadow-resistance axis but lost the subclass-aware error message that `this.constructor.name` originally provided: when a Struct-generated class is subclassed, the error should identify the actual instantiated subclass, not the underlying Struct name. `new.target` is a syntactic binding to the constructor actually invoked via `new`. It reflects the subclass identity AND cannot be shadowed by a `constructor` field the caller may have set earlier in the same loop. Strictly better than both `this.constructor.name` and closed-over `name`. Adds a subclassing regression test so this property is locked in.
fix(parser): defensive Bitmap copy and Struct prototype-chain guard
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.
No description provided.