summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_Debugger.Source.prototype.introductionScript.html
blob: cbc2ae6155d399d3a9f6c2642b1afd3ef9af0cea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=969786

Debugger.Source.prototype.introductionScript and .introductionOffset should
behave when 'eval' is called with no scripted frames active at all.
-->
<head>
  <meta charset="utf-8">
  <title>Debugger.Source.prototype.introductionScript with no caller</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script>

Components.utils.import("resource://gre/modules/jsdebugger.jsm");
addDebuggerToGlobal(this);

window.onload = function () {
  SimpleTest.waitForExplicitFinish();

  var dbg, iframeDO, doc, script2DO;

  // Create an iframe to debug.
  var iframe = document.createElement("iframe");
  iframe.src = "data:text/html,<div>Hi!</div>";
  iframe.onload = onLoadHandler;
  document.body.appendChild(iframe);

  function onLoadHandler() {
    // Now that the iframe's window has been created, we can add
    // it as a debuggee.
    dbg = new Debugger;
    iframeDO = dbg.addDebuggee(iframe.contentWindow);

    doc = iframe.contentWindow.document;
    var script = doc.createElement('script');
    script.text = "setTimeout(eval.bind(null, 'debugger;'), 0);";
    dbg.onDebuggerStatement = timerHandler;
    doc.body.appendChild(script);
  }

  function timerHandler(frame) {
    // The top stack frame's source should have an undefined
    // introduction script and introduction offset.
    var source = frame.script.source;
    ok(source.introductionScript === undefined,
       "setTimeout eval introductionScript is undefined");
    ok(source.introductionOffset === undefined,
       "setTimeout eval introductionOffset is undefined");

    // Check that the above isn't just some quirk of iframes, or the
    // browser milieu destroying information: an eval script should indeed
    // have proper introduction information.
    var script2 = doc.createElement('script');
    script2.text = "eval('debugger;');";
    script2DO = iframeDO.makeDebuggeeValue(script2);
    dbg.onDebuggerStatement = evalHandler;
    doc.body.appendChild(script2);
  }

  function evalHandler(frame) {
    // The top stack frame's source should be introduced by the script that
    // called eval.
    var source = frame.script.source;
    var frame2 = frame.older;

    ok(source.introductionType === 'eval',
       "top frame's source was introduced by 'eval'");
    ok(source.introductionScript === frame2.script,
       "eval frame's introduction script is the older frame's script");
    ok(source.introductionOffset === frame2.offset,
       "eval frame's introduction offset is current offset in older frame");
    ok(source.introductionScript.source.element === script2DO,
       "eval frame's introducer belongs to script2 element");

    // The frame that called eval, in turn, should have no introduction
    // information. (In the future, we certainly could point at the call
    // that inserted the script element into the document; if that happens,
    // we can update this test.)
    ok(frame2.script.source.introductionType === 'scriptElement',
       "older frame has no introduction type");
    ok(frame2.script.source.introductionScript === undefined,
       "older frame has no introduction script");
    ok(frame2.script.source.introductionOffset === undefined,
       "older frame has no introduction offset");

    SimpleTest.finish();
  }
}
</script>
</pre>
</body>
</html>