1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/collections/key-equality-1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,28 @@ 1.4 +// Different representations of the same number or string are treated as the same Map key. 1.5 + 1.6 +var m = new Map; 1.7 +var test = function test(a, b) { 1.8 + m.set(a, 'secret'); 1.9 + assertEq(m.get(b), 'secret'); 1.10 + m.set(b, 'password'); 1.11 + assertEq(m.get(a), 'password'); 1.12 + 1.13 + assertEq(a, b); 1.14 +}; 1.15 + 1.16 +// Float and integer representations of the same number are the same key. 1.17 +test(9, Math.sqrt(81)); 1.18 + 1.19 +// Ordinary strings and ropes are the same key. 1.20 +var a = Array(1001).join('x'); 1.21 +var b = Array(501).join('x') + Array(501).join('x'); 1.22 +test(a, b); 1.23 + 1.24 +// Two structurally different ropes with the same characters are the same key. 1.25 +a = ""; 1.26 +b = ""; 1.27 +for (var i = 0; i < 10; i++) { 1.28 + a = Array(501).join('x') + a; 1.29 + b = b + Array(501).join('x'); 1.30 +} 1.31 +test(a, b);