js/src/jit-test/tests/debug/Source-introductionScript-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Dynamically generated sources should have their introduction script and
michael@0 2 // offset set correctly.
michael@0 3
michael@0 4 var g = newGlobal();
michael@0 5 var dbg = new Debugger;
michael@0 6 var gDO = dbg.addDebuggee(g);
michael@0 7 var log;
michael@0 8
michael@0 9 // Direct eval, while the frame is live.
michael@0 10 dbg.onDebuggerStatement = function (frame) {
michael@0 11 log += 'd';
michael@0 12 var source = frame.script.source;
michael@0 13 var introducer = frame.older;
michael@0 14 assertEq(source.introductionScript, introducer.script);
michael@0 15 assertEq(source.introductionOffset, introducer.offset);
michael@0 16 };
michael@0 17 log = '';
michael@0 18 g.eval('\n\neval("\\n\\ndebugger;");');
michael@0 19 assertEq(log, 'd');
michael@0 20
michael@0 21 // Direct eval, after the frame has been popped.
michael@0 22 var introducer, introduced;
michael@0 23 dbg.onDebuggerStatement = function (frame) {
michael@0 24 log += 'de1';
michael@0 25 introducer = frame.script;
michael@0 26 dbg.onDebuggerStatement = function (frame) {
michael@0 27 log += 'de2';
michael@0 28 introduced = frame.script.source;
michael@0 29 };
michael@0 30 };
michael@0 31 log = '';
michael@0 32 g.evaluate('debugger; eval("\\n\\ndebugger;");', { lineNumber: 1812 });
michael@0 33 assertEq(log, 'de1de2');
michael@0 34 assertEq(introduced.introductionScript, introducer);
michael@0 35 assertEq(introducer.getOffsetLine(introduced.introductionOffset), 1812);
michael@0 36
michael@0 37 // Indirect eval, while the frame is live.
michael@0 38 dbg.onDebuggerStatement = function (frame) {
michael@0 39 log += 'd';
michael@0 40 var source = frame.script.source;
michael@0 41 var introducer = frame.older;
michael@0 42 assertEq(source.introductionScript, introducer.script);
michael@0 43 assertEq(source.introductionOffset, introducer.offset);
michael@0 44 };
michael@0 45 log = '';
michael@0 46 g.eval('\n\n(0,eval)("\\n\\ndebugger;");');
michael@0 47 assertEq(log, 'd');
michael@0 48
michael@0 49 // Indirect eval, after the frame has been popped.
michael@0 50 var introducer, introduced;
michael@0 51 dbg.onDebuggerStatement = function (frame) {
michael@0 52 log += 'de1';
michael@0 53 introducer = frame.script;
michael@0 54 dbg.onDebuggerStatement = function (frame) {
michael@0 55 log += 'de2';
michael@0 56 introduced = frame.script.source;
michael@0 57 };
michael@0 58 };
michael@0 59 log = '';
michael@0 60 g.evaluate('debugger; (0,eval)("\\n\\ndebugger;");', { lineNumber: 1066 });
michael@0 61 assertEq(log, 'de1de2');
michael@0 62 assertEq(introduced.introductionScript, introducer);
michael@0 63 assertEq(introducer.getOffsetLine(introduced.introductionOffset), 1066);
michael@0 64
michael@0 65 // Function constructor.
michael@0 66 dbg.onDebuggerStatement = function (frame) {
michael@0 67 log += 'o';
michael@0 68 var outerScript = frame.script;
michael@0 69 var outerOffset = frame.offset;
michael@0 70 dbg.onDebuggerStatement = function (frame) {
michael@0 71 log += 'i';
michael@0 72 var source = frame.script.source;
michael@0 73 assertEq(source.introductionScript, outerScript);
michael@0 74 assertEq(outerScript.getOffsetLine(source.introductionOffset),
michael@0 75 outerScript.getOffsetLine(outerOffset));
michael@0 76 };
michael@0 77 };
michael@0 78 log = '';
michael@0 79 g.eval('\n\n\ndebugger; Function("debugger;")()');
michael@0 80 assertEq(log, 'oi');
michael@0 81
michael@0 82 // Function constructor, after the the introduction call's frame has been
michael@0 83 // popped.
michael@0 84 var introducer;
michael@0 85 dbg.onDebuggerStatement = function (frame) {
michael@0 86 log += 'F2';
michael@0 87 introducer = frame.script;
michael@0 88 };
michael@0 89 log = '';
michael@0 90 var fDO = gDO.evalInGlobal('debugger; Function("origami;")', { lineNumber: 1685 }).return;
michael@0 91 var source = fDO.script.source;
michael@0 92 assertEq(log, 'F2');
michael@0 93 assertEq(source.introductionScript, introducer);
michael@0 94 assertEq(introducer.getOffsetLine(source.introductionOffset), 1685);
michael@0 95
michael@0 96 // If the introduction script is in a different global from the script it
michael@0 97 // introduced, we don't record it.
michael@0 98 dbg.onDebuggerStatement = function (frame) {
michael@0 99 log += 'x';
michael@0 100 var source = frame.script.source;
michael@0 101 assertEq(source.introductionScript, undefined);
michael@0 102 assertEq(source.introductionOffset, undefined);
michael@0 103 };
michael@0 104 log = '';
michael@0 105 g.eval('debugger;'); // introduction script is this top-level script
michael@0 106 assertEq(log, 'x');
michael@0 107
michael@0 108 // If the code is introduced by a function that doesn't provide
michael@0 109 // introduction information, that shouldn't be a problem.
michael@0 110 dbg.onDebuggerStatement = function (frame) {
michael@0 111 log += 'x';
michael@0 112 var source = frame.script.source;
michael@0 113 assertEq(source.introductionScript, undefined);
michael@0 114 assertEq(source.introductionOffset, undefined);
michael@0 115 };
michael@0 116 log = '';
michael@0 117 g.eval('evaluate("debugger;", { lineNumber: 1729 });');
michael@0 118 assertEq(log, 'x');

mercurial