summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/testReplaceWithLambda.js
blob: 9aad5ef98b4909c9dfb9de9b2f8602719bf6b825 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// optimized
(function(b) {
    assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
})({a:'A', b:'B' });
(function() {
    var b = {a:'A', b:'B' };
    assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
})();
(function() {
    {
        let b = {a:'A', b:'B' };
        assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
    }
})();
(function() {
    var b = {a:'A', b:'B' };
    (function () {
        assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
    })();
})();
(function() {
    {
        let b = {a:'A', b:'B' };
        (function () {
            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
        })();
    }
})();
(function() {
    var b = {a:'A', b:'B' };
    (function () {
        (function () {
            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
        })();
    })();
})();

// not optimized:
(function() {
    var b = {a:'A', b:'B' };
    with ({}) {
        (function () {
            assertEq("abc".replace(/a|b/g, function(a) { return b[a] }), 'ABc');
        })();
    }
})();
(function() {
   var b = {a:'A', b:'B' };
   var bad = function() { b = {a:1, b:2}; return 'X' }
   Object.defineProperty(b, 'x', {get:bad});
   assertEq("xabc".replace(/x|a|b/g, function(a) { return b[a] }), 'X12c');
})();