summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/bug786114.js
blob: 718d0426c66d3aee2783b219729a7c11cf2e224a (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
let expected = 'o!o!o!';
let actual = '';

// g is a function that needs an implicit |this| if called within a |with|
// statement.  If we fail to provide that implicit |this|, it will append
// "[object global]" instead of "o!".
let o = {
  g: function() { actual += this.toString(); },
  toString: function() { return "o!"; }
}

// g's presence within the |with| is detected by simple tracking of |with|s
// during parsing.
with (o) {
  (function() { g(); })();
}

// The eval() defeats the tracking of |with| during parsing.  Instead, g's
// presence within the |with| is detected by looking at the scopeChain of the
// ParseContext.
with (o) {
  eval("(function() { g(); })()");
}

// This is like the above case, but the knowledge of the |with| presence must
// be inherited by the inner function.  This is the case that was missed in bug
// 786114.
with (o) {
  eval("(function() { (function() { g(); })(); })()");
}

assertEq(actual, expected);