| 1 |
// Copyright (C) 2019 Alexey Shvayka. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-asyncgeneratorfunction |
| 6 |
description: Default [[Prototype]] value derived from realm of the NewTarget. |
| 7 |
info: | |
| 8 |
AsyncGeneratorFunction ( p1, p2, … , pn, body ) |
| 9 |
|
| 10 |
... |
| 11 |
3. Return ? CreateDynamicFunction(C, NewTarget, "async generator", args). |
| 12 |
|
| 13 |
Runtime Semantics: CreateDynamicFunction ( constructor, newTarget, kind, args ) |
| 14 |
|
| 15 |
... |
| 16 |
10. Else, |
| 17 |
a. Assert: kind is "async generator". |
| 18 |
... |
| 19 |
d. Let fallbackProto be "%AsyncGenerator%". |
| 20 |
... |
| 21 |
18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto). |
| 22 |
... |
| 23 |
|
| 24 |
GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) |
| 25 |
|
| 26 |
... |
| 27 |
3. Let proto be ? Get(constructor, "prototype"). |
| 28 |
4. If Type(proto) is not Object, then |
| 29 |
a. Let realm be ? GetFunctionRealm(constructor). |
| 30 |
b. Set proto to realm's intrinsic object named intrinsicDefaultProto. |
| 31 |
5. Return proto. |
| 32 |
features: [async-iteration, cross-realm, Reflect, Symbol] |
| 33 |
---*/ |
| 34 |
|
| 35 |
var AsyncGeneratorFunction = Object.getPrototypeOf(async function* () {}).constructor; |
| 36 |
var other = $262.createRealm().global; |
| 37 |
var OtherAsyncGeneratorFunction = Object.getPrototypeOf(other.eval('(0, async function* () {})')).constructor; |
| 38 |
var newTarget = new other.Function(); |
| 39 |
var fn; |
| 40 |
|
| 41 |
newTarget.prototype = undefined; |
| 42 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 43 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is undefined'); |
| 44 |
|
| 45 |
newTarget.prototype = null; |
| 46 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 47 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is null'); |
| 48 |
|
| 49 |
newTarget.prototype = true; |
| 50 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 51 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is a Boolean'); |
| 52 |
|
| 53 |
newTarget.prototype = ''; |
| 54 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 55 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is a String'); |
| 56 |
|
| 57 |
newTarget.prototype = Symbol(); |
| 58 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 59 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is a Symbol'); |
| 60 |
|
| 61 |
newTarget.prototype = 1; |
| 62 |
fn = Reflect.construct(AsyncGeneratorFunction, [], newTarget); |
| 63 |
assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncGeneratorFunction.prototype, 'newTarget.prototype is a Number'); |
| 64 |
|
| 65 |
reportCompare(0, 0); |