class-definition-null-proto-super.js (1448B)
1 // Copyright (C) 2016 the V8 project authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 /*--- 4 esid: sec-runtime-semantics-classdefinitionevaluation 5 description: > 6 Attempting to call `super()` in a null-extending class throws a TypeError, 7 because %FunctionPrototype% cannot be called as constructor function. 8 info: | 9 Runtime Semantics: ClassDefinitionEvaluation 10 11 [...] 12 5. If ClassHeritageopt is not present, then 13 [...] 14 6. Else, 15 [...] 16 b. Let superclass be the result of evaluating ClassHeritage. 17 [...] 18 e. If superclass is null, then 19 [...] 20 ii. Let constructorParent be the intrinsic object %FunctionPrototype%. 21 [...] 22 15. Let constructorInfo be the result of performing DefineMethod for constructor with arguments proto and constructorParent as the optional functionPrototype argument. 23 [...] 24 25 12.3.5.1 Runtime Semantics: Evaluation 26 27 SuperCall : super Arguments 28 29 [...] 30 3. Let func be ! GetSuperConstructor(). 31 4. Let argList be ? ArgumentListEvaluation of Arguments. 32 5. If IsConstructor(func) is false, throw a TypeError exception. 33 [...] 34 ---*/ 35 36 var unreachable = 0; 37 var reachable = 0; 38 39 class C extends null { 40 constructor() { 41 reachable += 1; 42 super(); 43 unreachable += 1; 44 } 45 } 46 47 assert.throws(TypeError, function() { 48 new C(); 49 }); 50 51 assert.sameValue(reachable, 1); 52 assert.sameValue(unreachable, 0); 53 54 reportCompare(0, 0);