Debian Codegraph @

js/src/tests/test262/built-ins/AsyncFunction/proto-from-ctor-realm.js

raw
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-async-function-constructor-arguments
6 description: Default [[Prototype]] value derived from realm of the NewTarget.
7 info: |
8 AsyncFunction ( p1, p2, … , pn, body )
9
10 ...
11 3. Return CreateDynamicFunction(C, NewTarget, "async", args).
12
13 Runtime Semantics: CreateDynamicFunction ( constructor, newTarget, kind, args )
14
15 ...
16 9. Else if kind is "async", then
17 ...
18 c. Let fallbackProto be "%AsyncFunction.prototype%".
19 ...
20 18. Let proto be ? GetPrototypeFromConstructor(newTarget, fallbackProto).
21 ...
22
23 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
24
25 ...
26 3. Let proto be ? Get(constructor, "prototype").
27 4. If Type(proto) is not Object, then
28 a. Let realm be ? GetFunctionRealm(constructor).
29 b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
30 5. Return proto.
31 features: [async-functions, cross-realm, Reflect, Symbol]
32 ---*/
33
34 var AsyncFunction = Object.getPrototypeOf(async function() {}).constructor;
35 var other = $262.createRealm().global;
36 var OtherAsyncFunction = Object.getPrototypeOf(other.eval('(0, async function() {})')).constructor;
37 var newTarget = new other.Function();
38 var fn;
39
40 newTarget.prototype = undefined;
41 fn = Reflect.construct(AsyncFunction, [], newTarget);
42 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is undefined');
43
44 newTarget.prototype = null;
45 fn = Reflect.construct(AsyncFunction, [], newTarget);
46 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is null');
47
48 newTarget.prototype = true;
49 fn = Reflect.construct(AsyncFunction, [], newTarget);
50 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Boolean');
51
52 newTarget.prototype = '';
53 fn = Reflect.construct(AsyncFunction, [], newTarget);
54 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a String');
55
56 newTarget.prototype = Symbol();
57 fn = Reflect.construct(AsyncFunction, [], newTarget);
58 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Symbol');
59
60 newTarget.prototype = 1;
61 fn = Reflect.construct(AsyncFunction, [], newTarget);
62 assert.sameValue(Object.getPrototypeOf(fn), OtherAsyncFunction.prototype, 'newTarget.prototype is a Number');
63
64 reportCompare(0, 0);