Frame-this-11.js (1829B)
1 // Ensure evalInFrame("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.eval('this').return; 13 if (frameThis !== null && typeof frameThis === "object") 14 g.gotThis = frameThis.unsafeDereference(); 15 else 16 g.gotThis = frameThis; 17 18 assertEq(frame.this, frameThis); 19 assertEq(frame.eval('this').return, frameThis); 20 }; 21 22 // Strict mode, function uses |this|. 23 g.eval("function strictfun() { 'use strict'; return this; }"); 24 g.eval("strictfun.call(Math); assertEq(gotThis, Math);"); 25 g.eval("strictfun.call(true); assertEq(gotThis, true);"); 26 g.eval("strictfun.call(); assertEq(gotThis, undefined);"); 27 28 // Strict mode, function doesn't use |this|. 29 g.eval("function strictfunNoThis() { 'use strict'; }"); 30 g.eval("strictfunNoThis.call(Math); assertEq(gotThis, Math);"); 31 g.eval("strictfunNoThis.call(true); assertEq(gotThis, true);"); 32 g.eval("strictfunNoThis.call(null); assertEq(gotThis, null);"); 33 34 // Non-strict mode (primitive |this| is boxed), function uses |this|. 35 g.eval("function nonstrictfun() { return this; }"); 36 g.eval("nonstrictfun.call(Math); assertEq(gotThis, Math);"); 37 g.eval("nonstrictfun.call(null); assertEq(gotThis, this);"); 38 g.eval("nonstrictfun.call(); assertEq(gotThis, this);"); 39 40 // Non-strict mode (primitive |this| is boxed), function doesn't use |this|. 41 g.eval("function nonstrictfunNoThis() {}"); 42 g.eval("nonstrictfunNoThis.call(Math); assertEq(gotThis, Math);"); 43 g.eval("nonstrictfunNoThis.call(null); assertEq(gotThis, this);"); 44 g.eval("nonstrictfunNoThis.call(); assertEq(gotThis, this);"); 45 46 assertEq(hits, 12);