BridgeJS: Unify JSUndefinedOr and Optional intrinsic methods#681
Merged
kateinoigakukun merged 1 commit intomainfrom Feb 27, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
_BridgedAsOptionalprotocol with@_spi(BridgeJS)visibility, with conformances for bothOptionalandJSUndefinedOr - Refactored all
Optionalextension bridge methods to use_BridgedAsOptionalprotocol, enabling code reuse withJSUndefinedOr - Removed over 300 lines of duplicated bridge implementations for
JSUndefinedOrby delegating to the unified_BridgedAsOptionalextensions
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.