tor-browser

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

proto-from-ctor-realm-zero.js (2435B)


      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 /*---
      5 esid: sec-array-constructor-array
      6 description: Default [[Prototype]] value derived from realm of the NewTarget.
      7 info: |
      8  Array ( )
      9 
     10  ...
     11  3. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget.
     12  4. Let proto be ? GetPrototypeFromConstructor(newTarget, "%Array.prototype%").
     13  5. Return ! ArrayCreate(0, proto).
     14 
     15  GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
     16 
     17  ...
     18  3. Let proto be ? Get(constructor, "prototype").
     19  4. If Type(proto) is not Object, then
     20    a. Let realm be ? GetFunctionRealm(constructor).
     21    b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
     22  5. Return proto.
     23 features: [cross-realm, Reflect, Symbol]
     24 ---*/
     25 
     26 var other = $262.createRealm().global;
     27 var newTarget = new other.Function();
     28 var arr;
     29 
     30 newTarget.prototype = undefined;
     31 arr = Reflect.construct(Array, [], newTarget);
     32 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     33 
     34 newTarget.prototype = null;
     35 arr = Reflect.construct(Array, [], newTarget);
     36 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     37 
     38 newTarget.prototype = true;
     39 arr = Reflect.construct(Array, [], newTarget);
     40 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     41 
     42 newTarget.prototype = 'str';
     43 arr = Reflect.construct(Array, [], newTarget);
     44 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     45 
     46 newTarget.prototype = Symbol();
     47 arr = Reflect.construct(Array, [], newTarget);
     48 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     49 
     50 newTarget.prototype = 1;
     51 arr = Reflect.construct(Array, [], newTarget);
     52 assert.sameValue(Object.getPrototypeOf(arr), other.Array.prototype, 'Object.getPrototypeOf(Reflect.construct(Array, [], newTarget)) returns other.Array.prototype');
     53 
     54 reportCompare(0, 0);