summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/language/statements/async-generator/yield-star-async-from-sync-iterator-inaccessible.js
blob: f962045044b3a22467fb3244051cc650f683ab9a (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// |reftest| async
// Copyright (C) 2019 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-createasyncfromsynciterator
description: >
  Async-from-Sync Iterator instances are not accessible from user code.
info: |
  25.1.4.1 CreateAsyncFromSyncIterator ( syncIteratorRecord )
    1. Let asyncIterator be ! ObjectCreate(%AsyncFromSyncIteratorPrototype%, « [[SyncIteratorRecord]] »).
    2. Set asyncIterator.[[SyncIteratorRecord]] to syncIteratorRecord.
    3. Let nextMethod be ! Get(asyncIterator, "next").
    4. Let iteratorRecord be Record { [[Iterator]]: asyncIterator, [[NextMethod]]: nextMethod, [[Done]]: false }.
    5. Return iteratorRecord.

  14.4.14 Runtime Semantics: Evaluation
    YieldExpression : yield * AssignmentExpression
      1. Let generatorKind be ! GetGeneratorKind().
      ...
      4. Let iteratorRecord be ? GetIterator(value, generatorKind).
      ...

  7.4.1 GetIterator ( obj [ , hint [ , method ] ] )
    ...
    3. If method is not present, then
      a. If hint is async, then
        i. Set method to ? GetMethod(obj, @@asyncIterator).
        ii. If method is undefined, then
          1. Let syncMethod be ? GetMethod(obj, @@iterator).
          2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod).
          3. Return ? CreateAsyncFromSyncIterator(syncIteratorRecord).
      ...

flags: [async]
features: [async-iteration]
---*/

var AsyncIteratorPrototype = Object.getPrototypeOf(async function*(){}.constructor.prototype.prototype);

Object.defineProperty(AsyncIteratorPrototype, Symbol.iterator, {
  get() {
    throw new Error("@@iterator accessed");
  }
});

Object.defineProperty(AsyncIteratorPrototype, Symbol.asyncIterator, {
  get() {
    throw new Error("@@asyncIterator accessed");
  }
});

async function* g() {
    yield* [];
}
g().next().then(() => $DONE(), $DONE);