Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Exercise the call to ScriptDebugPrologue in js_InternalInterpret. |
michael@0 | 2 | |
michael@0 | 3 | // This may change, but as of this writing, inline caches (ICs) are |
michael@0 | 4 | // disabled in debug mode, and those are the only users of the out-of-line entry |
michael@0 | 5 | // points for JIT code (arityCheckEntry, argsCheckEntry, fastEntry); debug |
michael@0 | 6 | // mode uses only invokeEntry. This means most of the bytecode tails in |
michael@0 | 7 | // js_InternalInterpret that might call ScriptPrologue or ScriptEpilogue are |
michael@0 | 8 | // unreachable in debug mode: they're only called from the out-of-line entry |
michael@0 | 9 | // points. |
michael@0 | 10 | // |
michael@0 | 11 | // The exception is REJOIN_THIS_PROTOTYPE, which can be reached reliably if you |
michael@0 | 12 | // add a JS_GC call to stubs::GetPropNoCache. JIT code calls that stub to |
michael@0 | 13 | // retrieve the 'prototype' property of a function called as a constructor, if |
michael@0 | 14 | // TI can't establish the exact identity of that prototype's value at compile |
michael@0 | 15 | // time. Thus the preoccupation with constructors here. |
michael@0 | 16 | |
michael@0 | 17 | load(libdir + "asserts.js"); |
michael@0 | 18 | |
michael@0 | 19 | var debuggee = newGlobal(); |
michael@0 | 20 | var dbg = Debugger(debuggee); |
michael@0 | 21 | var hits, savedFrame; |
michael@0 | 22 | |
michael@0 | 23 | // Allow the constructor to return normally. |
michael@0 | 24 | dbg.onEnterFrame = function (frame) { |
michael@0 | 25 | hits++; |
michael@0 | 26 | if (frame.constructing) { |
michael@0 | 27 | savedFrame = frame; |
michael@0 | 28 | assertEq(savedFrame.live, true); |
michael@0 | 29 | return undefined; |
michael@0 | 30 | } |
michael@0 | 31 | return undefined; |
michael@0 | 32 | }; |
michael@0 | 33 | hits = 0; |
michael@0 | 34 | debuggee.hits = 0; |
michael@0 | 35 | savedFrame = undefined; |
michael@0 | 36 | assertEq(typeof debuggee.eval("function f(){ hits++; } f.prototype = {}; new f;"), "object"); |
michael@0 | 37 | assertEq(hits, 2); |
michael@0 | 38 | assertEq(savedFrame.live, false); |
michael@0 | 39 | assertEq(debuggee.hits, 1); |
michael@0 | 40 | |
michael@0 | 41 | // Force an early return from the constructor. |
michael@0 | 42 | dbg.onEnterFrame = function (frame) { |
michael@0 | 43 | hits++; |
michael@0 | 44 | if (frame.constructing) { |
michael@0 | 45 | savedFrame = frame; |
michael@0 | 46 | assertEq(savedFrame.live, true); |
michael@0 | 47 | return { return: "pass" }; |
michael@0 | 48 | } |
michael@0 | 49 | return undefined; |
michael@0 | 50 | }; |
michael@0 | 51 | hits = 0; |
michael@0 | 52 | debuggee.hits = 0; |
michael@0 | 53 | savedFrame = undefined; |
michael@0 | 54 | assertEq(typeof debuggee.eval("function f(){ hits++; } f.prototype = {}; new f;"), "object"); |
michael@0 | 55 | assertEq(hits, 2); |
michael@0 | 56 | assertEq(savedFrame.live, false); |
michael@0 | 57 | assertEq(debuggee.hits, 0); |
michael@0 | 58 | |
michael@0 | 59 | // Force the constructor to throw an exception. |
michael@0 | 60 | dbg.onEnterFrame = function (frame) { |
michael@0 | 61 | hits++; |
michael@0 | 62 | if (frame.constructing) { |
michael@0 | 63 | savedFrame = frame; |
michael@0 | 64 | assertEq(savedFrame.live, true); |
michael@0 | 65 | return { throw: "pass" }; |
michael@0 | 66 | } |
michael@0 | 67 | return undefined; |
michael@0 | 68 | }; |
michael@0 | 69 | hits = 0; |
michael@0 | 70 | debuggee.hits = 0; |
michael@0 | 71 | savedFrame = undefined; |
michael@0 | 72 | assertThrowsValue(function () { |
michael@0 | 73 | debuggee.eval("function f(){ hits++ } f.prototype = {}; new f;"); |
michael@0 | 74 | }, "pass"); |
michael@0 | 75 | assertEq(hits, 2); |
michael@0 | 76 | assertEq(savedFrame.live, false); |
michael@0 | 77 | assertEq(debuggee.hits, 0); |
michael@0 | 78 | |
michael@0 | 79 | // Ensure that forcing an early return only returns from one JS call. |
michael@0 | 80 | debuggee.eval("function g() { var result = new f; g_hits++; return result; }"); |
michael@0 | 81 | dbg.onEnterFrame = function (frame) { |
michael@0 | 82 | hits++; |
michael@0 | 83 | if (frame.constructing) { |
michael@0 | 84 | savedFrame = frame; |
michael@0 | 85 | assertEq(savedFrame.live, true); |
michael@0 | 86 | return { return: "pass" }; |
michael@0 | 87 | } |
michael@0 | 88 | return undefined; |
michael@0 | 89 | }; |
michael@0 | 90 | hits = 0; |
michael@0 | 91 | debuggee.hits = 0; |
michael@0 | 92 | debuggee.g_hits = 0; |
michael@0 | 93 | savedFrame = undefined; |
michael@0 | 94 | assertEq(typeof debuggee.eval("g();"), "object"); |
michael@0 | 95 | assertEq(hits, 3); |
michael@0 | 96 | assertEq(savedFrame.live, false); |
michael@0 | 97 | assertEq(debuggee.hits, 0); |
michael@0 | 98 | assertEq(debuggee.g_hits, 1); |