GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — BridgeJS: Unify @JS struct parameter lowering onto the stack ABI by kateinoigakukun · Pull Request #798 · swiftwasm/JavaScriptKit

Conversation

@kateinoigakukun

@kateinoigakukun kateinoigakukun commented Aug 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary

@JS struct bridgeJSLowerParameter() used toJSObject() (object-id ABI). Swift→JS callbacks and the rest of the stack ABI expect a stack push + JS structHelpers.*.lift(). The object-id path pushed then lifted into a JS object, discarded the id, and left the stacks empty for the callback glue — so JS read garbage.

This matches arrays/dictionaries: lower = stack push. ImportTS non-optional structs use the same stack ABI (optional structs already did).

Problematic case

@JS struct Vector2D {
    var dx: Double
    var dy: Double
}

@JS class TextProcessor {
    @JS func observeVector(_ callback: (Vector2D) -> Void) {
        callback(Vector2D(dx: 1.5, dy: 2.5))
    }
}
processor.observeVector((vector) => {
  // Before: { dx: undefined, dy: undefined, ... }
  // After:  { dx: 1.5, dy: 2.5, ... }
});

Same failure mode for any Swift→JS typed closure that takes a non-optional @JS struct (e.g. observation payloads). Bool fields were especially misleading: empty-stack i32 pops yielded undefined, and undefined !== 0 became true.

Fix

  • _BridgedSwiftStruct.bridgeJSLowerParameter() → bridgeJSStackPush()
  • ImportTS non-optional struct param/return ABI → stack (same as ExportSwift / optionals)
  • Runtime regression: observeVector / mapVector in ClosureSupportTests

Test plan

  • BridgeJS plugin tests / snapshots
  • ClosureSupportTests.testRunJsClosureSupportTests (struct callback params)
  • SwiftStructTests.testSwiftStructInImportedSignature (ImportTS stack unify)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kateinoigakukun
BridgeJS: Unify @js struct parameter lowering onto the stack ABI
0e11da5
bridgeJSLowerParameter for structs used toJSObject(), so Swift→JS
callbacks discarded the stack and JS lift() read garbage. Match arrays:
stack-push on lower, and use the same ABI for ImportTS non-optional structs.
@kateinoigakukun
kateinoigakukun marked this pull request as ready for review August 10, 2026 00:58
@kateinoigakukun
kateinoigakukun requested a review from krodak August 10, 2026 00:58
krodak
krodak approved these changes Aug 10, 2026
View reviewed changes
@krodak
krodak merged commit 83eae16 into main Aug 10, 2026
31 of 32 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@krodak
krodak deleted the yt/fix-struct-closure-param branch August 10, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@krodak krodak krodak approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kateinoigakukun @krodak
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.