js/xpconnect/tests/unit/test_js_weak_references.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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/. */
     5 /* See https://bugzilla.mozilla.org/show_bug.cgi?id=317304 */
     7 function run_test()
     8 {
     9   // Bug 712649: Calling getWeakReference(null) should work.
    10   try {
    11     var nullWeak = Components.utils.getWeakReference(null);
    12     do_check_true(nullWeak.get() === null);
    13   } catch (e) {
    14     do_check_true(false);
    15   }
    17   var obj = { num: 5, str: 'foo' };
    18   var weak = Components.utils.getWeakReference(obj);
    20   do_check_true(weak.get() === obj);
    21   do_check_true(weak.get().num == 5);
    22   do_check_true(weak.get().str == 'foo');
    24   // Force garbage collection
    25   Components.utils.forceGC();
    27   // obj still references the object, so it should still be accessible via weak
    28   do_check_true(weak.get() === obj);
    29   do_check_true(weak.get().num == 5);
    30   do_check_true(weak.get().str == 'foo');
    32   // Clear obj's reference to the object and force garbage collection. To make
    33   // sure that there are no instances of obj stored in the registers or on the
    34   // native stack and the conservative GC would not find it we force the same
    35   // code paths that we used for the initial allocation.
    36   obj = { num: 6, str: 'foo2' };
    37   var weak2 = Components.utils.getWeakReference(obj);
    38   do_check_true(weak2.get() === obj);
    40   Components.utils.forceGC();
    42   // The object should have been garbage collected and so should no longer be
    43   // accessible via weak
    44   do_check_true(weak.get() === null);
    45 }

mercurial