BridgeJS: Standardize lift/lower pattern across Swift and JavaScript #423
Merged
kateinoigakukun merged 8 commits intomainfrom Aug 24, 2025
Merged
BridgeJS: Standardize lift/lower pattern across Swift and JavaScript #423kateinoigakukun merged 8 commits intomainfrom
kateinoigakukun merged 8 commits intomainfrom
Conversation
Replace global intrinsic functions with consistent extension-based system. Each bridged type now defines standardized lift/lower operations: Swift side (type extensions): - bridgeJSLowerParameter/Return: Swift -> Wasm core types - bridgeJSLiftParameter/Return: Wasm core types -> Swift JavaScript side (JSGlueGen): - Corresponding lift/lower functions for JS <-> Wasm interop Adds CodeFragmentPrinter for improved code organization. Reduces generated code complexity across both Swift and JS.
Clean up variable declaration in VariableDeclSyntax visitor.
Introduce _BridgedSwiftTypeLoweredIntoSingleWasmCoreType protocol to formalize lift/lower operations. All basic types (Bool, Int, Float, Double) now conform to this protocol with standardized bridgeJS* methods. Add _BridgedSwiftHeapObject and _BridgedSwiftEnumNoPayload protocols for heap objects and enums respectively. Update generated code and test snapshots to use new protocol-based intrinsic functions.
…gedClass Add _JSBridgedClass protocol with lift/lower operations for JavaScript objects imported into Swift. Update ImportTS code generation to use new protocol-based bridgeJS* methods. Update all generated ImportTS Swift files and test snapshots to use the new bridgeJS* method calls instead of legacy functions.
9811899 to
177be43
Compare
This is a workaround for the issue that reference to imported bjs wasm functions can't be eliminated in debug builds, even if they are not reachable at runtime without explicit BridgeJS usage.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR standardizes the lift/lower pattern across Swift and JavaScript by replacing global intrinsic functions with a consistent extension-based system. The change implements standardized bridge operations for each type, improving code organization and reducing complexity.
- Introduces a standardized lift/lower protocol system for all bridged types
- Replaces manual type conversion code with consistent
bridgeJSLowerParameter/ReturnandbridgeJSLiftParameter/Returnmethods - Adds
CodeFragmentPrinterfor improved JavaScript code generation
Reviewed Changes
Copilot reviewed 51 out of 56 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/JavaScriptKit/BridgeJSInstrincics.swift | Implements standardized lift/lower extensions for all basic types (Bool, Int, Float, Double, String, JSObject) and bridged types |
| Sources/JavaScriptKit/JSBridgedType.swift | Adds _JSBridgedClass protocol and updates JSBridgedClass to inherit from it |
| Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift | New file implementing JavaScript-side lift/lower operations with IntrinsicJSFragment |
| Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift | New utility class for organized code fragment printing |
| Multiple test snapshots | Updates generated code to use new standardized bridge methods |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Remove unused _BridgedSwiftTypeLoweredIntoWasmCoreType protocol and fix incomplete documentation comment for the remaining protocol.
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.
Replace global intrinsic functions with consistent extension-based system.
Each bridged type now defines standardized lift/lower operations:
Swift side (type extensions):
JavaScript side (JSGlueGen):
Adds CodeFragmentPrinter for improved code organization.
Reduces generated code complexity across both Swift and JS.