summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Source-introductionScript-01.js
blob: 29dfeb0c83d7e41bec9b1ee15d285c95a5e6e138 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Dynamically generated sources should have their introduction script and
// offset set correctly.

var g = newGlobal({newCompartment: true});
var dbg = new Debugger;
var gDO = dbg.addDebuggee(g);
var log;

// Direct eval, while the frame is live.
dbg.onDebuggerStatement = function (frame) {
  log += 'd';
  var source = frame.script.source;
  var introducer = frame.older;
  assertEq(source.introductionScript, introducer.script);
  assertEq(source.introductionOffset, introducer.offset);
};
log = '';
g.eval('\n\neval("\\n\\ndebugger;");');
assertEq(log, 'd');

// Direct eval, after the frame has been popped.
var introducer, introduced;
dbg.onDebuggerStatement = function (frame) {
  log += 'de1';
  introducer = frame.script;
  dbg.onDebuggerStatement = function (frame) {
    log += 'de2';
    introduced = frame.script.source;
  };
};
log = '';
g.evaluate('debugger; eval("\\n\\ndebugger;");', { lineNumber: 1812 });
assertEq(log, 'de1de2');
assertEq(introduced.introductionScript, introducer);
assertEq(introducer.getOffsetLocation(introduced.introductionOffset).lineNumber, 1812);

// Indirect eval, while the frame is live.
dbg.onDebuggerStatement = function (frame) {
  log += 'd';
  var source = frame.script.source;
  var introducer = frame.older;
  assertEq(source.introductionScript, introducer.script);
  assertEq(source.introductionOffset, introducer.offset);
};
log = '';
g.eval('\n\n(0,eval)("\\n\\ndebugger;");');
assertEq(log, 'd');

// Indirect eval, after the frame has been popped.
var introducer, introduced;
dbg.onDebuggerStatement = function (frame) {
  log += 'de1';
  introducer = frame.script;
  dbg.onDebuggerStatement = function (frame) {
    log += 'de2';
    introduced = frame.script.source;
  };
};
log = '';
g.evaluate('debugger; (0,eval)("\\n\\ndebugger;");', { lineNumber: 1066 });
assertEq(log, 'de1de2');
assertEq(introduced.introductionScript, introducer);
assertEq(introducer.getOffsetLocation(introduced.introductionOffset).lineNumber, 1066);

// Function constructor.
dbg.onDebuggerStatement = function (frame) {
  log += 'o';
  var outerScript = frame.script;
  var outerOffset = frame.offset;
  dbg.onDebuggerStatement = function (frame) {
    log += 'i';
    var source = frame.script.source;
    assertEq(source.introductionScript, outerScript);
    assertEq(outerScript.getOffsetLocation(source.introductionOffset).lineNumber,
             outerScript.getOffsetLocation(outerOffset).lineNumber);
  };
};
log = '';
g.eval('\n\n\ndebugger; Function("debugger;")()');
assertEq(log, 'oi');

// Function constructor, after the the introduction call's frame has been
// popped.
var introducer;
dbg.onDebuggerStatement = function (frame) {
  log += 'F2';
  introducer = frame.script;
};
log = '';
var fDO = gDO.executeInGlobal('debugger; Function("origami;")', { lineNumber: 1685 }).return;
var source = fDO.script.source;
assertEq(log, 'F2');
assertEq(source.introductionScript, introducer);
assertEq(introducer.getOffsetLocation(source.introductionOffset).lineNumber, 1685);

// If the introduction script is in a different global from the script it
// introduced, we don't record it.
dbg.onDebuggerStatement = function (frame) {
  log += 'x';
  var source = frame.script.source;
  assertEq(source.introductionScript, undefined);
  assertEq(source.introductionOffset, undefined);
};
log = '';
g.eval('debugger;'); // introduction script is this top-level script
assertEq(log, 'x');

// If the code is introduced by a function that doesn't provide
// introduction information, that shouldn't be a problem.
dbg.onDebuggerStatement = function (frame) {
  log += 'x';
  var source = frame.script.source;
  assertEq(source.introductionScript, undefined);
  assertEq(source.introductionOffset, undefined);
};
log = '';
g.eval('evaluate("debugger;", { lineNumber: 1729 });');
assertEq(log, 'x');