tor-browser

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

symbol-iterator.js (1935B)


      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 const { Actor } = require("resource://devtools/shared/protocol.js");
      8 const { symbolIteratorSpec } = require("resource://devtools/shared/specs/symbol-iterator.js");
      9 
     10 const DevToolsUtils = require("resource://devtools/shared/DevToolsUtils.js");
     11 
     12 loader.lazyRequireGetter(
     13  this,
     14  "propertyDescriptor",
     15  "resource://devtools/server/actors/object/property-descriptor.js",
     16  true
     17 );
     18 
     19 /**
     20 * Creates an actor to iterate over an object's symbols.
     21 *
     22 * @param objectActor ObjectActor
     23 *        The object actor.
     24 */
     25 class SymbolIteratorActor extends Actor {
     26  constructor(objectActor, conn) {
     27    super(conn, symbolIteratorSpec);
     28 
     29    let symbols = [];
     30    if (DevToolsUtils.isSafeDebuggerObject(objectActor.obj)) {
     31      try {
     32        symbols = objectActor.obj.getOwnPropertySymbols();
     33      } catch (err) {
     34        // The above can throw when the debuggee does not subsume the object's
     35        // compartment, or for some WrappedNatives like Cu.Sandbox.
     36      }
     37    }
     38 
     39    this.iterator = {
     40      size: symbols.length,
     41      symbolDescription(index) {
     42        const symbol = symbols[index];
     43        return {
     44          name: symbol.toString(),
     45          descriptor: propertyDescriptor(objectActor, symbol, 0),
     46        };
     47      },
     48    };
     49  }
     50 
     51  form() {
     52    return {
     53      type: this.typeName,
     54      actor: this.actorID,
     55      count: this.iterator.size,
     56    };
     57  }
     58 
     59  slice({ start, count }) {
     60    const ownSymbols = [];
     61    for (let i = start, m = start + count; i < m; i++) {
     62      ownSymbols.push(this.iterator.symbolDescription(i));
     63    }
     64    return {
     65      ownSymbols,
     66    };
     67  }
     68 
     69  all() {
     70    return this.slice({ start: 0, count: this.iterator.size });
     71  }
     72 }
     73 
     74 exports.SymbolIteratorActor = SymbolIteratorActor;