js/src/jit-test/tests/basic/testReplaceMap.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/testReplaceMap.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,27 @@
     1.4 +
     1.5 +// String.replace on functions returning hashmap elements.
     1.6 +
     1.7 +function first() {
     1.8 +  var arr = {a: "hello", b: "there"};
     1.9 +  var s = 'a|b';
    1.10 +  return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g');
    1.11 +}
    1.12 +assertEq(first(), "hello|there");
    1.13 +
    1.14 +function second() {
    1.15 +  var arr = {a: "hello", c: "there"};
    1.16 +  var s = 'a|b|c';
    1.17 +  return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g');
    1.18 +}
    1.19 +assertEq(second(), "hello|undefined|there");
    1.20 +
    1.21 +Object.defineProperty(Object.prototype, "b", {get: function() { return "what"; }});
    1.22 +
    1.23 +assertEq(second(), "hello|what|there");
    1.24 +
    1.25 +function third() {
    1.26 +  var arr = {a: "hello", b: {toString: function() { arr = {}; return "three"; }}, c: "there"};
    1.27 +  var s = 'a|b|c';
    1.28 +  return s.replace(/[a-z]/g, function(a) { return arr[a]; }, 'g');
    1.29 +}
    1.30 +assertEq(third(), "hello|three|undefined");

mercurial