1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/basic/testReplaceWithLambda.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,50 @@ 1.4 +// optimized 1.5 +(function(b) { 1.6 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.7 +})({a:'A', b:'B' }); 1.8 +(function() { 1.9 + var b = {a:'A', b:'B' }; 1.10 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.11 +})(); 1.12 +(function() { 1.13 + let (b = {a:'A', b:'B' }) { 1.14 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.15 + } 1.16 +})(); 1.17 +(function() { 1.18 + var b = {a:'A', b:'B' }; 1.19 + (function () { 1.20 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.21 + })(); 1.22 +})(); 1.23 +(function() { 1.24 + let (b = {a:'A', b:'B' }) { 1.25 + (function () { 1.26 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.27 + })(); 1.28 + } 1.29 +})(); 1.30 +(function() { 1.31 + var b = {a:'A', b:'B' }; 1.32 + (function () { 1.33 + (function () { 1.34 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.35 + })(); 1.36 + })(); 1.37 +})(); 1.38 + 1.39 +// not optimized: 1.40 +(function() { 1.41 + var b = {a:'A', b:'B' }; 1.42 + with ({}) { 1.43 + (function () { 1.44 + assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc'); 1.45 + })(); 1.46 + } 1.47 +})(); 1.48 +(function() { 1.49 + var b = {a:'A', b:'B' }; 1.50 + var bad = function() { b = {a:1, b:2}; return 'X' } 1.51 + Object.defineProperty(b, 'x', {get:bad}); 1.52 + assertEq("xabc".replace(/x|a|b/g, function(a) { return b[a] }), 'X12c'); 1.53 +})();