michael@0: // Different representations of the same number or string are treated as the same Map key. michael@0: michael@0: var m = new Map; michael@0: var test = function test(a, b) { michael@0: m.set(a, 'secret'); michael@0: assertEq(m.get(b), 'secret'); michael@0: m.set(b, 'password'); michael@0: assertEq(m.get(a), 'password'); michael@0: michael@0: assertEq(a, b); michael@0: }; michael@0: michael@0: // Float and integer representations of the same number are the same key. michael@0: test(9, Math.sqrt(81)); michael@0: michael@0: // Ordinary strings and ropes are the same key. michael@0: var a = Array(1001).join('x'); michael@0: var b = Array(501).join('x') + Array(501).join('x'); michael@0: test(a, b); michael@0: michael@0: // Two structurally different ropes with the same characters are the same key. michael@0: a = ""; michael@0: b = ""; michael@0: for (var i = 0; i < 10; i++) { michael@0: a = Array(501).join('x') + a; michael@0: b = b + Array(501).join('x'); michael@0: } michael@0: test(a, b);