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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Source-introductionScript-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +// Dynamically generated sources should have their introduction script and
     1.5 +// offset set correctly.
     1.6 +
     1.7 +var g = newGlobal();
     1.8 +var dbg = new Debugger;
     1.9 +var gDO = dbg.addDebuggee(g);
    1.10 +var log;
    1.11 +
    1.12 +// Direct eval, while the frame is live.
    1.13 +dbg.onDebuggerStatement = function (frame) {
    1.14 +  log += 'd';
    1.15 +  var source = frame.script.source;
    1.16 +  var introducer = frame.older;
    1.17 +  assertEq(source.introductionScript, introducer.script);
    1.18 +  assertEq(source.introductionOffset, introducer.offset);
    1.19 +};
    1.20 +log = '';
    1.21 +g.eval('\n\neval("\\n\\ndebugger;");');
    1.22 +assertEq(log, 'd');
    1.23 +
    1.24 +// Direct eval, after the frame has been popped.
    1.25 +var introducer, introduced;
    1.26 +dbg.onDebuggerStatement = function (frame) {
    1.27 +  log += 'de1';
    1.28 +  introducer = frame.script;
    1.29 +  dbg.onDebuggerStatement = function (frame) {
    1.30 +    log += 'de2';
    1.31 +    introduced = frame.script.source;
    1.32 +  };
    1.33 +};
    1.34 +log = '';
    1.35 +g.evaluate('debugger; eval("\\n\\ndebugger;");', { lineNumber: 1812 });
    1.36 +assertEq(log, 'de1de2');
    1.37 +assertEq(introduced.introductionScript, introducer);
    1.38 +assertEq(introducer.getOffsetLine(introduced.introductionOffset), 1812);
    1.39 +
    1.40 +// Indirect eval, while the frame is live.
    1.41 +dbg.onDebuggerStatement = function (frame) {
    1.42 +  log += 'd';
    1.43 +  var source = frame.script.source;
    1.44 +  var introducer = frame.older;
    1.45 +  assertEq(source.introductionScript, introducer.script);
    1.46 +  assertEq(source.introductionOffset, introducer.offset);
    1.47 +};
    1.48 +log = '';
    1.49 +g.eval('\n\n(0,eval)("\\n\\ndebugger;");');
    1.50 +assertEq(log, 'd');
    1.51 +
    1.52 +// Indirect eval, after the frame has been popped.
    1.53 +var introducer, introduced;
    1.54 +dbg.onDebuggerStatement = function (frame) {
    1.55 +  log += 'de1';
    1.56 +  introducer = frame.script;
    1.57 +  dbg.onDebuggerStatement = function (frame) {
    1.58 +    log += 'de2';
    1.59 +    introduced = frame.script.source;
    1.60 +  };
    1.61 +};
    1.62 +log = '';
    1.63 +g.evaluate('debugger; (0,eval)("\\n\\ndebugger;");', { lineNumber: 1066 });
    1.64 +assertEq(log, 'de1de2');
    1.65 +assertEq(introduced.introductionScript, introducer);
    1.66 +assertEq(introducer.getOffsetLine(introduced.introductionOffset), 1066);
    1.67 +
    1.68 +// Function constructor.
    1.69 +dbg.onDebuggerStatement = function (frame) {
    1.70 +  log += 'o';
    1.71 +  var outerScript = frame.script;
    1.72 +  var outerOffset = frame.offset;
    1.73 +  dbg.onDebuggerStatement = function (frame) {
    1.74 +    log += 'i';
    1.75 +    var source = frame.script.source;
    1.76 +    assertEq(source.introductionScript, outerScript);
    1.77 +    assertEq(outerScript.getOffsetLine(source.introductionOffset),
    1.78 +             outerScript.getOffsetLine(outerOffset));
    1.79 +  };
    1.80 +};
    1.81 +log = '';
    1.82 +g.eval('\n\n\ndebugger; Function("debugger;")()');
    1.83 +assertEq(log, 'oi');
    1.84 +
    1.85 +// Function constructor, after the the introduction call's frame has been
    1.86 +// popped.
    1.87 +var introducer;
    1.88 +dbg.onDebuggerStatement = function (frame) {
    1.89 +  log += 'F2';
    1.90 +  introducer = frame.script;
    1.91 +};
    1.92 +log = '';
    1.93 +var fDO = gDO.evalInGlobal('debugger; Function("origami;")', { lineNumber: 1685 }).return;
    1.94 +var source = fDO.script.source;
    1.95 +assertEq(log, 'F2');
    1.96 +assertEq(source.introductionScript, introducer);
    1.97 +assertEq(introducer.getOffsetLine(source.introductionOffset), 1685);
    1.98 +
    1.99 +// If the introduction script is in a different global from the script it
   1.100 +// introduced, we don't record it.
   1.101 +dbg.onDebuggerStatement = function (frame) {
   1.102 +  log += 'x';
   1.103 +  var source = frame.script.source;
   1.104 +  assertEq(source.introductionScript, undefined);
   1.105 +  assertEq(source.introductionOffset, undefined);
   1.106 +};
   1.107 +log = '';
   1.108 +g.eval('debugger;'); // introduction script is this top-level script
   1.109 +assertEq(log, 'x');
   1.110 +
   1.111 +// If the code is introduced by a function that doesn't provide
   1.112 +// introduction information, that shouldn't be a problem.
   1.113 +dbg.onDebuggerStatement = function (frame) {
   1.114 +  log += 'x';
   1.115 +  var source = frame.script.source;
   1.116 +  assertEq(source.introductionScript, undefined);
   1.117 +  assertEq(source.introductionOffset, undefined);
   1.118 +};
   1.119 +log = '';
   1.120 +g.eval('evaluate("debugger;", { lineNumber: 1729 });');
   1.121 +assertEq(log, 'x');

mercurial