tor-browser

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

client.js (3275B)


      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 const {
      6  getValue,
      7  nodeHasFullText,
      8 } = require("resource://devtools/client/shared/components/object-inspector/utils/node.js");
      9 
     10 async function enumIndexedProperties(objectFront, start, end) {
     11  try {
     12    const iterator = await objectFront.enumProperties({
     13      ignoreNonIndexedProperties: true,
     14    });
     15    const response = await iteratorSlice(iterator, start, end);
     16    return response;
     17  } catch (e) {
     18    console.error("Error in enumIndexedProperties", e);
     19    return {};
     20  }
     21 }
     22 
     23 async function enumNonIndexedProperties(objectFront, start, end) {
     24  try {
     25    const iterator = await objectFront.enumProperties({
     26      ignoreIndexedProperties: true,
     27    });
     28    const response = await iteratorSlice(iterator, start, end);
     29    return response;
     30  } catch (e) {
     31    console.error("Error in enumNonIndexedProperties", e);
     32    return {};
     33  }
     34 }
     35 
     36 async function enumEntries(objectFront, start, end) {
     37  try {
     38    const iterator = await objectFront.enumEntries();
     39    const response = await iteratorSlice(iterator, start, end);
     40    return response;
     41  } catch (e) {
     42    console.error("Error in enumEntries", e);
     43    return {};
     44  }
     45 }
     46 
     47 async function enumSymbols(objectFront, start, end) {
     48  try {
     49    const iterator = await objectFront.enumSymbols();
     50    const response = await iteratorSlice(iterator, start, end);
     51    return response;
     52  } catch (e) {
     53    console.error("Error in enumSymbols", e);
     54    return {};
     55  }
     56 }
     57 
     58 async function enumPrivateProperties(objectFront, start, end) {
     59  try {
     60    const iterator = await objectFront.enumPrivateProperties();
     61    const response = await iteratorSlice(iterator, start, end);
     62    return response;
     63  } catch (e) {
     64    console.error("Error in enumPrivateProperties", e);
     65    return {};
     66  }
     67 }
     68 
     69 async function getPrototype(objectFront) {
     70  if (typeof objectFront.getPrototype !== "function") {
     71    console.error("objectFront.getPrototype is not a function");
     72    return Promise.resolve({});
     73  }
     74  return objectFront.getPrototype();
     75 }
     76 
     77 async function getFullText(longStringFront, item) {
     78  const { initial, fullText, length } = getValue(item);
     79  // Return fullText property if it exists so that it can be added to the
     80  // loadedProperties map.
     81  if (nodeHasFullText(item)) {
     82    return { fullText };
     83  }
     84 
     85  try {
     86    const substring = await longStringFront.substring(initial.length, length);
     87    return {
     88      fullText: initial + substring,
     89    };
     90  } catch (e) {
     91    console.error("LongStringFront.substring", e);
     92    throw e;
     93  }
     94 }
     95 
     96 async function getPromiseState(objectFront) {
     97  return objectFront.getPromiseState();
     98 }
     99 
    100 async function getProxySlots(objectFront) {
    101  return objectFront.getProxySlots();
    102 }
    103 
    104 function iteratorSlice(iterator, start, end) {
    105  start = start || 0;
    106  const count = end ? end - start + 1 : iterator.count;
    107 
    108  if (count === 0) {
    109    return Promise.resolve({});
    110  }
    111  return iterator.slice(start, count);
    112 }
    113 
    114 module.exports = {
    115  enumEntries,
    116  enumIndexedProperties,
    117  enumNonIndexedProperties,
    118  enumPrivateProperties,
    119  enumSymbols,
    120  getPrototype,
    121  getFullText,
    122  getPromiseState,
    123  getProxySlots,
    124 };