Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/devtools/shared/test-helpers/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 1 kB image not shown  

Quelle  tracked-objects.sys.mjs   Sprache: unbekannt

 
Spracherkennung für: .mjs vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

// Test-only module in order to register objects later inspected by
// the allocation tracker (in the same folder).
//
// We are going to store a weak reference to the passed objects,
// in order to prevent holding them in memory.
// Allocation tracker will then print detailed information
// about why these objects are still allocated.

const objects = [];

/**
 * Request to track why the given object is kept in memory,
 * later on, when retrieving all the watched object via getStillAllocatedObjects.
 */
export function track(obj) {
  // We store a weak reference, so that we do force keeping the object in memory!!
  objects.push(Cu.getWeakReference(obj));
}

/**
 * Return the reference and NodeId's of all the objects passed via `track()` method,
 * which are still hold in memory.
 *
 * NodeId's are used by spidermonkey memory API to designates JS objects in heap snapshots.
 */
export function getStillAllocatedObjects() {
  return (
    objects
      // Filter out objects which have been freed already
      .filter(ref => !!ref.get())
      .map(weakRef => {
        return {
          weakRef,
          // Convert objects from here instead of from allocation tracker in order
          // to be from the shared system compartment and avoid trying to compute the NodeId
          // of a wrapper!
          ubiNodeId: ChromeUtils.getObjectNodeId(weakRef.get()),
        };
      })
  );
}

/**
 * Used by tests to clear all tracked objects
 */
export function clear() {
  objects.length = 0;
}

[Dauer der Verarbeitung: 0.29 Sekunden, vorverarbeitet 2026-08-25]