tor-browser

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

messages.js (1254B)


      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 "use strict";
      6 
      7 function getArrayTypeNames() {
      8  return [
      9    "Array",
     10    "Int8Array",
     11    "Uint8Array",
     12    "Int16Array",
     13    "Uint16Array",
     14    "Int32Array",
     15    "Uint32Array",
     16    "Float32Array",
     17    "Float64Array",
     18    "Uint8ClampedArray",
     19    "BigInt64Array",
     20    "BigUint64Array",
     21  ];
     22 }
     23 
     24 /**
     25 * Return true if the parameters passed to console.log is supported.
     26 * The parameters can be either from server side (without getGrip) or client
     27 * side (with getGrip).
     28 *
     29 * @param {Message} parameters
     30 * @returns {boolean}
     31 */
     32 function isSupportedByConsoleTable(parameters) {
     33  const supportedClasses = [
     34    "Object",
     35    "Map",
     36    "Set",
     37    "WeakMap",
     38    "WeakSet",
     39  ].concat(getArrayTypeNames());
     40 
     41  if (!Array.isArray(parameters) || parameters.length === 0 || !parameters[0]) {
     42    return false;
     43  }
     44 
     45  if (parameters[0].getGrip) {
     46    return supportedClasses.includes(parameters[0].getGrip().class);
     47  }
     48 
     49  return supportedClasses.includes(parameters[0].class);
     50 }
     51 
     52 module.exports = {
     53  getArrayTypeNames,
     54  isSupportedByConsoleTable,
     55 };