summaryrefslogtreecommitdiff
path: root/test/language/expressions/optional-chaining/iteration-statement-for-of-type-error.js
blob: 3cd18cd48ffe46028e2b88d1e717edc939372cc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Copyright 2019 Google, LLC.  All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: prod-OptionalExpression
description: >
  optional chain returning undefined in RHS of for of statement
info: |
  IterationStatement
    for (LeftHandSideExpression of Expression) Statement
features: [optional-chaining]
---*/

assert.throws(TypeError, function() {
  for (const key of {}?.a) ;
});

assert.throws(TypeError, function() {
  for (const key of {}?.a) {}
});

const obj = undefined;
assert.throws(TypeError, function() {
  for (const key of obj?.a) {}
});

assert.throws(TypeError, function() {
  for (const key of obj?.a);
});