tor-browser

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

properties.js (2854B)


      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 
      5 function assertOwnDescriptor(object, propertyKey, expected) {
      6  var desc = Object.getOwnPropertyDescriptor(object, propertyKey);
      7  if (desc === undefined) {
      8    assertEq(expected, undefined, "Property shouldn't be present");
      9    return;
     10  }
     11 
     12  assertEq(desc.enumerable, expected.enumerable, `${String(propertyKey)}.[[Enumerable]]`);
     13  assertEq(desc.configurable, expected.configurable, `${String(propertyKey)}.[[Configurable]]`);
     14 
     15  if (Object.prototype.hasOwnProperty.call(desc, "value")) {
     16    assertEq(desc.value, expected.value, `${String(propertyKey)}.[[Value]]`);
     17    assertEq(desc.writable, expected.writable, `${String(propertyKey)}.[[Writable]]`);
     18  } else {
     19    assertEq(desc.get, expected.get, `${String(propertyKey)}.[[Get]]`);
     20    assertEq(desc.set, expected.set, `${String(propertyKey)}.[[Set]]`);
     21  }
     22 }
     23 
     24 async function asyncFunc(){}
     25 var AsyncFunctionPrototype = Object.getPrototypeOf(asyncFunc);
     26 var AsyncFunction = AsyncFunctionPrototype.constructor;
     27 
     28 
     29 // ES2017, 25.5.2 Properties of the AsyncFunction Constructor
     30 
     31 assertEqArray(Object.getOwnPropertyNames(AsyncFunction).sort(), ["length", "name", "prototype"]);
     32 assertEqArray(Object.getOwnPropertySymbols(AsyncFunction), []);
     33 
     34 assertOwnDescriptor(AsyncFunction, "length", {
     35    value: 1, writable: false, enumerable: false, configurable: true
     36 });
     37 
     38 assertOwnDescriptor(AsyncFunction, "name", {
     39    value: "AsyncFunction", writable: false, enumerable: false, configurable: true
     40 });
     41 
     42 assertOwnDescriptor(AsyncFunction, "prototype", {
     43    value: AsyncFunctionPrototype, writable: false, enumerable: false, configurable: false
     44 });
     45 
     46 
     47 // ES2017, 25.5.3 Properties of the AsyncFunction Prototype Object
     48 
     49 assertEqArray(Object.getOwnPropertyNames(AsyncFunctionPrototype).sort(), ["constructor"]);
     50 assertEqArray(Object.getOwnPropertySymbols(AsyncFunctionPrototype), [Symbol.toStringTag]);
     51 
     52 assertOwnDescriptor(AsyncFunctionPrototype, "constructor", {
     53    value: AsyncFunction, writable: false, enumerable: false, configurable: true
     54 });
     55 
     56 assertOwnDescriptor(AsyncFunctionPrototype, Symbol.toStringTag, {
     57    value: "AsyncFunction", writable: false, enumerable: false, configurable: true
     58 });
     59 
     60 
     61 // ES2017, 25.5.4 AsyncFunction Instances
     62 
     63 assertEqArray(Object.getOwnPropertyNames(asyncFunc).sort(), ["length", "name"]);
     64 assertEqArray(Object.getOwnPropertySymbols(asyncFunc), []);
     65 
     66 assertOwnDescriptor(asyncFunc, "length", {
     67    value: 0, writable: false, enumerable: false, configurable: true
     68 });
     69 
     70 assertOwnDescriptor(asyncFunc, "name", {
     71    value: "asyncFunc", writable: false, enumerable: false, configurable: true
     72 });
     73 
     74 
     75 if (typeof reportCompare == "function")
     76    reportCompare(true, true);