tor-browser

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

proto-from-ctor-realm.js (2446B)


      1 // Copyright (C) 2019 Alexey Shvayka. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-intl.pluralrules
      6 description: Default [[Prototype]] value derived from realm of the NewTarget.
      7 info: |
      8  Intl.PluralRules ( [ locales [ , options ] ] )
      9 
     10  1. If NewTarget is undefined, throw a TypeError exception.
     11  2. Let pluralRules be ? OrdinaryCreateFromConstructor(newTarget, "%PluralRulesPrototype%", « ... »).
     12  3. Return ? InitializePluralRules(pluralRules, locales, options).
     13 
     14  OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] )
     15 
     16  ...
     17  2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto).
     18  3. Return ObjectCreate(proto, internalSlotsList).
     19 
     20  GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto )
     21 
     22  ...
     23  3. Let proto be ? Get(constructor, 'prototype').
     24  4. If Type(proto) is not Object, then
     25    a. Let realm be ? GetFunctionRealm(constructor).
     26    b. Set proto to realm's intrinsic object named intrinsicDefaultProto.
     27  5. Return proto.
     28 features: [cross-realm, Reflect, Symbol]
     29 ---*/
     30 
     31 var other = $262.createRealm().global;
     32 var newTarget = new other.Function();
     33 var pr;
     34 
     35 newTarget.prototype = undefined;
     36 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     37 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is undefined');
     38 
     39 newTarget.prototype = null;
     40 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     41 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is null');
     42 
     43 newTarget.prototype = false;
     44 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     45 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Boolean');
     46 
     47 newTarget.prototype = '';
     48 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     49 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a String');
     50 
     51 newTarget.prototype = Symbol();
     52 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     53 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Symbol');
     54 
     55 newTarget.prototype = 0;
     56 pr = Reflect.construct(Intl.PluralRules, [], newTarget);
     57 assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Number');
     58 
     59 reportCompare(0, 0);