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

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

function testFunc() {
    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);
    })();
}

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

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

var cloneFunc = clone(testFunc, obj);
cloneFunc();