Skip to content

BridgeJS: Unify JSUndefinedOr and Optional intrinsic methods#681

Merged
kateinoigakukun merged 1 commit intomainfrom
pr-555f1adc5bc4fcf9cdc572ac439f174d13f79b1a
Feb 27, 2026
Merged

BridgeJS: Unify JSUndefinedOr and Optional intrinsic methods#681
kateinoigakukun merged 1 commit intomainfrom
pr-555f1adc5bc4fcf9cdc572ac439f174d13f79b1a

Conversation

@kateinoigakukun
Copy link
Member

No description provided.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request refactors the bridging layer to unify the intrinsic methods for JSUndefinedOr and Optional, eliminating significant code duplication. The refactoring introduces a _BridgedAsOptional protocol that both Optional and JSUndefinedOr conform to, allowing them to share the same bridge implementations through delegation to Optional<Wrapped> helper methods.

Changes:

  • Added _BridgedAsOptional protocol with @_spi(BridgeJS) visibility, with conformances for both Optional and JSUndefinedOr
  • Refactored all Optional extension bridge methods to use _BridgedAsOptional protocol, enabling code reuse with JSUndefinedOr
  • Removed over 300 lines of duplicated bridge implementations for JSUndefinedOr by delegating to the unified _BridgedAsOptional extensions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Sources/JavaScriptKit/JSUndefinedOr.swift Added @_spi(BridgeJS) visibility to _BridgedAsOptional conformance
Sources/JavaScriptKit/BridgeJSIntrinsics.swift Refactored bridge methods from Optional extensions to _BridgedAsOptional extensions, added Optional: _BridgedAsOptional conformance, removed duplicate implementations, reorganized code structure
Comments suppressed due to low confidence (1)

Sources/JavaScriptKit/BridgeJSIntrinsics.swift:1240

  • The comment "Use return lowering to retain the JS function so JS lifting can fetch it from the heap" was removed from line 1239 of the Optional extension for JSTypedClosure. This comment documents important memory management behavior for JavaScript function closures. Consider preserving this documentation or adding it elsewhere to maintain clarity on the retention semantics.
extension Optional {
    @_spi(BridgeJS) public consuming func bridgeJSLowerParameter<Signature>() -> (
        isSome: Int32, value: Int32
    ) where Wrapped == JSTypedClosure<Signature> {
        switch consume self {
        case .none:
            return (isSome: 0, value: 0)
        case .some(let wrapped):
            return (isSome: 1, value: wrapped.bridgeJSLowerParameter())

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kateinoigakukun kateinoigakukun merged commit a86c7d2 into main Feb 27, 2026
16 checks passed
@kateinoigakukun kateinoigakukun deleted the pr-555f1adc5bc4fcf9cdc572ac439f174d13f79b1a branch February 27, 2026 08:25
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