tor-browser

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

shell.js (16409B)


      1 // GENERATED, DO NOT EDIT
      2 // file: iteratorZipUtils.js
      3 // Copyright (C) 2025 André Bargull.  All rights reserved.
      4 // This code is governed by the BSD license found in the LICENSE file.
      5 /*---
      6 description: |
      7    Utility functions for testing Iterator.prototype.zip and Iterator.prototype.zipKeyed. Requires inclusion of propertyHelper.js.
      8 defines:
      9  - forEachSequenceCombination
     10  - forEachSequenceCombinationKeyed
     11  - assertZipped
     12  - assertZippedKeyed
     13  - assertIteratorResult
     14  - assertIsPackedArray
     15 ---*/
     16 
     17 // Assert |result| is an object created by CreateIteratorResultObject.
     18 function assertIteratorResult(result, value, done, label) {
     19  assert.sameValue(
     20    Object.getPrototypeOf(result),
     21    Object.prototype,
     22    label + ": [[Prototype]] of iterator result is Object.prototype"
     23  );
     24 
     25  assert(Object.isExtensible(result), label + ": iterator result is extensible");
     26 
     27  var ownKeys = Reflect.ownKeys(result);
     28  assert.compareArray(ownKeys, ["value", "done"], label + ": iterator result properties");
     29 
     30  verifyProperty(result, "value", {
     31    value: value,
     32    writable: true,
     33    enumerable: true,
     34    configurable: true,
     35  });
     36 
     37  verifyProperty(result, "done", {
     38    value: done,
     39    writable: true,
     40    enumerable: true,
     41    configurable: true,
     42  });
     43 }
     44 
     45 // Assert |array| is a packed array with default property attributes.
     46 function assertIsPackedArray(array, label) {
     47  assert(Array.isArray(array), label + ": array is an array exotic object");
     48 
     49  assert.sameValue(
     50    Object.getPrototypeOf(array),
     51    Array.prototype,
     52    label + ": [[Prototype]] of array is Array.prototype"
     53  );
     54 
     55  assert(Object.isExtensible(array), label + ": array is extensible");
     56 
     57  // Ensure "length" property has its default property attributes.
     58  verifyProperty(array, "length", {
     59    writable: true,
     60    enumerable: false,
     61    configurable: false,
     62  });
     63 
     64  // Ensure no holes and all elements have the default property attributes.
     65  for (var i = 0; i < array.length; i++) {
     66    verifyProperty(array, i, {
     67      writable: true,
     68      enumerable: true,
     69      configurable: true,
     70    });
     71  }
     72 }
     73 
     74 // Assert |array| is an extensible null-prototype object with default property attributes.
     75 function _assertIsNullProtoMutableObject(object, label) {
     76  assert.sameValue(
     77    Object.getPrototypeOf(object),
     78    null,
     79    label + ": [[Prototype]] of object is null"
     80  );
     81 
     82  assert(Object.isExtensible(object), label + ": object is extensible");
     83 
     84  // Ensure all properties have the default property attributes.
     85  var keys = Object.getOwnPropertyNames(object);
     86  for (var i = 0; i < keys.length; i++) {
     87    verifyProperty(object, keys[i], {
     88      writable: true,
     89      enumerable: true,
     90      configurable: true,
     91    });
     92  }
     93 }
     94 
     95 // Assert that the `zipped` iterator yields the first `count` outputs of Iterator.zip.
     96 // Assumes `inputs` is an array of arrays, each with length >= `count`.
     97 // Advances `zipped` by `count` steps.
     98 function assertZipped(zipped, inputs, count, label) {
     99  // Last returned elements array.
    100  var last = null;
    101 
    102  for (var i = 0; i < count; i++) {
    103    var itemLabel = label + ", step " + i;
    104 
    105    var result = zipped.next();
    106    var value = result.value;
    107 
    108    // Test IteratorResult structure.
    109    assertIteratorResult(result, value, false, itemLabel);
    110 
    111    // Ensure value is a new array.
    112    assert.notSameValue(value, last, itemLabel + ": returns a new array");
    113    last = value;
    114 
    115    // Ensure all array elements have the expected value.
    116    var expected = inputs.map(function (array) {
    117      return array[i];
    118    });
    119    assert.compareArray(value, expected, itemLabel + ": values");
    120 
    121    // Ensure value is a packed array with default data properties.
    122    assertIsPackedArray(value, itemLabel);
    123  }
    124 }
    125 
    126 // Assert that the `zipped` iterator yields the first `count` outputs of Iterator.zipKeyed.
    127 // Assumes `inputs` is an object whose values are arrays, each with length >= `count`.
    128 // Advances `zipped` by `count` steps.
    129 function assertZippedKeyed(zipped, inputs, count, label) {
    130  // Last returned elements array.
    131  var last = null;
    132 
    133  var expectedKeys = Object.keys(inputs);
    134 
    135  for (var i = 0; i < count; i++) {
    136    var itemLabel = label + ", step " + i;
    137 
    138    var result = zipped.next();
    139    var value = result.value;
    140 
    141    // Test IteratorResult structure.
    142    assertIteratorResult(result, value, false, itemLabel);
    143 
    144    // Ensure resulting object is a new object.
    145    assert.notSameValue(value, last, itemLabel + ": returns a new object");
    146    last = value;
    147 
    148    // Ensure resulting object has the expected keys and values.
    149    assert.compareArray(Reflect.ownKeys(value), expectedKeys, itemLabel + ": result object keys");
    150 
    151    var expectedValues = Object.values(inputs).map(function (array) {
    152      return array[i];
    153    });
    154    assert.compareArray(Object.values(value), expectedValues, itemLabel + ": result object values");
    155 
    156    // Ensure resulting object is a null-prototype mutable object with default data properties.
    157    _assertIsNullProtoMutableObject(value, itemLabel);
    158  }
    159 }
    160 
    161 function forEachSequenceCombinationKeyed(callback) {
    162  return forEachSequenceCombination(function(inputs, inputsLabel, min, max) {
    163    var object = {};
    164    for (var i = 0; i < inputs.length; ++i) {
    165      object["prop_" + i] = inputs[i];
    166    }
    167    inputsLabel = "inputs = " + JSON.stringify(object);
    168    callback(object, inputsLabel, min, max);
    169  });
    170 }
    171 
    172 function forEachSequenceCombination(callback) {
    173  function test(inputs) {
    174    if (inputs.length === 0) {
    175      callback(inputs, "inputs = []", 0, 0);
    176      return;
    177    }
    178 
    179    var lengths = inputs.map(function(array) {
    180      return array.length;
    181    });
    182 
    183    var min = Math.min.apply(null, lengths);
    184    var max = Math.max.apply(null, lengths);
    185 
    186    var inputsLabel = "inputs = " + JSON.stringify(inputs);
    187 
    188    callback(inputs, inputsLabel, min, max);
    189  }
    190 
    191  // Yield all prefixes of the string |s|.
    192  function* prefixes(s) {
    193    for (var i = 0; i <= s.length; ++i) {
    194      yield s.slice(0, i);
    195    }
    196  }
    197 
    198  // Zip an empty iterable.
    199  test([]);
    200 
    201  // Zip a single iterator.
    202  for (var prefix of prefixes("abcd")) {
    203    test([prefix.split("")]);
    204  }
    205 
    206  // Zip two iterators.
    207  for (var prefix1 of prefixes("abcd")) {
    208    for (var prefix2 of prefixes("efgh")) {
    209      test([prefix1.split(""), prefix2.split("")]);
    210    }
    211  }
    212 
    213  // Zip three iterators.
    214  for (var prefix1 of prefixes("abcd")) {
    215    for (var prefix2 of prefixes("efgh")) {
    216      for (var prefix3 of prefixes("ijkl")) {
    217        test([prefix1.split(""), prefix2.split(""), prefix3.split("")]);
    218      }
    219    }
    220  }
    221 }
    222 
    223 // file: proxyTrapsHelper.js
    224 // Copyright (C) 2016 Jordan Harband.  All rights reserved.
    225 // This code is governed by the BSD license found in the LICENSE file.
    226 /*---
    227 description: |
    228    Used to assert the correctness of object behavior in the presence
    229    and context of Proxy objects.
    230 defines: [allowProxyTraps]
    231 ---*/
    232 
    233 function allowProxyTraps(overrides) {
    234  function throwTest262Error(msg) {
    235    return function () { throw new Test262Error(msg); };
    236  }
    237  if (!overrides) { overrides = {}; }
    238  return {
    239    getPrototypeOf: overrides.getPrototypeOf || throwTest262Error('[[GetPrototypeOf]] trap called'),
    240    setPrototypeOf: overrides.setPrototypeOf || throwTest262Error('[[SetPrototypeOf]] trap called'),
    241    isExtensible: overrides.isExtensible || throwTest262Error('[[IsExtensible]] trap called'),
    242    preventExtensions: overrides.preventExtensions || throwTest262Error('[[PreventExtensions]] trap called'),
    243    getOwnPropertyDescriptor: overrides.getOwnPropertyDescriptor || throwTest262Error('[[GetOwnProperty]] trap called'),
    244    has: overrides.has || throwTest262Error('[[HasProperty]] trap called'),
    245    get: overrides.get || throwTest262Error('[[Get]] trap called'),
    246    set: overrides.set || throwTest262Error('[[Set]] trap called'),
    247    deleteProperty: overrides.deleteProperty || throwTest262Error('[[Delete]] trap called'),
    248    defineProperty: overrides.defineProperty || throwTest262Error('[[DefineOwnProperty]] trap called'),
    249    enumerate: throwTest262Error('[[Enumerate]] trap called: this trap has been removed'),
    250    ownKeys: overrides.ownKeys || throwTest262Error('[[OwnPropertyKeys]] trap called'),
    251    apply: overrides.apply || throwTest262Error('[[Call]] trap called'),
    252    construct: overrides.construct || throwTest262Error('[[Construct]] trap called')
    253  };
    254 }
    255 
    256 // file: wellKnownIntrinsicObjects.js
    257 // Copyright (C) 2018 the V8 project authors. All rights reserved.
    258 // This code is governed by the BSD license found in the LICENSE file.
    259 /*---
    260 description: |
    261    An Array of all representable Well-Known Intrinsic Objects
    262 defines: [WellKnownIntrinsicObjects, getWellKnownIntrinsicObject]
    263 ---*/
    264 
    265 const WellKnownIntrinsicObjects = [
    266  {
    267    name: '%AggregateError%',
    268    source: 'AggregateError',
    269  },
    270  {
    271    name: '%Array%',
    272    source: 'Array',
    273  },
    274  {
    275    name: '%ArrayBuffer%',
    276    source: 'ArrayBuffer',
    277  },
    278  {
    279    name: '%ArrayIteratorPrototype%',
    280    source: 'Object.getPrototypeOf([][Symbol.iterator]())',
    281  },
    282  {
    283    // Not currently accessible to ECMAScript user code
    284    name: '%AsyncFromSyncIteratorPrototype%',
    285    source: '',
    286  },
    287  {
    288    name: '%AsyncFunction%',
    289    source: '(async function() {}).constructor',
    290  },
    291  {
    292    name: '%AsyncGeneratorFunction%',
    293    source: '(async function* () {}).constructor',
    294  },
    295  {
    296    name: '%AsyncGeneratorPrototype%',
    297    source: 'Object.getPrototypeOf(async function* () {}).prototype',
    298  },
    299  {
    300    name: '%AsyncIteratorPrototype%',
    301    source: 'Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype)',
    302  },
    303  {
    304    name: '%Atomics%',
    305    source: 'Atomics',
    306  },
    307  {
    308    name: '%BigInt%',
    309    source: 'BigInt',
    310  },
    311  {
    312    name: '%BigInt64Array%',
    313    source: 'BigInt64Array',
    314  },
    315  {
    316    name: '%BigUint64Array%',
    317    source: 'BigUint64Array',
    318  },
    319  {
    320    name: '%Boolean%',
    321    source: 'Boolean',
    322  },
    323  {
    324    name: '%DataView%',
    325    source: 'DataView',
    326  },
    327  {
    328    name: '%Date%',
    329    source: 'Date',
    330  },
    331  {
    332    name: '%decodeURI%',
    333    source: 'decodeURI',
    334  },
    335  {
    336    name: '%decodeURIComponent%',
    337    source: 'decodeURIComponent',
    338  },
    339  {
    340    name: '%encodeURI%',
    341    source: 'encodeURI',
    342  },
    343  {
    344    name: '%encodeURIComponent%',
    345    source: 'encodeURIComponent',
    346  },
    347  {
    348    name: '%Error%',
    349    source: 'Error',
    350  },
    351  {
    352    name: '%eval%',
    353    source: 'eval',
    354  },
    355  {
    356    name: '%EvalError%',
    357    source: 'EvalError',
    358  },
    359  {
    360    name: '%FinalizationRegistry%',
    361    source: 'FinalizationRegistry',
    362  },
    363  {
    364    name: '%Float32Array%',
    365    source: 'Float32Array',
    366  },
    367  {
    368    name: '%Float64Array%',
    369    source: 'Float64Array',
    370  },
    371  {
    372    // Not currently accessible to ECMAScript user code
    373    name: '%ForInIteratorPrototype%',
    374    source: '',
    375  },
    376  {
    377    name: '%Function%',
    378    source: 'Function',
    379  },
    380  {
    381    name: '%GeneratorFunction%',
    382    source: '(function* () {}).constructor',
    383  },
    384  {
    385    name: '%GeneratorPrototype%',
    386    source: 'Object.getPrototypeOf(function * () {}).prototype',
    387  },
    388  {
    389    name: '%Int8Array%',
    390    source: 'Int8Array',
    391  },
    392  {
    393    name: '%Int16Array%',
    394    source: 'Int16Array',
    395  },
    396  {
    397    name: '%Int32Array%',
    398    source: 'Int32Array',
    399  },
    400  {
    401    name: '%isFinite%',
    402    source: 'isFinite',
    403  },
    404  {
    405    name: '%isNaN%',
    406    source: 'isNaN',
    407  },
    408  {
    409    name: '%Iterator%',
    410    source: 'typeof Iterator !== "undefined" ? Iterator : Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())).constructor',
    411  },
    412  {
    413    name: '%IteratorHelperPrototype%',
    414    source: 'Object.getPrototypeOf(Iterator.from([]).drop(0))',
    415  },
    416  {
    417    name: '%JSON%',
    418    source: 'JSON',
    419  },
    420  {
    421    name: '%Map%',
    422    source: 'Map',
    423  },
    424  {
    425    name: '%MapIteratorPrototype%',
    426    source: 'Object.getPrototypeOf(new Map()[Symbol.iterator]())',
    427  },
    428  {
    429    name: '%Math%',
    430    source: 'Math',
    431  },
    432  {
    433    name: '%Number%',
    434    source: 'Number',
    435  },
    436  {
    437    name: '%Object%',
    438    source: 'Object',
    439  },
    440  {
    441    name: '%parseFloat%',
    442    source: 'parseFloat',
    443  },
    444  {
    445    name: '%parseInt%',
    446    source: 'parseInt',
    447  },
    448  {
    449    name: '%Promise%',
    450    source: 'Promise',
    451  },
    452  {
    453    name: '%Proxy%',
    454    source: 'Proxy',
    455  },
    456  {
    457    name: '%RangeError%',
    458    source: 'RangeError',
    459  },
    460  {
    461    name: '%ReferenceError%',
    462    source: 'ReferenceError',
    463  },
    464  {
    465    name: '%Reflect%',
    466    source: 'Reflect',
    467  },
    468  {
    469    name: '%RegExp%',
    470    source: 'RegExp',
    471  },
    472  {
    473    name: '%RegExpStringIteratorPrototype%',
    474    source: 'Object.getPrototypeOf(RegExp.prototype[Symbol.matchAll](""))',
    475  },
    476  {
    477    name: '%Set%',
    478    source: 'Set',
    479  },
    480  {
    481    name: '%SetIteratorPrototype%',
    482    source: 'Object.getPrototypeOf(new Set()[Symbol.iterator]())',
    483  },
    484  {
    485    name: '%SharedArrayBuffer%',
    486    source: 'SharedArrayBuffer',
    487  },
    488  {
    489    name: '%String%',
    490    source: 'String',
    491  },
    492  {
    493    name: '%StringIteratorPrototype%',
    494    source: 'Object.getPrototypeOf(new String()[Symbol.iterator]())',
    495  },
    496  {
    497    name: '%Symbol%',
    498    source: 'Symbol',
    499  },
    500  {
    501    name: '%SyntaxError%',
    502    source: 'SyntaxError',
    503  },
    504  {
    505    name: '%ThrowTypeError%',
    506    source: '(function() { "use strict"; return Object.getOwnPropertyDescriptor(arguments, "callee").get })()',
    507  },
    508  {
    509    name: '%TypedArray%',
    510    source: 'Object.getPrototypeOf(Uint8Array)',
    511  },
    512  {
    513    name: '%TypeError%',
    514    source: 'TypeError',
    515  },
    516  {
    517    name: '%Uint8Array%',
    518    source: 'Uint8Array',
    519  },
    520  {
    521    name: '%Uint8ClampedArray%',
    522    source: 'Uint8ClampedArray',
    523  },
    524  {
    525    name: '%Uint16Array%',
    526    source: 'Uint16Array',
    527  },
    528  {
    529    name: '%Uint32Array%',
    530    source: 'Uint32Array',
    531  },
    532  {
    533    name: '%URIError%',
    534    source: 'URIError',
    535  },
    536  {
    537    name: '%WeakMap%',
    538    source: 'WeakMap',
    539  },
    540  {
    541    name: '%WeakRef%',
    542    source: 'WeakRef',
    543  },
    544  {
    545    name: '%WeakSet%',
    546    source: 'WeakSet',
    547  },
    548  {
    549    name: '%WrapForValidIteratorPrototype%',
    550    source: 'Object.getPrototypeOf(Iterator.from({ [Symbol.iterator](){ return {}; } }))',
    551  },
    552 
    553  // Extensions to well-known intrinsic objects.
    554  //
    555  // https://tc39.es/ecma262/#sec-additional-properties-of-the-global-object
    556  {
    557    name: "%escape%",
    558    source: "escape",
    559  },
    560  {
    561    name: "%unescape%",
    562    source: "unescape",
    563  },
    564 
    565  // Extensions to well-known intrinsic objects.
    566  //
    567  // https://tc39.es/ecma402/#sec-402-well-known-intrinsic-objects
    568  {
    569    name: "%Intl%",
    570    source: "Intl",
    571  },
    572  {
    573    name: "%Intl.Collator%",
    574    source: "Intl.Collator",
    575  },
    576  {
    577    name: "%Intl.DateTimeFormat%",
    578    source: "Intl.DateTimeFormat",
    579  },
    580  {
    581    name: "%Intl.DisplayNames%",
    582    source: "Intl.DisplayNames",
    583  },
    584  {
    585    name: "%Intl.DurationFormat%",
    586    source: "Intl.DurationFormat",
    587  },
    588  {
    589    name: "%Intl.ListFormat%",
    590    source: "Intl.ListFormat",
    591  },
    592  {
    593    name: "%Intl.Locale%",
    594    source: "Intl.Locale",
    595  },
    596  {
    597    name: "%Intl.NumberFormat%",
    598    source: "Intl.NumberFormat",
    599  },
    600  {
    601    name: "%Intl.PluralRules%",
    602    source: "Intl.PluralRules",
    603  },
    604  {
    605    name: "%Intl.RelativeTimeFormat%",
    606    source: "Intl.RelativeTimeFormat",
    607  },
    608  {
    609    name: "%Intl.Segmenter%",
    610    source: "Intl.Segmenter",
    611  },
    612  {
    613    name: "%IntlSegmentIteratorPrototype%",
    614    source: "Object.getPrototypeOf(new Intl.Segmenter().segment()[Symbol.iterator]())",
    615  },
    616  {
    617    name: "%IntlSegmentsPrototype%",
    618    source: "Object.getPrototypeOf(new Intl.Segmenter().segment())",
    619  },
    620 
    621  // Extensions to well-known intrinsic objects.
    622  //
    623  // https://tc39.es/proposal-temporal/#sec-well-known-intrinsic-objects
    624  {
    625    name: "%Temporal%",
    626    source: "Temporal",
    627  },
    628 ];
    629 
    630 WellKnownIntrinsicObjects.forEach((wkio) => {
    631  var actual;
    632 
    633  try {
    634    actual = new Function("return " + wkio.source)();
    635  } catch (exception) {
    636    // Nothing to do here.
    637  }
    638 
    639  wkio.value = actual;
    640 });
    641 
    642 /**
    643 * Returns a well-known intrinsic object, if the implementation provides it.
    644 * Otherwise, throws.
    645 * @param {string} key - the specification's name for the intrinsic, for example
    646 *   "%Array%"
    647 * @returns {object} the well-known intrinsic object.
    648 */
    649 function getWellKnownIntrinsicObject(key) {
    650  for (var ix = 0; ix < WellKnownIntrinsicObjects.length; ix++) {
    651    if (WellKnownIntrinsicObjects[ix].name === key) {
    652      var value = WellKnownIntrinsicObjects[ix].value;
    653      if (value !== undefined)
    654        return value;
    655      throw new Test262Error('this implementation could not obtain ' + key);
    656    }
    657  }
    658  throw new Test262Error('unknown well-known intrinsic ' + key);
    659 }