newtarget-proto-fallback.js (1673B)
1 // Copyright (C) 2019 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-aggregate-error 6 description: > 7 Fallback to the NewTarget's [[Prototype]] if the prototype property is not an object 8 info: | 9 AggregateError ( errors, message ) 10 11 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. 12 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]], [[AggregateErrors]] »). 13 ... 14 6. Return O. 15 16 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) 17 18 ... 19 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). 20 3. Return ObjectCreate(proto, internalSlotsList). 21 22 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) 23 24 ... 25 3. Let proto be ? Get(constructor, "prototype"). 26 4. If Type(proto) is not Object, then 27 a. Let realm be ? GetFunctionRealm(constructor). 28 b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 29 Return proto. 30 features: [AggregateError, Symbol] 31 ---*/ 32 33 const values = [ 34 undefined, 35 null, 36 42, 37 false, 38 true, 39 Symbol(), 40 'string', 41 AggregateError.prototype, 42 ]; 43 44 const NewTarget = new Function(); 45 46 for (const value of values) { 47 const NewTargetProxy = new Proxy(NewTarget, { 48 get(t, p) { 49 if (p === 'prototype') { 50 return value; 51 } 52 return t[p]; 53 } 54 }); 55 56 const error = Reflect.construct(AggregateError, [[]], NewTargetProxy); 57 assert.sameValue(Object.getPrototypeOf(error), AggregateError.prototype); 58 } 59 60 reportCompare(0, 0);