Debian Codegraph @

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

raw
1 // Check the Frame.this getter always returns the same object for a given frame.
2 // Primitive this-values should not be boxed multiple times.
3
4 var g = newGlobal({newCompartment: true});
5 var dbg = new Debugger(g);
6 var framesEntered = 0;
7 var framesPopped = 0;
8 var numSteps = 0;
9 dbg.onEnterFrame = function (frame) {
10 if (frame.type === 'eval')
11 return;
12 framesEntered++;
13
14 var frameThis = frame.this;
15 assertEq(frame.this, frameThis);
16
17 frame.onPop = function() {
18 framesPopped++;
19 assertEq(frame.this, frameThis);
20 };
21
22 frame.onStep = function() {
23 numSteps++;
24 assertEq(frame.this, frameThis);
25 }
26
27 g.gotThis = frameThis.unsafeDereference();
28 };
29
30 g.eval("function nonstrictfun() { return this; }");
31 g.eval("nonstrictfun.call(Math); assertEq(gotThis, Math);");
32 g.eval("nonstrictfun.call(true); assertEq(gotThis.valueOf(), true);");
33 g.eval("nonstrictfun.call(); assertEq(gotThis, this);");
34
35 g.eval("function nonstrictfunNoThis() { return 1; }");
36 g.eval("nonstrictfunNoThis.call(Math); assertEq(gotThis, Math);");
37 g.eval("nonstrictfunNoThis.call(true); assertEq(gotThis.valueOf(), true);");
38 g.eval("nonstrictfunNoThis.call(); assertEq(gotThis, this);");
39
40 assertEq(framesEntered, 6);
41 assertEq(framesPopped, 6);
42 assertEq(numSteps > 15, true);