Repository navigation
Open
Description
Describe the bug
Three destructuring issues and one async try/catch/finally issue:
- Numeric key with a default in an assignment or arrow-parameter object pattern is rejected as a
SyntaxError.ObjectLiteral::to_pattern(core/ast/src/expression/literal/object.rs) checkslet name = name.literal()?;in the(_, Expression::Assign(assign)) => AssignTarget::Identifier(ident)arm, which returnsNonefor numeric keys because the parser stores numeric property names asPropertyName::Computed(Expression::Literal(...)). - Object rest after a nested pattern with a default does not exclude the key and evaluates its getter twice. In
compile_declaration_pattern_impl(core/engine/src/bytecompiler/declaration/declaration_pattern.rs), theObjectPatternElement::Patternarm does not push the property key toexcluded_keys_registers, soCopyDataPropertiescopies the property into the rest object again. - Array rest calls
next()again even when the iterator is already markeddone.iterator_to_array(core/engine/src/bytecompiler/iterator.rs) callsiterator_nextbefore checkingiterator_done, ignoring thedoneflag already set on the iterator record by an earlier destructuring element. - In an async function,
finally { return }does not override an exception thrown incatch. Whenreturnexecutes insidefinally,JumpRecordKind::Return(core/engine/src/bytecompiler/jump_control.rs) checksMaybeExceptionand rejects the async function's promise capability with the pending exception fromcatchinstead of resolving it with thefinallyreturn value.
To Reproduce
// 1. Numeric key with default in assignment / arrow parameter / for-of
let v;
({ 0: v = 5 } = []);
// SyntaxError: Invalid left-hand side in assignment at line 2, col 15
console.log((({ 0: a = 6 }) => a)([]));
// SyntaxError: invalid object binding pattern in formal parameter list at line 1, col 14
for ({ 7: v = 1 } of [{}]) {}
// SyntaxError: invalid object destructuring pattern in iterable loop initializer// 2. Object rest after a nested pattern with a default
let n = 0;
const { b: { c } = {}, ...rest } = { get b() { n++; return {}; }, c: 3 };
console.log(JSON.stringify(rest), n);
// Boa: {"b":{},"c":3} 2
// Expected: {"c":3} 1
// 3. Array rest calls next() again after done
let calls = 0;
const it = { [Symbol.iterator]() { return this; }, next() { calls++; return { done: true }; } };
const [x, ...y] = it;
console.log(calls);
// Boa: 2
// Expected: 1
// 4. Async function finally { return } after catch rethrow
async function a() { try { throw 1; } catch (e) { throw e; } finally { return 2; } }
a().then((v) => console.log("ok", v), (e) => console.log("rejected", e));
// Boa: rejected 1
// Expected: ok 2Expected behavior
- Case 1 parses and evaluates
vto5,ato6, andvto1(var { 0: v = 5 } = [],function f({ 0: v = 5 }),({ "0": v = 5 } = []), and({ 0: v } = [])already work). - Case 2 prints
{"c":3} 1(RestBindingInitialization excludes all bound property keys). - Case 3 prints
1(BindingRestElementonly steps the iterator wheniteratorRecord.[[Done]]isfalse). - Case 4 prints
ok 2(inTryStatementevaluation, an abruptreturncompletion fromFinallyreplaces the abruptthrowcompletion fromCatch; synchronous functions and generators in Boa already return2).
Build environment (please complete the following information):
- OS: Debian GNU/Linux 12 (bookworm)
- Version:
main(bfaa15a7d6, 2026-11-09) and v0.22.0 release binary - Target triple:
x86_64-unknown-linux-gnu - Rustc version:
rustc 1.98.1 (48a229cea 2026-09-01)
Additional context
Happy to split these into separate issues if preferred.
Related: labelled break out of a nested for…of
break L out of an inner for…of ends the enclosing for…of
const r = [];
for (const k of ["a", "b", "c"]) {
L: { for (const x of [0]) { break L; } }
r.push(k);
}
console.log(r.join()); // "a", expected "a,b,c"Same with for…in inside, or L: on a loop instead of a block. Outer for (let i…) is fine. With L: do { … } while (false) as the target the program never terminates.
Credit: https://ucsbplse.github.io/
Metadata
Metadata
Assignees
Labels
No labels
Activity
Tushar15769 commentedon Nov 10, 2026
Hey there @trackoor !!
I'd like to work and take a look at Bug 3 in this issue, where array destructuring seems to call
next()again even after the iterator is already done. I'll try my best fixing that behaviour and add a test to make surenext()is only called once in this case, without affecting normal array destructuring.tarushmohindru commentedon Nov 27, 2026
Hi! I'd like to work on Bug 4 (async
finally { return }not overriding acatchrethrow) if no one else has picked it up.I see #5656 covers Bug 3 and the labelled-break case is being tracked in #5671, so this shouldn't overlap with either. I'll link the PR here once it's up.
Surri757 commentedon Nov 29, 2026
Hi @trackoor, thanks for the very detailed report. I'd like to take Bug 1 — the numeric key with a default in an assignment or arrow-parameter object pattern being rejected as a
SyntaxError(theObjectLiteral::to_patternissue incore/ast/src/expression/literal/object.rs). I've reproduced all three cases from the issue (({ 0: v = 5 } = []),(({ 0: a = 6 }) => a)([]), andfor ({ 7: v = 1 } of [{}]) {}) and I'm working on a fix with tests. This shouldn't overlap with #5656 (Bug 3) or #5695 (Bug 4) — I'll link the PR here once it's ready.