Skip to content

Merge master into production#45

Merged
RobinBol merged 5 commits into
productionfrom
master
May 20, 2026
Merged

Merge master into production#45
RobinBol merged 5 commits into
productionfrom
master

Conversation

@RobinBol
Copy link
Copy Markdown
Contributor

No description provided.

RobinBol and others added 5 commits May 20, 2026 15:52
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
@RobinBol RobinBol merged commit d2d000c into production May 20, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant