Skip to content

fix(bindgen): fix async future JS codegen producing invalid output#1367

Open
wondenge wants to merge 1 commit intobytecodealliance:mainfrom
wondenge:fix(bindgen)-async-future-codegen-bugs
Open

fix(bindgen): fix async future JS codegen producing invalid output#1367
wondenge wants to merge 1 commit intobytecodealliance:mainfrom
wondenge:fix(bindgen)-async-future-codegen-bugs

Conversation

@wondenge
Copy link
Copy Markdown

@wondenge wondenge commented Apr 7, 2026

The async future intrinsic templates produced invalid JavaScript that failed to parse when transpiling any component with future types. These bugs made P3 async futures completely unusable.

  • Removed a stray closing parenthesis in the elementTypeRep range check
  • Changed self to this in four places inside drop() - in JavaScript class methods, self refers to globalThis, not the instance
  • Used the current variant name instead of always emitting futureWrite, which caused a duplicate declaration when rendering futureRead
  • Same for futureCancelRead which was emitted for both cancel variants
  • Renamed the second futureIdx parameter to futureEndIdx — the duplicate left futureEndIdx undefined at runtime
  • Also fixed the matching duplicate in the debug log object
  • Added the missing throw keyword before new Error in the instanceof guard, which was constructing an error and silently discarding it
  • Removed a broken line that called .remaining(bufferID) without the BUFFER_MGR receiver and had no closing brace
  • Added componentIdx to the cancel function parameter list and debug log, since the function body referenced it but never received it
  • Added the missing lookup to fetch the future from the global map before comparing element type reps
  • Replaced streamEndIdx with futureEndIdx, a copy-paste leftover from the stream equivalent
  • Added the missing closing parenthesis in the instanceof check

The async future intrinsic templates produced invalid JavaScript
that failed to parse when transpiling any component with future<T>
types. These bugs made P3 async futures completely unusable.

- Removed a stray closing parenthesis in the elementTypeRep range check
- Changed self to this in four places inside drop() - in JavaScript
  class methods, self refers to globalThis, not the instance
- Used the current variant name instead of always emitting futureWrite,
  which caused a duplicate declaration when rendering futureRead
- Same for futureCancelRead which was emitted for both cancel variants
- Renamed the second futureIdx parameter to futureEndIdx — the
  duplicate left futureEndIdx undefined at runtime
- Also fixed the matching duplicate in the debug log object
- Added the missing throw keyword before new Error in the instanceof
  guard, which was constructing an error and silently discarding it
- Removed a broken line that called .remaining(bufferID) without the
  BUFFER_MGR receiver and had no closing brace
- Added componentIdx to the cancel function parameter list and debug
  log, since the function body referenced it but never received it
- Added the missing lookup to fetch the future from the global map
  before comparing element type reps
- Replaced streamEndIdx with futureEndIdx, a copy-paste leftover from
  the stream equivalent
- Added the missing closing parenthesis in the instanceof check
@wondenge wondenge marked this pull request as ready for review April 7, 2026 18:08
@wondenge wondenge requested a review from vados-cosmonic as a code owner April 7, 2026 18:08
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