summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/annexB/language/statements/for-await-of/iterator-close-return-emulates-undefined-throws-when-called.js
blob: 21860d325ec27c907ba5be8440b3f552b0b21fb2 (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
29
30
31
32
33
34
35
36
37
38
39
40
// |reftest| async
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-getiterator
description: >
    `GetIterator(obj, ~async~)` must attempt to call `obj[@@asyncIterator]` when
    that value is an object with an [[IsHTMLDDA]] internal slot, not act as if
    the value were `undefined`.
features: [async-iteration, IsHTMLDDA]
flags: [async]
---*/

async function f() {
  var IsHTMLDDA = $262.IsHTMLDDA;
  var iter = {
    [Symbol.asyncIterator]: IsHTMLDDA,
    get [Symbol.iterator]() {
      throw new Test262Error("shouldn't touch Symbol.iterator");
    },
  };

  // `IsHTMLDDA` is called here with `iter` as `this` and no arguments, and it's
  // expected to return `null` under these conditions.  Then the iteration
  // protocol throws a `TypeError` because `null` isn't an object.
  for await (var x of iter)
    return "for-await-of body shouldn't be reached";

  return "should have failed earlier";
}

f().then($DONE,
         function (e) {
           assert.sameValue(e.constructor, TypeError,
                            "expected TypeError because " +
                            "`iter[Symbol.asyncIterator]() returned a " +
                            "non-object: " + e);
         })
   .then($DONE, $DONE);