tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

newtarget-proto-fallback.js (1997B)


      1 // |reftest| shell-option(--enable-explicit-resource-management) skip-if(!(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration('explicit-resource-management'))||!xulRuntime.shell) -- explicit-resource-management is not enabled unconditionally, requires shell-options
      2 // Copyright (C) 2023 Ron Buckton. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 esid: sec-suppressederror-constructor
      7 description: >
      8  Fallback to the NewTarget's [[Prototype]] if the prototype property is not an object
      9 info: |
     10  SuppressedError ( error, suppressed, message )
     11 
     12  1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
     13  2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%SuppressedError.prototype%", « [[ErrorData]], [[AggregateErrors]] »).
     14  ...
     15  6. Return O.
     16 
     17  OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
     18 
     19  ...
     20  2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
     21  3. Return ObjectCreate(proto, internalSlotsList).
     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  Return proto.
     31 features: [explicit-resource-management, Symbol]
     32 ---*/
     33 
     34 const values = [
     35  undefined,
     36  null,
     37  42,
     38  false,
     39  true,
     40  Symbol(),
     41  'string',
     42  SuppressedError.prototype,
     43 ];
     44 
     45 const NewTarget = new Function();
     46 
     47 for (const value of values) {
     48  const NewTargetProxy = new Proxy(NewTarget, {
     49    get(t, p) {
     50      if (p === 'prototype') {
     51        return value;
     52      }
     53      return t[p];
     54    }
     55  });
     56 
     57  const error = Reflect.construct(SuppressedError, [], NewTargetProxy);
     58  assert.sameValue(Object.getPrototypeOf(error), SuppressedError.prototype);
     59 }
     60 
     61 reportCompare(0, 0);