tor-browser

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

bug1762575-3.js (2330B)


      1 // Test implementation details when arguments object keep strong references
      2 // to their elements.
      3 
      4 function checkWeakRef(f, isCleared = true) {
      5  let [wr, args] = f({});
      6 
      7  assertEq(wr.deref() !== undefined, true);
      8 
      9  clearKeptObjects();
     10  gc();
     11 
     12  // In an ideal world, the reference is always cleared. But in specific
     13  // circumstances we're currently keeping the reference alive. Should this
     14  // ever change, feel free to update this test case accordingly. IOW having
     15  // |isCleared == false| is okay for spec correctness, but it isn't optimal.
     16  assertEq(wr.deref() === undefined, isCleared);
     17 }
     18 
     19 checkWeakRef(function() {
     20  // Create a weak-ref for the first argument.
     21  let wr = new WeakRef(arguments[0]);
     22 
     23  // Clear the reference from the arguments object.
     24  arguments[0] = null;
     25 
     26  // Let the arguments object escape.
     27  return [wr, arguments];
     28 });
     29 
     30 checkWeakRef(function() {
     31  // Create a weak-ref for the first argument.
     32  let wr = new WeakRef(arguments[0]);
     33 
     34  // Clear the reference from the arguments object.
     35  Object.defineProperty(arguments, 0, {value: null});
     36 
     37  // Let the arguments object escape.
     38  return [wr, arguments];
     39 });
     40 
     41 checkWeakRef(function self() {
     42  // Create a weak-ref for the first argument.
     43  let wr = new WeakRef(arguments[0]);
     44 
     45  // Delete operation doesn't clear the reference!
     46  delete arguments[0];
     47 
     48  // Let the arguments object escape.
     49  return [wr, arguments];
     50 }, /*isCleared=*/ false);
     51 
     52 checkWeakRef(function() {
     53  "use strict";
     54 
     55  // Create a weak-ref for the first argument.
     56  let wr = new WeakRef(arguments[0]);
     57 
     58  // Clear the reference from the arguments object.
     59  arguments[0] = null;
     60 
     61  // Let the arguments object escape.
     62  return [wr, arguments];
     63 });
     64 
     65 checkWeakRef(function() {
     66  "use strict";
     67 
     68  // Create a weak-ref for the first argument.
     69  let wr = new WeakRef(arguments[0]);
     70 
     71  // This define operation doesn't clear the reference!
     72  Object.defineProperty(arguments, 0, {value: null});
     73 
     74  // Let the arguments object escape.
     75  return [wr, arguments];
     76 }, /*isCleared=*/ false);
     77 
     78 checkWeakRef(function() {
     79  "use strict";
     80 
     81  // Create a weak-ref for the first argument.
     82  let wr = new WeakRef(arguments[0]);
     83 
     84  // Delete operation doesn't clear the reference!
     85  delete arguments[0];
     86 
     87  // Let the arguments object escape.
     88  return [wr, arguments];
     89 }, /*isCleared=*/ false);