Skip to content

Conversation

@andreabergia
Copy link
Contributor

Extend the parser and IR to support things like catch ({message}) or catch ([a, b]).

Note that, while Rhino supports a non-standard extension for conditions in catch clauses, i.e. catch (a if b), I have opted to not support it if we have a destructuring expression.

The implementation does this:

  • at parse time, we rely on pre-existing functions
  • the AST node for CatchClause was made more generic, and will now contain either the name or the destructuring expression
  • during the IR generation, from:
catch ( {message} ) { 
  body
}

we generate:

catch ( $tempname ) { 
  let {message} = $tempname;
  body
}

Fixes #2194

Extend the parser and IR to support things like `catch ({message})` or
`catch ([a, b])`.

Note that, while Rhino supports a non-standard extension for conditions
in catch clauses, i.e. `catch (a if b)`, I have opted to _not_ support
it if we have a destructuring expression.
@rbri
Copy link
Collaborator

rbri commented Dec 3, 2025

Wow 50 mor passing test...

public class CatchClause extends AstNode {

private Name varName;
private AstNode varName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

at least the name of the var and the name of the getter/setter does no longer match the value

catchCond = transform(ccc);
} else {
AstNode ccc = cc.getCatchCondition();
if (ccc != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

depressive if - maybe you can swap the branches

@gbrail
Copy link
Collaborator

gbrail commented Dec 7, 2025

Thanks!

@gbrail gbrail merged commit 9e3d6c0 into mozilla:master Dec 7, 2025
11 checks passed
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.

Support destructuring in catch

4 participants