js/src/tests/js1_8_5/extensions/weakmap.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 /*
     2  * Any copyright is dedicated to the Public Domain.
     3  * http://creativecommons.org/licenses/publicdomain/
     4  * Contributor:
     5  *   Andreas Gal <gal@mozilla.com>
     6  */
     8 //-----------------------------------------------------------------------------
     9 var BUGNUMBER = 547941;
    10 var summary = 'js weak maps';
    11 var actual = '';
    12 var expect = '';
    14 //-----------------------------------------------------------------------------
    15 test();
    16 //-----------------------------------------------------------------------------
    18 function test()
    19 {
    20     enterFunc ('test');
    21     printBugNumber(BUGNUMBER);
    22     printStatus(summary);
    24     var TestPassCount = 0;
    25     var TestFailCount = 0;
    26     var TestTodoCount = 0;
    28     var TODO = 1;
    30     function check(fun, todo) {
    31         var thrown = null;
    32         var success = false;
    33         try {
    34             success = fun();
    35         } catch (x) {
    36             thrown = x;
    37         }
    39         if (thrown)
    40             success = false;
    42         if (todo) {
    43             TestTodoCount++;
    45             if (success) {
    46                 var ex = new Error;
    47                 print ("=== TODO but PASSED? ===");
    48                 print (ex.stack);
    49                 print ("========================");
    50             }
    52             return;
    53         }
    55         if (success) {
    56             TestPassCount++;
    57         } else {
    58             TestFailCount++;
    60             var ex = new Error;
    61             print ("=== FAILED ===");
    62             print (ex.stack);
    63             if (thrown) {
    64                 print ("    threw exception:");
    65                 print (thrown);
    66             }
    67             print ("==============");
    68         }
    69     }
    71     function checkThrows(fun, todo) {
    72         let thrown = false;
    73         try {
    74             fun();
    75         } catch (x) {
    76             thrown = true;
    77         }
    79         check(function() thrown, todo);
    80     }
    82     var key = {};
    83     var map = WeakMap();
    85     check(function() !map.has(key));
    86     map.set(key, 42);
    87     check(function() map.get(key) == 42);
    88     check(function() typeof map.get({}) == "undefined");
    89     check(function() map.get({}, "foo") == "foo");
    91     gc(); gc(); gc();
    93     check(function() map.get(key) == 42);
    94     map.delete(key);
    95     check(function() typeof map.get(key) == "undefined");
    96     check(function() !map.has(key));
    98     var value = { };
    99     map.set(new Object(), value);
   100     gc(); gc(); gc();
   102     print ("done");
   104     reportCompare(0, TestFailCount, "weak map tests");
   106     exitFunc ('test');
   107 }

mercurial