tor-browser

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

computed-__proto__.js (3903B)


      1 // Copyright (C) 2017 the V8 project authors. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 /*---
      4 esid: prod-PropertyDefinition
      5 description: >
      6  computed __proto__ property key is assigned to an own property
      7 info: |
      8  12.2.6 Object Initializer
      9 
     10  PropertyDefinition[Yield, Await] :
     11    PropertyName[?Yield, ?Await] : AssignmentExpression[+In, ?Yield, ?Await]
     12 
     13  PropertyName[Yield, Await] :
     14    LiteralPropertyName
     15    ComputedPropertyName[?Yield, ?Await]
     16 
     17  ComputedPropertyName[Yield, Await] :
     18    [ AssignmentExpression[+In, ?Yield, ?Await] ]
     19 
     20  B.3.1__proto__ Property Names in Object Initializers
     21 
     22  ...
     23  5. If propKey is the String value "__proto__" and if IsComputedPropertyKey(propKey)
     24    is false, then
     25    a. If Type(propValue) is either Object or Null, then
     26        i. Return object.[[SetPrototypeOf]](propValue).
     27    b. Return NormalCompletion(empty).
     28 features: [Symbol]
     29 ---*/
     30 
     31 var obj;
     32 var sample = {};
     33 
     34 obj = {
     35  ['__proto__']: sample
     36 };
     37 assert.sameValue(
     38  Object.getPrototypeOf(obj),
     39  Object.prototype,
     40  'does not change the object prototype (ordinary object)'
     41 );
     42 assert(
     43  obj.hasOwnProperty('__proto__'),
     44  'computed __proto__ property is set as an own property (ordinary object)'
     45 );
     46 assert.sameValue(
     47  obj.__proto__,
     48  sample,
     49  'value is properly defined (ordinary object)'
     50 );
     51 
     52 obj = {
     53  ['__proto__']: null
     54 };
     55 assert.sameValue(
     56  Object.getPrototypeOf(obj),
     57  Object.prototype,
     58  'does not change the object prototype (null)'
     59 );
     60 assert(
     61  obj.hasOwnProperty('__proto__'),
     62  'computed __proto__ property is set as an own property (null)'
     63 );
     64 assert.sameValue(
     65  obj.__proto__,
     66  null,
     67  'value is properly defined (null)'
     68 );
     69 
     70 obj = {
     71  ['__proto__']: undefined
     72 };
     73 assert.sameValue(
     74  Object.getPrototypeOf(obj),
     75  Object.prototype,
     76  'does not change the object prototype (undefined)'
     77 );
     78 assert(
     79  obj.hasOwnProperty('__proto__'),
     80  'computed __proto__ property is set as an own property (undefined)'
     81 );
     82 assert.sameValue(
     83  obj.__proto__,
     84  undefined,
     85  'value is properly defined (undefined)'
     86 );
     87 
     88 var func = function() {};
     89 obj = {
     90  ['__proto__']: func
     91 };
     92 assert.sameValue(
     93  Object.getPrototypeOf(obj),
     94  Object.prototype,
     95  'does not change the object prototype (func)'
     96 );
     97 assert(
     98  obj.hasOwnProperty('__proto__'),
     99  'computed __proto__ property is set as an own property (func)'
    100 );
    101 assert.sameValue(
    102  obj.__proto__,
    103  func,
    104  'value is properly defined (func)'
    105 );
    106 
    107 var symbol = Symbol('Leo');
    108 obj = {
    109  ['__proto__']: symbol
    110 };
    111 assert.sameValue(
    112  Object.getPrototypeOf(obj),
    113  Object.prototype,
    114  'does not change the object prototype (symbol)'
    115 );
    116 assert(
    117  obj.hasOwnProperty('__proto__'),
    118  'computed __proto__ property is set as an own property (symbol)'
    119 );
    120 assert.sameValue(
    121  obj.__proto__,
    122  symbol,
    123  'value is properly defined (symbol)'
    124 );
    125 
    126 obj = {
    127  ['__proto__']: 42
    128 };
    129 assert.sameValue(
    130  Object.getPrototypeOf(obj),
    131  Object.prototype,
    132  'does not change the object prototype (number)'
    133 );
    134 assert(
    135  obj.hasOwnProperty('__proto__'),
    136  'computed __proto__ property is set as an own property (number)'
    137 );
    138 assert.sameValue(
    139  obj.__proto__,
    140  42,
    141  'value is properly defined (number)'
    142 );
    143 
    144 obj = {
    145  ['__proto__']: ''
    146 };
    147 assert.sameValue(
    148  Object.getPrototypeOf(obj),
    149  Object.prototype,
    150  'does not change the object prototype (string)'
    151 );
    152 assert(
    153  obj.hasOwnProperty('__proto__'),
    154  'computed __proto__ property is set as an own property (string)'
    155 );
    156 assert.sameValue(
    157  obj.__proto__,
    158  '',
    159  'value is properly defined (string)'
    160 );
    161 
    162 obj = {
    163  ['__proto__']: false
    164 };
    165 assert.sameValue(
    166  Object.getPrototypeOf(obj),
    167  Object.prototype,
    168  'does not change the object prototype (boolean)'
    169 );
    170 assert(
    171  obj.hasOwnProperty('__proto__'),
    172  'computed __proto__ property is set as an own property (boolean)'
    173 );
    174 assert.sameValue(
    175  obj.__proto__,
    176  false,
    177  'value is properly defined (boolean)'
    178 );
    179 
    180 reportCompare(0, 0);