[NFC] BridgeJS: Make JSGlueGen and IntrinsicJSFragment methods throwable by kateinoigakukun · Pull Request #606 · swiftwasm/JavaScriptKit
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.printCodeand several BridgeJSLink generation helpersthrows, updating call sites to usetry. - 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.