Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork57
BridgeJS: @JS Protocol with methods support#456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
kateinoigakukun merged 1 commit intoswiftwasm:mainfromPassiveLogic:feat/protocol-support-methodsOct 22, 2025
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
5 changes: 4 additions & 1 deletionBenchmarks/Sources/Generated/JavaScript/BridgeJS.ExportSwift.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -720,5 +720,8 @@ | ||
| } | ||
| } | ||
| ], | ||
| "moduleName" : "Benchmarks", | ||
| "protocols" : [ | ||
| ] | ||
| } | ||
5 changes: 4 additions & 1 deletionExamples/PlayBridgeJS/Sources/PlayBridgeJS/Generated/JavaScript/BridgeJS.ExportSwift.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -138,5 +138,8 @@ | ||
| "functions" : [ | ||
| ], | ||
| "moduleName" : "PlayBridgeJS", | ||
| "protocols" : [ | ||
| ] | ||
| } | ||
422 changes: 343 additions & 79 deletionsPlugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Large diffs are not rendered by default.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
4 changes: 4 additions & 0 deletionsPlugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
80 changes: 75 additions & 5 deletionsPlugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletionsPlugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
26 changes: 25 additions & 1 deletionPlugins/BridgeJS/Sources/BridgeJSSkeleton/BridgeJSSkeleton.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletionsPlugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/Protocol.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import JavaScriptKit | ||
| @JS protocol MyViewControllerDelegate { | ||
| func onSomethingHappened() | ||
| func onValueChanged(_ value: String) | ||
| func onCountUpdated(count: Int) -> Bool | ||
| func onLabelUpdated(_ prefix: String, _ suffix: String) | ||
| func isCountEven() -> Bool | ||
| } | ||
| @JS class MyViewController { | ||
| @JS | ||
| var delegate: MyViewControllerDelegate | ||
| @JS | ||
| var secondDelegate: MyViewControllerDelegate? | ||
| @JS init(delegate: MyViewControllerDelegate) { | ||
| self.delegate = delegate | ||
| } | ||
| @JS func triggerEvent() { | ||
| delegate.onSomethingHappened() | ||
| } | ||
| @JS func updateValue(_ value: String) { | ||
| delegate.onValueChanged(value) | ||
| } | ||
| @JS func updateCount(_ count: Int) -> Bool { | ||
| return delegate.onCountUpdated(count: count) | ||
| } | ||
| @JS func updateLabel(_ prefix: String, _ suffix: String) { | ||
| delegate.onLabelUpdated(prefix, suffix) | ||
| } | ||
| @JS func checkEvenCount() -> Bool { | ||
| return delegate.isCountEven() | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions...ins/BridgeJS/Tests/BridgeJSToolTests/__Snapshots__/BridgeJSLinkTests/Protocol.Export.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // NOTICE: This is auto-generated code by BridgeJS from JavaScriptKit, | ||
| // DO NOT EDIT. | ||
| // | ||
| // To update this file, just rebuild your project or run | ||
| // `swift package bridge-js`. | ||
| export interface MyViewControllerDelegate { | ||
| onSomethingHappened(): void; | ||
| onValueChanged(value: string): void; | ||
| onCountUpdated(count: number): boolean; | ||
| onLabelUpdated(prefix: string, suffix: string): void; | ||
| isCountEven(): boolean; | ||
| } | ||
| /// Represents a Swift heap object like a class instance or an actor instance. | ||
| export interface SwiftHeapObject { | ||
| /// Release the heap object. | ||
| /// | ||
| /// Note: Calling this method will release the heap object and it will no longer be accessible. | ||
| release(): void; | ||
| } | ||
| export interface MyViewController extends SwiftHeapObject { | ||
| triggerEvent(): void; | ||
| updateValue(value: string): void; | ||
| updateCount(count: number): boolean; | ||
| updateLabel(prefix: string, suffix: string): void; | ||
| checkEvenCount(): boolean; | ||
| delegate: MyViewControllerDelegate; | ||
| secondDelegate: MyViewControllerDelegate | null; | ||
| } | ||
| export type Exports = { | ||
| MyViewController: { | ||
| new(delegate: MyViewControllerDelegate): MyViewController; | ||
| } | ||
| } | ||
| export type Imports = { | ||
| } | ||
| export function createInstantiator(options: { | ||
| imports: Imports; | ||
| }, swift: any): Promise<{ | ||
| addImports: (importObject: WebAssembly.Imports) => void; | ||
| setInstance: (instance: WebAssembly.Instance) => void; | ||
| createExports: (instance: WebAssembly.Instance) => Exports; | ||
| }>; |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.