1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_8_5/extensions/weakmap.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,107 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/licenses/publicdomain/ 1.7 + * Contributor: 1.8 + * Andreas Gal <gal@mozilla.com> 1.9 + */ 1.10 + 1.11 +//----------------------------------------------------------------------------- 1.12 +var BUGNUMBER = 547941; 1.13 +var summary = 'js weak maps'; 1.14 +var actual = ''; 1.15 +var expect = ''; 1.16 + 1.17 +//----------------------------------------------------------------------------- 1.18 +test(); 1.19 +//----------------------------------------------------------------------------- 1.20 + 1.21 +function test() 1.22 +{ 1.23 + enterFunc ('test'); 1.24 + printBugNumber(BUGNUMBER); 1.25 + printStatus(summary); 1.26 + 1.27 + var TestPassCount = 0; 1.28 + var TestFailCount = 0; 1.29 + var TestTodoCount = 0; 1.30 + 1.31 + var TODO = 1; 1.32 + 1.33 + function check(fun, todo) { 1.34 + var thrown = null; 1.35 + var success = false; 1.36 + try { 1.37 + success = fun(); 1.38 + } catch (x) { 1.39 + thrown = x; 1.40 + } 1.41 + 1.42 + if (thrown) 1.43 + success = false; 1.44 + 1.45 + if (todo) { 1.46 + TestTodoCount++; 1.47 + 1.48 + if (success) { 1.49 + var ex = new Error; 1.50 + print ("=== TODO but PASSED? ==="); 1.51 + print (ex.stack); 1.52 + print ("========================"); 1.53 + } 1.54 + 1.55 + return; 1.56 + } 1.57 + 1.58 + if (success) { 1.59 + TestPassCount++; 1.60 + } else { 1.61 + TestFailCount++; 1.62 + 1.63 + var ex = new Error; 1.64 + print ("=== FAILED ==="); 1.65 + print (ex.stack); 1.66 + if (thrown) { 1.67 + print (" threw exception:"); 1.68 + print (thrown); 1.69 + } 1.70 + print ("=============="); 1.71 + } 1.72 + } 1.73 + 1.74 + function checkThrows(fun, todo) { 1.75 + let thrown = false; 1.76 + try { 1.77 + fun(); 1.78 + } catch (x) { 1.79 + thrown = true; 1.80 + } 1.81 + 1.82 + check(function() thrown, todo); 1.83 + } 1.84 + 1.85 + var key = {}; 1.86 + var map = WeakMap(); 1.87 + 1.88 + check(function() !map.has(key)); 1.89 + map.set(key, 42); 1.90 + check(function() map.get(key) == 42); 1.91 + check(function() typeof map.get({}) == "undefined"); 1.92 + check(function() map.get({}, "foo") == "foo"); 1.93 + 1.94 + gc(); gc(); gc(); 1.95 + 1.96 + check(function() map.get(key) == 42); 1.97 + map.delete(key); 1.98 + check(function() typeof map.get(key) == "undefined"); 1.99 + check(function() !map.has(key)); 1.100 + 1.101 + var value = { }; 1.102 + map.set(new Object(), value); 1.103 + gc(); gc(); gc(); 1.104 + 1.105 + print ("done"); 1.106 + 1.107 + reportCompare(0, TestFailCount, "weak map tests"); 1.108 + 1.109 + exitFunc ('test'); 1.110 +}