◐ Shell
reader mode source ↗
Skip to content

[NFC] BridgeJS: Make JSGlueGen and IntrinsicJSFragment methods throwable#606

Merged
kateinoigakukun merged 2 commits into
mainfrom
yt/fix-optional-swift-class-ret-2
Feb 9, 2026
Merged

[NFC] BridgeJS: Make JSGlueGen and IntrinsicJSFragment methods throwable#606
kateinoigakukun merged 2 commits into
mainfrom
yt/fix-optional-swift-class-ret-2

Conversation

@kateinoigakukun

Copy link
Copy Markdown
Member

Instead of crashing on errors in JS code generation for BridgeJSLink, we should prefer propagating errors.

Instead of crashing on errors in JS code generation for BridgeJSLink,
we should prefer propagating errors.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hide comment

Pull request overview

This PR updates BridgeJSLink’s JS glue code generation to propagate failures via Swift throws instead of crashing (previously via try! / forced failures), improving error handling during BridgeJSLink codegen.

Changes:

  • Make IntrinsicJSFragment.printCode and several BridgeJSLink generation helpers throws, updating call sites to use try.
  • Update intrinsic registration APIs (JSIntrinsicRegistry.register, JSGlueVariableScope.registerIntrinsic) to accept throwing builders (rethrows).
  • Replace prior try! usage across codegen paths (arrays/dictionaries/struct helpers/closure helpers) with error propagation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift Converts intrinsic fragment emission to throwing, removing try! and propagating codegen errors upward.
Plugins/BridgeJS/Sources/BridgeJSLink/CodeFragmentPrinter.swift Allows intrinsic builders to throw (rethrows) during registration.
Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift Updates JS glue generation to call throwing fragment builders and propagate errors via throws.
Comments suppressed due to low confidence (1)

Plugins/BridgeJS/Sources/BridgeJSLink/JSGlueGen.swift:3873

  • The generated JS for optional associated-value enum struct fields includes an extra trailing comma in the .lift(...) call (e.g. ...lift(caseIdVar, );), which will produce a JavaScript syntax error at runtime. Remove the stray comma so the generated call is valid; this same pattern also appears in the associated-value-enum lifting path used elsewhere in this file.
                    try printer.indent {
                        // Special handling for associated value enum - in struct fields, case ID is pushed to i32Stack
                        if case .associatedValueEnum(let enumName) = wrappedType {
                            let base = enumName.components(separatedBy: ".").last ?? enumName
                            let caseIdVar = scope.variable("enumCaseId")

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

Hide details View details @kateinoigakukun kateinoigakukun merged commit c336a3f into main Feb 9, 2026
11 checks passed
@kateinoigakukun kateinoigakukun deleted the yt/fix-optional-swift-class-ret-2 branch February 9, 2026 03: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