Skip to content

Fix RemoteNodeList inherited array methods throwing this.view.getUint32 is not a function#4346

Open
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-remote-node-list-inherited-array-methods
Open

Fix RemoteNodeList inherited array methods throwing this.view.getUint32 is not a function#4346
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-remote-node-list-inherited-array-methods

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

NodeArray<T> (exposed via the native API) extends ReadonlyArray<T>, but calling inherited array methods on a RemoteNodeList (e.g. sourceFile.statements.filter(...), .map(...), .slice(...)) threw TypeError: this.view.getUint32 is not a function.

Root cause

RemoteNodeList extends Array<RemoteNode>. Inherited methods like filter/map/slice use ArraySpeciesCreate, which constructs the result via new this.constructor[Symbol.species](length). The default species is RemoteNodeList, so this invoked new RemoteNodeList(length) — passing a number where a DataView is expected. The constructor then runs this.length = this.data, dereferencing this.view.getUint32(...) on a number.

Changes

  • _scripts/generate-encoder.ts: Emit a static get [Symbol.species]() returning Array on RemoteNodeList, so inherited array methods produce plain arrays instead of reconstructing a RemoteNodeList.
  • node.generated.ts: Regenerated output (verified identical to the generator emission).
  • test/sync/ast.test.ts: Regression test covering filter/map/slice.
export class RemoteNodeList extends Array<RemoteNode> implements NodeArray<RemoteNode> {
    static get [Symbol.species](): ArrayConstructor {
        return Array;
    }
    // ...
}

The new test fails with the reported error prior to the change and passes after.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix RemoteNodeList inherited array methods throwing an error Fix RemoteNodeList inherited array methods throwing this.view.getUint32 is not a function Jun 17, 2026
Copilot AI requested a review from andrewbranch June 17, 2026 00:52
@andrewbranch andrewbranch marked this pull request as ready for review June 17, 2026 00:59
Copilot AI review requested due to automatic review settings June 17, 2026 00:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime error in the native preview API where RemoteNodeList (which subclasses Array) would throw when calling inherited array methods (e.g. filter/map/slice) due to ArraySpeciesCreate constructing new RemoteNodeList(length).

Changes:

  • Update the encoder generator to emit static get [Symbol.species]() on RemoteNodeList, forcing derived array methods to return plain Array instances.
  • Regenerate node.generated.ts to include the new Symbol.species override.
  • Add a sync regression test covering filter/map/slice on RemoteNodeList.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
_scripts/generate-encoder.ts Emits a RemoteNodeList Symbol.species override so inherited array methods don’t invoke the custom constructor.
_packages/native-preview/src/api/node/node.generated.ts Generated output reflecting the new Symbol.species override in RemoteNodeList.
_packages/native-preview/test/sync/ast.test.ts Adds a regression test ensuring array methods no longer throw on RemoteNodeList.

Comment thread _packages/native-preview/test/sync/ast.test.ts
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

3 participants