Debian Codegraph @

js/src/jit-test/tests/debug/Frame-this-09.js

raw
1 // Ensure |Frame.this| returns the right value even if we're still in the
2 // script's prologue, before JSOP_FUNCTIONTHIS.
3
4 var g = newGlobal({newCompartment: true});
5 var dbg = new Debugger(g);
6 var hits = 0;
7 dbg.onEnterFrame = function (frame) {
8 if (frame.type === 'eval')
9 return;
10 hits++;
11
12 var frameThis = frame.this;
13 if (frameThis !== null && typeof frameThis === "object")
14 g.gotThis = frameThis.unsafeDereference();
15 else
16 g.gotThis = frameThis;
17
18 assertEq(frame.this, frameThis, "getter should not return a different object");
19 };
20
21 // Strict mode, function uses |this|.
22 g.eval("function strictfun() { 'use strict'; return this; }");
23 g.eval("strictfun.call(Math); assertEq(gotThis, Math);");
24 g.eval("strictfun.call(true); assertEq(gotThis, true);");
25 g.eval("strictfun.call(); assertEq(gotThis, undefined);");
26
27 // Strict mode, function doesn't use |this|.
28 g.eval("function strictfunNoThis() { 'use strict'; }");
29 g.eval("strictfunNoThis.call(Math); assertEq(gotThis, Math);");
30 g.eval("strictfunNoThis.call(true); assertEq(gotThis, true);");
31 g.eval("strictfunNoThis.call(null); assertEq(gotThis, null);");
32
33 // Non-strict mode (primitive |this| is boxed), function uses |this|.
34 g.eval("function nonstrictfun() { return this; }");
35 g.eval("nonstrictfun.call(Math); assertEq(gotThis, Math);");
36 g.eval("nonstrictfun.call(null); assertEq(gotThis, this);");
37 g.eval("nonstrictfun.call(); assertEq(gotThis, this);");
38
39 // Non-strict mode (primitive |this| is boxed), function doesn't use |this|.
40 g.eval("function nonstrictfunNoThis() {}");
41 g.eval("nonstrictfunNoThis.call(Math); assertEq(gotThis, Math);");
42 g.eval("nonstrictfunNoThis.call(null); assertEq(gotThis, this);");
43 g.eval("nonstrictfunNoThis.call(); assertEq(gotThis, this);");
44
45 assertEq(hits, 12);