◐ Shell
reader mode source ↗
Skip to content

BridgeJS: Enforce throws(JSException) on @JS protocol methods#563

Merged
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:krodak/protocol-throws
Feb 3, 2026
Merged

BridgeJS: Enforce throws(JSException) on @JS protocol methods#563
krodak merged 1 commit into
swiftwasm:mainfrom
PassiveLogic:krodak/protocol-throws

Conversation

@krodak

@krodak krodak commented Feb 3, 2026

Copy link
Copy Markdown
Member

Overview

  • Require throws(JSException) on @JS protocol methods, matching the import side (@JSFunction) behavior
  • Fix generated protocol wrapper code to propagate throws effect
  • Updated tests and documentation

Test updates

  • Protocol.swift test input: Added throws(JSException) to all protocol methods
  • ExportAPITests.swift: Updated DataProcessor protocol methods with throws
  • Regenerated snapshots

Documentation

  • Updated Exporting-Swift-Protocols.md with throws requirement and examples

Motivation

This partially addresses the inconsistency where @JSFunction (import side) requires throws(JSException) but @JS protocol methods (export side) didn't.

Properties will be covered in separate PR 🙏🏻

@kateinoigakukun kateinoigakukun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hide comment

Thanks!

@kateinoigakukun

kateinoigakukun commented Feb 3, 2026

Copy link
Copy Markdown
Member

I think we need to enable the exception check emitted by CallJSEmission (or it needs to be done after the property interface adjustment?)

@krodak

krodak commented Feb 3, 2026

Copy link
Copy Markdown
Member Author

@kateinoigakukun my bad, now added exception checking for protocol wrapper methods with new BridgeContext.exportSwiftProtocol case.

The issue was that protocol wrappers call into JavaScript (like .importTS), so they indeed need exception checking that I missed. But they also need to support Swift heap objects as parameters/returns (like .exportSwift), hence new type 🙏🏻
For now this only applies to methods. Property accessors will be updated in a follow-up PR.

@krodak krodak force-pushed the krodak/protocol-throws branch from 1c4d924 to 905f4ea Compare February 3, 2026 11:24
BridgeJS: Enforce throws(JSException) on @js protocol methods
@krodak krodak force-pushed the krodak/protocol-throws branch from 905f4ea to d4da0e3 Compare February 3, 2026 11:34
Hide details View details @krodak krodak merged commit a070ba0 into swiftwasm:main Feb 3, 2026
11 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.

2 participants