tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

testReplaceWithLambda.js (1352B)


      1 // optimized
      2 (function(b) {
      3    assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
      4 })({a:'A', b:'B' });
      5 (function() {
      6    var b = {a:'A', b:'B' };
      7    assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
      8 })();
      9 (function() {
     10    {
     11        let b = {a:'A', b:'B' };
     12        assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
     13    }
     14 })();
     15 (function() {
     16    var b = {a:'A', b:'B' };
     17    (function () {
     18        assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
     19    })();
     20 })();
     21 (function() {
     22    {
     23        let b = {a:'A', b:'B' };
     24        (function () {
     25            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
     26        })();
     27    }
     28 })();
     29 (function() {
     30    var b = {a:'A', b:'B' };
     31    (function () {
     32        (function () {
     33            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
     34        })();
     35    })();
     36 })();
     37 
     38 // not optimized:
     39 (function() {
     40    var b = {a:'A', b:'B' };
     41    with ({}) {
     42        (function () {
     43            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
     44        })();
     45    }
     46 })();
     47 (function() {
     48   var b = {a:'A', b:'B' };
     49   var bad = function() { b = {a:1, b:2}; return 'X' }
     50   Object.defineProperty(b, 'x', {get:bad});
     51   assertEq("xabc".replace(/x|a|b/g, function(a) { return b[a] }), 'X12c');
     52 })();