instance-construct-throws.js (1151B)
1 // Copyright 2016 Microsoft, Inc. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 author: Brian Terlson <brian.terlson@microsoft.com> 6 esid: sec-async-function-instances 7 description: > 8 Async function instances are not constructors and do not have a 9 [[Construct]] slot. 10 info: | 11 25.5.1.1 AsyncFunction( p1, p2, … , pn, body ) 12 13 ... 14 3. Return CreateDynamicFunction(C, NewTarget, "async", args). 15 16 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction( constructor, newTarget, kind, args ) 17 18 ... 19 33. Perform FunctionInitialize(F, Normal, parameters, body, scope). 20 34. If kind is "generator", then 21 ... 22 35. Else if kind is "normal", perform MakeConstructor(F). 23 36. NOTE: Async functions are not constructable and do not have a [[Construct]] internal method 24 or a "prototype" property. 25 ... 26 ---*/ 27 28 async function foo() {} 29 assert.throws(TypeError, function() { 30 new foo(); 31 }); 32 33 var AsyncFunction = Object.getPrototypeOf(foo).constructor; 34 var instance = AsyncFunction(); 35 36 assert.throws(TypeError, function() { 37 new instance(); 38 }) 39 40 reportCompare(0, 0);