default-proto.js (2043B)
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 esid: sec-asyncgenerator-definitions-evaluatebody 5 description: > 6 Default [[Prototype]] value derived from realm of the async generator function. 7 info: | 8 Runtime Semantics: EvaluateBody 9 10 ... 11 2. Let generator be ? OrdinaryCreateFromConstructor(functionObject, "%AsyncGeneratorPrototype%", « ... »). 12 3. Perform ! AsyncGeneratorStart(generator, FunctionBody). 13 4. Return Completion { [[Type]]: return, [[Value]]: generator, [[Target]]: empty }. 14 15 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 16 17 ... 18 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 19 3. Return ObjectCreate(proto, internalSlotsList). 20 21 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 22 23 ... 24 3. Let proto be ? Get(constructor, 'prototype'). 25 4. If Type(proto) is not Object, then 26 a. Let realm be ? GetFunctionRealm(constructor). 27 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 28 5. Return proto. 29 features: [async-iteration, Symbol] 30 ---*/ 31 32 var fn = async function* () {}; 33 var AsyncGeneratorPrototype = Object.getPrototypeOf(fn.prototype); 34 35 fn.prototype = undefined; 36 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is undefined'); 37 38 fn.prototype = null; 39 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is null'); 40 41 fn.prototype = false; 42 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Boolean'); 43 44 fn.prototype = ''; 45 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a String'); 46 47 fn.prototype = Symbol(); 48 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Symbol'); 49 50 fn.prototype = 1; 51 assert.sameValue(Object.getPrototypeOf(fn()), AsyncGeneratorPrototype, 'fn.prototype is a Number'); 52 53 reportCompare(0, 0);