michael@0: michael@0: // String.replace on functions returning hashmap elements. michael@0: michael@0: function first() { michael@0: var arr = {a: "hello", b: "there"}; michael@0: var s = 'a|b'; michael@0: return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g'); michael@0: } michael@0: assertEq(first(), "hello|there"); michael@0: michael@0: function second() { michael@0: var arr = {a: "hello", c: "there"}; michael@0: var s = 'a|b|c'; michael@0: return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g'); michael@0: } michael@0: assertEq(second(), "hello|undefined|there"); michael@0: michael@0: Object.defineProperty(Object.prototype, "b", {get: function() { return "what"; }}); michael@0: michael@0: assertEq(second(), "hello|what|there"); michael@0: michael@0: function third() { michael@0: var arr = {a: "hello", b: {toString: function() { arr = {}; return "three"; }}, c: "there"}; michael@0: var s = 'a|b|c'; michael@0: return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g'); michael@0: } michael@0: assertEq(third(), "hello|three|undefined");