Skip to content

BridgeJS: support imports of JS Promise as async Swift#707

Open
MaxDesiatov wants to merge 10 commits intomainfrom
maxd/async-bridgejs
Open

BridgeJS: support imports of JS Promise as async Swift#707
MaxDesiatov wants to merge 10 commits intomainfrom
maxd/async-bridgejs

Conversation

@MaxDesiatov
Copy link
Member

@MaxDesiatov MaxDesiatov commented Mar 23, 2026

Supersedes #486.

Provides a motivating example with fetchWeatherData() test. The full end-to-end flow works:

  1. TypeScript interface WeatherData { temperature: number; description: string; humidity: number; };
  2. Function fetchWeatherData(city: string): Promise<WeatherData>;
  3. JS returns Promise.resolve({ temperature: 15.5, description: "Cloudy", humidity: 80 });
  4. Swift awaits and gets a typed WeatherData struct with .temperature, .description, .humidity properties;
  5. No Foundation, no Codable, no manual JSValue unwrapping for this and analogous functions backed by fetch(...).json().

Compatible with Embedded Swift.

@MaxDesiatov MaxDesiatov requested review from kateinoigakukun and krodak and removed request for kateinoigakukun March 23, 2026 23:15
@MaxDesiatov MaxDesiatov marked this pull request as ready for review March 23, 2026 23:16
@MaxDesiatov MaxDesiatov added enhancement New feature or request bridgejs labels Mar 23, 2026
@MaxDesiatov MaxDesiatov changed the title BridgeJS: support imports of Promise JS as async Swift BridgeJS: support imports of JS Promise as async Swift Mar 23, 2026
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

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

I think we need a different approach using JSTypedClosure to avoid the boxing

@MaxDesiatov MaxDesiatov marked this pull request as draft March 24, 2026 15:00
@MaxDesiatov MaxDesiatov removed the request for review from krodak March 24, 2026 15:00
@MaxDesiatov MaxDesiatov marked this pull request as ready for review March 24, 2026 16:51
import Testing
import JavaScriptKit

@Suite struct AsyncImportTests {
Copy link
Member

Choose a reason for hiding this comment

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

#expect(try weather2.temperature == 25.0)
#expect(try weather2.description == "Sunny")
#expect(try weather2.humidity == 40)
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you cover more cases especially around types using Stack ABI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bridgejs enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants