Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  test_weakRefs.html   Sprache: HTML

 
 products/sources/formale Sprachen/C/Firefox/js/xpconnect/tests/mochitest/test_weakRefs.html


<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test WeakRef works in the browser</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript">
      let wr1, wr2, wr3, wr4;

      function go() {
        SimpleTest.waitForExplicitFinish();

        // 1. WeakRef with JS target.
        wr1 = new WeakRef({});

        // 2. WeakRef with DOM object target (without preserved wrapper).
        wr2 = new WeakRef(document.createElement("div"));

        // 3. WeakRef with DOM object target (with preserved wrapper).
        let object = document.createElement("div");
        object.someProperty = true;
        wr3 = new WeakRef(object);
        object = null

        // 4. WeakRef with reachable DOM object target without preserved wrapper.
        document.body.appendChild(document.createElement("div"));
        wr4 = new WeakRef(document.body.lastChild);

        // WeakRef should keep the target in the current task.
        isnot(wr1.deref(), undefined, "deref() should return its target.");
        isnot(wr2.deref(), undefined, "deref() should return its target.");
        isnot(wr3.deref(), undefined, "deref() should return its target.");
        isnot(wr4.deref(), undefined, "deref() should return its target.");

        // WeakRef should keep the target until the end of current task, which
        // includes promise microtasks.
        Promise.resolve().then(() => {
          isnot(wr1.deref(), undefined, "deref() should return its target.");
          isnot(wr2.deref(), undefined, "deref() should return its target.");
          isnot(wr3.deref(), undefined, "deref() should return its target.");
          isnot(wr4.deref(), undefined, "deref() should return its target.");
        });

        // setTimeout will call its callback in a new task.
        setTimeout(task2, 0);
      }

      function task2() {
        // Trigger a full GC/CC/GC cycle to collect WeakRef targets.
        SpecialPowers.DOMWindowUtils.garbageCollect();
        SpecialPowers.DOMWindowUtils.cycleCollect();
        SpecialPowers.DOMWindowUtils.garbageCollect();

        is(wr1.deref(), undefined, "deref() should return undefined.");
        is(wr2.deref(), undefined, "deref() should return undefined.");
        is(wr3.deref(), undefined, "deref() should return undefined.");
        isnot(wr4.deref(), undefined, "deref() should return its target.");

        // setTimeout will call its callback in a new task.
        setTimeout(task3, 0);
      }

      function task3() {
        document.body.removeChild(document.body.lastChild);

        SpecialPowers.DOMWindowUtils.garbageCollect();
        SpecialPowers.DOMWindowUtils.cycleCollect();
        SpecialPowers.DOMWindowUtils.garbageCollect();

        is(wr1.deref(), undefined, "deref() should return undefined.");
        is(wr2.deref(), undefined, "deref() should return undefined.");
        is(wr3.deref(), undefined, "deref() should return undefined.");
        is(wr4.deref(), undefined, "deref() should return undefined.");

        SimpleTest.finish();
      }
    </script>
  </head>
  <body onload="go()"></body>
</html>

Messung V0.5
C=93 H=91 G=91

¤ Dauer der Verarbeitung: 0.8 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Produkte
     Quellcodebibliothek

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Monitoring

Montastic status badge