Skip to content

Commit 5e6df20

Browse files
committed
Add test case where iteratorbindinginitialization-bindingrestelement throws
1 parent cff91cd commit 5e6df20

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (C) 2026 Garham Lee. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-runtime-semantics-bindinginitialization
6+
description: >
7+
IteratorBindingInitialization throws TypeError trying to destructure nested array.
8+
info: |
9+
Runtime Semantics: BindingInitialization (_value_, _environment_)
10+
11+
BindingPattern : ArrayBindingPattern
12+
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
13+
2. Let _result_ be Completion(IteratorBindingInitialization of |ArrayBindingPattern| with arguments _iteratorRecord_ and _environment_).
14+
15+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
16+
17+
ArrayBindingPattern : `[` Elision? BindingRestElement `]`
18+
1. If |Elision| is present, then
19+
a. Perform ? IteratorDestructuringAssignmentEvaluation of |Elision| with argument _iteratorRecord_.
20+
2. Return ? IteratorBindingInitialization of |BindingRestElement| with arguments _iteratorRecord_ and _environment_.
21+
22+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
23+
24+
BindingRestElement : `...` BindingPattern
25+
1. Let _A_ be ! ArrayCreate(0).
26+
3.c.i Return ? BindingInitialization of |BindingPattern| with arguments _A_ and _environment_.
27+
28+
Runtime Semantics: BindingInitialization (_value_, _environment_)
29+
30+
BindingPattern : ArrayBindingPattern
31+
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
32+
2. Let _result_ be Completion(IteratorBindingInitialization of |ArrayBindingPattern| with arguments _iteratorRecord_ and _environment_).
33+
34+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
35+
36+
BindingElement : BindingPattern Initializer?
37+
1. Let _v_ be *undefined*.
38+
4. Return ? BindingInitialization of |BindingPattern| with arguments _v_ and _environment_.
39+
40+
Runtime Semantics: BindingInitialization (_value_, _environment_)
41+
42+
BindingPattern : ArrayBindingPattern
43+
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
44+
45+
GetIterator (_obj_, _kind_)
46+
2. Else,
47+
a. Let _method_ be ? GetMethod(_obj_, %Symbol.iterator%).
48+
49+
GetMethod (_V_, _P_)
50+
1. Let _func_ be ? GetV(_V_, _P_).
51+
52+
GetV (_V_, _P_)
53+
1. Let _O_ be ? ToObject(_V_).
54+
features: [destructuring-binding]
55+
---*/
56+
assert.throws(TypeError, function () {
57+
var [, ...[[x]]] = '';
58+
}, "IteratorBindingInitialization throws TypeError trying to destructure nested array.");
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (C) 2026 Garham Lee. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-runtime-semantics-bindinginitialization
6+
description: >
7+
IteratorBindingInitialization throws TypeError trying to destructure nested object.
8+
info: |
9+
Runtime Semantics: BindingInitialization (_value_, _environment_)
10+
11+
BindingPattern : ArrayBindingPattern
12+
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
13+
2. Let _result_ be Completion(IteratorBindingInitialization of |ArrayBindingPattern| with arguments _iteratorRecord_ and _environment_).
14+
15+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
16+
17+
ArrayBindingPattern : `[` Elision? BindingRestElement `]`
18+
1. If |Elision| is present, then
19+
a. Perform ? IteratorDestructuringAssignmentEvaluation of |Elision| with argument _iteratorRecord_.
20+
2. Return ? IteratorBindingInitialization of |BindingRestElement| with arguments _iteratorRecord_ and _environment_.
21+
22+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
23+
24+
BindingRestElement : `...` BindingPattern
25+
1. Let _A_ be ! ArrayCreate(0).
26+
3.c.i Return ? BindingInitialization of |BindingPattern| with arguments _A_ and _environment_.
27+
28+
Runtime Semantics: BindingInitialization (_value_, _environment_)
29+
30+
BindingPattern : ArrayBindingPattern
31+
1. Let _iteratorRecord_ be ? GetIterator(_value_, ~sync~).
32+
2. Let _result_ be Completion(IteratorBindingInitialization of |ArrayBindingPattern| with arguments _iteratorRecord_ and _environment_).
33+
34+
Runtime Semantics: IteratorBindingInitialization (_iteratorRecord_, _environment_)
35+
36+
BindingElement : BindingPattern Initializer?
37+
1. Let _v_ be *undefined*.
38+
4. Return ? BindingInitialization of |BindingPattern| with arguments _v_ and _environment_.
39+
40+
Runtime Semantics: BindingInitialization (_value_, _environment_)
41+
42+
BindingPattern : ObjectBindingPattern
43+
1. Perform ? RequireObjectCoercible(_value_).
44+
features: [destructuring-binding]
45+
---*/
46+
assert.throws(TypeError, function () {
47+
var [... [{}]] = ''
48+
}, "IteratorBindingInitialization throws TypeError trying to destructure nested object.")

0 commit comments

Comments
 (0)