You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# fix(parser): replace expect_expression panic with try_into_expression error handling
2
+
3
+
## Summary
4
+
5
+
Replaces all uses of `expect_expression()` with `try_into_expression()` in the parser, and removes the panicking `expect_expression()` method. When the parser encounters arrow-function parameter list syntax in a context that requires an expression (e.g. conditional operator `a ? b : c`, call expression `foo()`, optional chaining `a?.b`), it now returns a recoverable parse error instead of panicking.
6
+
7
+
## Motivation
8
+
9
+
The `FormalParameterListOrExpression` type represents the grammar ambiguity between `(a, b)` as a comma expression vs `(a, b)` as arrow-function parameters. In contexts like the conditional operator (`x ? y : z`), call expressions (`f()`), and optional chaining (`a?.b`), the left-hand side must be an expression—arrow params are invalid. Previously, call sites used `expect_expression()`, which panics with "Unexpected arrow-function arguments" when the parser produced a `FormalParameterList` instead of an `Expression`. This can occur with edge-case input such as `(a) ? 1 : 2` when `(a)` is parsed as a single arrow param. For Boa as an embedded engine or in tooling, panics are unacceptable; the host expects a parse error. The `try_into_expression()` method already existed and returns `Err(Error::General { ... })` with a helpful message ("invalid arrow-function arguments (parentheses around the arrow-function may help)"). Replacing `expect_expression()` with `try_into_expression()?` propagates that error instead of panicking, aligning with Boa's stability goals.
-**Behavioral impact:** Invalid input that previously caused a panic now produces `Err(Error::General { message: "invalid arrow-function arguments (parentheses around the arrow-function may help)", position })`. Valid input is unchanged.
25
+
26
+
## Testing
27
+
28
+
-[x]`cargo test -p boa_parser` — all 296 tests pass
29
+
-[x]`cargo test -p boa_engine --lib` — all 921 tests pass
.expect("registers must have an async generator object")
137
-
.as_object()
143
+
.js_expect("registers must have an async generator object")?;
144
+
145
+
Ok(val.as_object())
138
146
}
139
147
}
140
148
@@ -306,7 +314,7 @@ impl Generator {
306
314
307
315
letmut r#gen = generator_obj
308
316
.downcast_mut::<Self>()
309
-
.expect("already checked this object type");
317
+
.js_expect("already checked this object type")?;
310
318
311
319
// 8. Push genContext onto the execution context stack; genContext is now the running execution context.
312
320
// 9. Resume the suspended evaluation of genContext using NormalCompletion(value) as the result of the operation that suspended it. Let result be the value returned by the resumed computation.
0 commit comments