tor-browser

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

eager-ecma-allowlist.js (6740B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 /* global BigInt */
      5 
      6 "use strict";
      7 
      8 function matchingProperties(obj, regexp) {
      9  return Object.getOwnPropertyNames(obj)
     10    .filter(n => regexp.test(n))
     11    .map(n => obj[n])
     12    .filter(v => typeof v == "function");
     13 }
     14 
     15 function allProperties(obj) {
     16  return matchingProperties(obj, /./);
     17 }
     18 
     19 function getter(obj, name) {
     20  return Object.getOwnPropertyDescriptor(obj, name).get;
     21 }
     22 
     23 const TypedArray = Reflect.getPrototypeOf(Int8Array);
     24 
     25 const functionAllowList = [
     26  Array,
     27  Array.from,
     28  Array.isArray,
     29  Array.of,
     30  Array.prototype.concat,
     31  Array.prototype.entries,
     32  Array.prototype.every,
     33  Array.prototype.filter,
     34  Array.prototype.find,
     35  Array.prototype.findIndex,
     36  Array.prototype.flat,
     37  Array.prototype.flatMap,
     38  Array.prototype.forEach,
     39  Array.prototype.includes,
     40  Array.prototype.indexOf,
     41  Array.prototype.join,
     42  Array.prototype.keys,
     43  Array.prototype.lastIndexOf,
     44  Array.prototype.map,
     45  Array.prototype.reduce,
     46  Array.prototype.reduceRight,
     47  Array.prototype.slice,
     48  Array.prototype.some,
     49  Array.prototype.toReversed,
     50  Array.prototype.toSorted,
     51  Array.prototype.toSpliced,
     52  Array.prototype.values,
     53  Array.prototype.with,
     54  ArrayBuffer,
     55  ArrayBuffer.isView,
     56  ArrayBuffer.prototype.slice,
     57  BigInt,
     58  ...allProperties(BigInt),
     59  Boolean,
     60  DataView,
     61  Date,
     62  Date.now,
     63  Date.parse,
     64  Date.UTC,
     65  ...matchingProperties(Date.prototype, /^get/),
     66  ...matchingProperties(Date.prototype, /^to.*?String$/),
     67  Error,
     68  Function,
     69  Function.prototype.apply,
     70  Function.prototype.bind,
     71  Function.prototype.call,
     72  Function.prototype[Symbol.hasInstance],
     73  Int8Array,
     74  Uint8Array,
     75  Uint8ClampedArray,
     76  Int16Array,
     77  Uint16Array,
     78  Int32Array,
     79  Uint32Array,
     80  Float32Array,
     81  Float64Array,
     82  TypedArray.from,
     83  TypedArray.of,
     84  TypedArray.prototype.entries,
     85  TypedArray.prototype.every,
     86  TypedArray.prototype.filter,
     87  TypedArray.prototype.find,
     88  TypedArray.prototype.findIndex,
     89  TypedArray.prototype.forEach,
     90  TypedArray.prototype.includes,
     91  TypedArray.prototype.indexOf,
     92  TypedArray.prototype.join,
     93  TypedArray.prototype.keys,
     94  TypedArray.prototype.lastIndexOf,
     95  TypedArray.prototype.map,
     96  TypedArray.prototype.reduce,
     97  TypedArray.prototype.reduceRight,
     98  TypedArray.prototype.slice,
     99  TypedArray.prototype.some,
    100  TypedArray.prototype.subarray,
    101  TypedArray.prototype.toReversed,
    102  TypedArray.prototype.toSorted,
    103  TypedArray.prototype.values,
    104  TypedArray.prototype.with,
    105  ...allProperties(JSON),
    106  Map,
    107  Map.prototype.forEach,
    108  Map.prototype.get,
    109  Map.prototype.has,
    110  Map.prototype.entries,
    111  Map.prototype.keys,
    112  Map.prototype.values,
    113  ...allProperties(Math),
    114  Number,
    115  ...allProperties(Number),
    116  ...allProperties(Number.prototype),
    117  Object,
    118  Object.create,
    119  Object.keys,
    120  Object.entries,
    121  Object.getOwnPropertyDescriptor,
    122  Object.getOwnPropertyDescriptors,
    123  Object.getOwnPropertyNames,
    124  Object.getOwnPropertySymbols,
    125  Object.getPrototypeOf,
    126  Object.is,
    127  Object.isExtensible,
    128  Object.isFrozen,
    129  Object.isSealed,
    130  Object.values,
    131  Object.prototype.hasOwnProperty,
    132  Object.prototype.isPrototypeOf,
    133  Proxy,
    134  Proxy.revocable,
    135  Reflect.apply,
    136  Reflect.construct,
    137  Reflect.get,
    138  Reflect.getOwnPropertyDescriptor,
    139  Reflect.getPrototypeOf,
    140  Reflect.has,
    141  Reflect.isExtensible,
    142  Reflect.ownKeys,
    143  RegExp,
    144  RegExp.prototype.exec,
    145  RegExp.prototype.test,
    146  RegExp.prototype[Symbol.match],
    147  RegExp.prototype[Symbol.search],
    148  RegExp.prototype[Symbol.replace],
    149  Set,
    150  Set.prototype.entries,
    151  Set.prototype.forEach,
    152  Set.prototype.has,
    153  Set.prototype.values,
    154  String,
    155  ...allProperties(String),
    156  ...allProperties(String.prototype),
    157  Symbol,
    158  Symbol.keyFor,
    159  WeakMap,
    160  WeakMap.prototype.get,
    161  WeakMap.prototype.has,
    162  WeakSet,
    163  WeakSet.prototype.has,
    164  decodeURI,
    165  decodeURIComponent,
    166  encodeURI,
    167  encodeURIComponent,
    168  escape,
    169  isFinite,
    170  isNaN,
    171  unescape,
    172 ];
    173 
    174 const getterAllowList = [
    175  getter(ArrayBuffer.prototype, "byteLength"),
    176  getter(ArrayBuffer, Symbol.species),
    177  getter(Array, Symbol.species),
    178  getter(DataView.prototype, "buffer"),
    179  getter(DataView.prototype, "byteLength"),
    180  getter(DataView.prototype, "byteOffset"),
    181  getter(Error.prototype, "stack"),
    182  getter(Function.prototype, "arguments"),
    183  getter(Function.prototype, "caller"),
    184  getter(Intl.Locale.prototype, "baseName"),
    185  getter(Intl.Locale.prototype, "calendar"),
    186  getter(Intl.Locale.prototype, "caseFirst"),
    187  getter(Intl.Locale.prototype, "collation"),
    188  getter(Intl.Locale.prototype, "hourCycle"),
    189  getter(Intl.Locale.prototype, "numeric"),
    190  getter(Intl.Locale.prototype, "numberingSystem"),
    191  getter(Intl.Locale.prototype, "language"),
    192  getter(Intl.Locale.prototype, "script"),
    193  getter(Intl.Locale.prototype, "region"),
    194  getter(Map.prototype, "size"),
    195  getter(Map, Symbol.species),
    196  // NOTE: Object.prototype.__proto__ is not safe, because it can internally
    197  //       invoke Proxy getPrototypeOf handler.
    198  getter(Promise, Symbol.species),
    199  getter(RegExp, "input"),
    200  getter(RegExp, "lastMatch"),
    201  getter(RegExp, "lastParen"),
    202  getter(RegExp, "leftContext"),
    203  getter(RegExp, "rightContext"),
    204  getter(RegExp, "$1"),
    205  getter(RegExp, "$2"),
    206  getter(RegExp, "$3"),
    207  getter(RegExp, "$4"),
    208  getter(RegExp, "$5"),
    209  getter(RegExp, "$6"),
    210  getter(RegExp, "$7"),
    211  getter(RegExp, "$8"),
    212  getter(RegExp, "$9"),
    213  getter(RegExp, "$_"),
    214  getter(RegExp, "$&"),
    215  getter(RegExp, "$+"),
    216  getter(RegExp, "$`"),
    217  getter(RegExp, "$'"),
    218  getter(RegExp.prototype, "dotAll"),
    219  getter(RegExp.prototype, "flags"),
    220  getter(RegExp.prototype, "global"),
    221  getter(RegExp.prototype, "hasIndices"),
    222  getter(RegExp.prototype, "ignoreCase"),
    223  getter(RegExp.prototype, "multiline"),
    224  getter(RegExp.prototype, "source"),
    225  getter(RegExp.prototype, "sticky"),
    226  getter(RegExp.prototype, "unicode"),
    227  getter(RegExp.prototype, "unicodeSets"),
    228  getter(RegExp, Symbol.species),
    229  getter(Set.prototype, "size"),
    230  getter(Set, Symbol.species),
    231  getter(Symbol.prototype, "description"),
    232  getter(TypedArray.prototype, "buffer"),
    233  getter(TypedArray.prototype, "byteLength"),
    234  getter(TypedArray.prototype, "byteOffset"),
    235  getter(TypedArray.prototype, "length"),
    236  getter(TypedArray.prototype, Symbol.toStringTag),
    237  getter(TypedArray, Symbol.species),
    238 ];
    239 
    240 // TODO: See Bug 1910717, this can be removed when we remove the pref for iterator helpers
    241 if (typeof Iterator === "function") {
    242  // eslint-disable-next-line no-undef
    243  getterAllowList.push(getter(Iterator.prototype, "constructor"));
    244 }
    245 
    246 module.exports = { functions: functionAllowList, getters: getterAllowList };