Skip to content

[BridgeJS] Support Foundation.URL as parameter/return type #496

Description

@kateinoigakukun
No description provided.

Activity

  1. MaxDesiatov commented on Jan 19, 2026

    @MaxDesiatov
    Member

    However this is implemented, it should be configurable for users building with Embedded Swift, where Foundation is unavailable.

  2. krodak commented on Feb 11, 2026

    @krodak
    Member

    I was thinking about working on implementing some Foundation types support in BridgeJS, starting with UUID (which could simplify interface a bit in our project) and designing the mechanism that could also cover URL

    Proposed approach:

    Add a new BridgeType.foundationType(FoundationTypeKind) case where FoundationTypeKind is a closed enum of recognized Foundation types (uuid, url, extensible to date etc.). Each kind declares its wire type (e.g., both UUID and URL use string on the wire), Swift type name, and TypeScript type.

    This means:

    • ABI: Foundation types reuse existing wire encodings (UUID/URL → string)
    • Swift side: Auto-generated lift/lower code converts between the Foundation type and its wire representation (UUID(uuidString:)! / .uuidString, URL(string:)! / .absoluteString)
    • TypeScript side: Maps to string
    • Embedded Swift: All Foundation bridging gated behind #if canImport(Foundation) in BridgeJSIntrinsics.swift, following approach similar to JavaScriptFoundationCompat

    The single foundationType case keeps changeset manageable, most switch statements over BridgeType can delegate to the wire type's existing handling rather than needing per-type branches.

    I could start on this early next week, happy to discuss the design before I start coding 🙏🏻

  3. kateinoigakukun commented on Feb 11, 2026

    @kateinoigakukun
    MemberAuthor

    Thanks @krodak for sharing your idea

    TBH I'm a bit concerned about adding more BridgeType cases before we pay down some of the existing complexity debt in the code generator. In particular, the current ad-hoc handling for container types should probably be moved out of the code generator and into something that leverages Swift's generic type system more directly.

    I think we should limit the set of types that the code generator needs to recognize to only those that truly require specialized, performance-critical handling. For everything else, I've been wondering whether we could adopt a more generic ABI approach (similar in spirit to a stack-based ABI), so that extending supported types wouldn't require invasive changes to the code generator.

  4. krodak commented on Feb 11, 2026

    @krodak
    Member

    @kateinoigakukun let me think on this for a bit, I think we could introduce something that could allow us to just have a set of pairs of Swift <-> TS types bridging defined and generalize code gen logic for them similarly to stack based types and also address ad-hoc handling

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions