Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BridgeJS: Support optional @JSClass as exported function parameters#754

Merged
krodak merged 2 commits into
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:kr/fix-optional-jsclass-paramPassiveLogic/JavaScriptKit:kr/fix-optional-jsclass-paramCopy head branch name to clipboard
Jun 9, 2026
Merged

BridgeJS: Support optional @JSClass as exported function parameters#754
krodak merged 2 commits into
swiftwasm:mainswiftwasm/JavaScriptKit:mainfrom
PassiveLogic:kr/fix-optional-jsclass-paramPassiveLogic/JavaScriptKit:kr/fix-optional-jsclass-paramCopy head branch name to clipboard

Conversation

@krodak

@krodak krodak commented Jun 3, 2026

Copy link
Copy Markdown
Member

Overview

Fixes #751. A @JS exported function taking (or returning) an optional @JSClass such as JSAbortSignal? failed to compile with no exact matches in call to static method 'bridgeJSLiftParameter' for Optional<JSAbortSignal>.

Optional jsObject (incl. @JSClass) parameters now use the direct (isSome, objId) ABI in both directions, matching plain Optional<JSObject> and exported @JS class parameters; only return values use the stack ABI.

1. Export parameters: use the direct ABI. ExportSwift no longer special-cases .nullable(.jsObject), so exported parameters lift via Optional<T>.bridgeJSLiftParameter(isSome, value). Adds the missing Optional<_JSBridgedClass>.bridgeJSLiftParameter(isSome, objId) and bridgeJSLowerReturn() so optional @JSClass values round-trip as both parameters and return values.

2. Import parameters: align to the direct ABI. loweringParameterInfo already lowered optional jsObject import parameters as direct (isSome, value), but the JS lift still popped the object id off the stack that Swift never pushed, throwing ReferenceError: Attempted to use invalid reference undefined for a non-nil value. The JS lift now reads the object id directly, matching the extern.

A new optionalParameterUsesStackABI keeps the stack ABI only for the return direction of optional jsObject.

Tests

  • Export direction: end-to-end runtime test passing an optional imported @JSClass directly as an exported function parameter and return value (present and null cases), plus snapshot coverage for optional JSObject? and @JSClass?.
  • Import direction: end-to-end runtime test passing an optional JSObject? into an imported JS function (present and null cases), plus updated snapshot coverage for the optional @JSClass? import parameter.
  • Regenerated in-package snapshots and the AoT-committed bindings. Snapshot suites, the BridgeJS TypeScript declaration check, and the full wasm test suite pass.

@krodak krodak self-assigned this Jun 3, 2026
@krodak krodak requested a review from kateinoigakukun June 3, 2026 11:22
@kateinoigakukun

Copy link
Copy Markdown
Member

Sorry, I'm still reviewing this, so please give me some more time 🙇

Comment thread Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift Outdated
@krodak krodak force-pushed the kr/fix-optional-jsclass-param branch from 5dbbd02 to c93a031 Compare June 9, 2026 16:03
@krodak krodak merged commit 9706c4c into swiftwasm:main Jun 9, 2026
13 checks passed
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.

BridgeJS: Optional @JSClass parameter fails lift/lower for generated bindings

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.