summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/weird-scopechains.js
blob: c992f315bbcba0e12e5c37960d018d1541e39448 (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
function checkNameLookup() {
    return "global";
}

function assertWithMessage(got, expected, message) {
    assertEq(message + ": " + got, message + ": " + expected);
}

var obj = {
    checkNameLookup: function() {
	return "local";
    },

    checkThisBinding: function() {
	return this.checkNameLookup();
    },
};

evaluate("(" + function() {
    assertWithMessage(checkNameLookup(), "local", "nameLookup");
    assertWithMessage(checkThisBinding(), "local", "thisBinding");

    // Important: lambda needs to close over "reason", so it won't just get the
    // scope of testFunc as its scope.  Instead it'll get the Call object
    // "reason" lives in.
    var reason = " in lambda in Call";
    (function() {
	assertWithMessage(checkNameLookup(), "local", "nameLookup" + reason);
	assertWithMessage(checkThisBinding(), "local", "thisBinding" + reason);
    })();
} + ")()", {envChainObject: obj});