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

Sign up
Appearance settings

BridgeJS: Change @JS init to generate static init() methods instead of constructor in JS #409

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
kateinoigakukun merged 10 commits into main from yt/bjs-fix-swift-class
Aug 15, 2025

Conversation

@kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Aug 15, 2025
edited
Loading

Changes @JS init to generate static init() methods instead of direct constructors to separate two distinct Swift class instantiation patterns.

Problem

Previously, new SwiftClass() was used for both:

  1. Calling Swift @JS init constructors
  2. Lifting Swift class instances returned from exposed Swift functions (Swift side returns pointer, JS glue code lifts it into wrapper object)

These two operations should not share the same API as they have fundamentally different semantics.

Solution

  • @JS init now generates static init() methods for Swift constructor calls
  • new SwiftClass() is reserved for lifting Swift instances returned from Swift functions
  • Fixed handling of Swift classes without @JS init constructors

Changes on generated interface

// Before
export type Exports = {
 Greeter: {
 new(name: string): Greeter;
 }
}
const { exports } = await instantiate(...)
const greeter = new exports.Greeter("world");
// After
export type Exports = {
 Greeter: {
 init(name: string): Greeter;
 }
}
const { exports } = await instantiate(...)
const greeter = exports.Greeter.init("world");

- Add BridgeJS plugin test commands to CONTRIBUTING.md
- Document UPDATE_SNAPSHOTS=1 environment variable usage for snapshot tests
@kateinoigakukun kateinoigakukun merged commit 57a6fa2 into main Aug 15, 2025
9 checks passed
@kateinoigakukun kateinoigakukun deleted the yt/bjs-fix-swift-class branch August 15, 2025 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /