forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreadClient.js
More file actions
97 lines (85 loc) · 2.64 KB
/
Copy paththreadClient.js
File metadata and controls
97 lines (85 loc) · 2.64 KB
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { makeLocationId } from "../../../utils/breakpoint";
function createSource(name) {
name = name.replace(/\..*$/, "");
return {
source: `function ${name}() {\n return ${name} \n}`,
contentType: "text/javascript"
};
}
const sources = [
"a",
"b",
"foo",
"bar",
"foo1",
"foo2",
"a.js",
"baz.js",
"foobar.js",
"barfoo.js",
"foo.js",
"bar.js",
"base.js",
"bazz.js",
"jquery.js"
];
export const simpleMockThreadClient = {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, _condition) =>
Promise.resolve({ id: "hi", actualLocation: location }),
removeBreakpoint: _id => Promise.resolve(),
setBreakpointCondition: (_id, _location, _condition, _noSliding) =>
Promise.resolve({ sourceId: "a", line: 5 }),
setPausePoints: () => Promise.resolve({}),
sourceContents: sourceId =>
new Promise((resolve, reject) => {
if (sources.includes(sourceId)) {
resolve(createSource(sourceId));
}
reject(`unknown source: ${sourceId}`);
})
};
// Breakpoint Sliding
function generateCorrectingThreadClient(offset = 0) {
return {
getBreakpointByLocation: jest.fn(),
setBreakpoint: (location, condition) => {
const actualLocation = { ...location, line: location.line + offset };
return Promise.resolve({
id: makeLocationId(location),
actualLocation,
condition
});
},
sourceContents: sourceId => Promise.resolve(createSource(sourceId))
};
}
/* in some cases, a breakpoint may be added, but the source will respond
* with a different breakpoint location. This is due to the breakpoint being
* added between functions, or somewhere that doesnt make sense. This function
* simulates that behavior.
* */
export function simulateCorrectThreadClient(offset, location) {
const correctedThreadClient = generateCorrectingThreadClient(offset);
const offsetLine = { line: location.line + offset };
const correctedLocation = { ...location, ...offsetLine };
return { correctedThreadClient, correctedLocation };
}
// sources and tabs
export const sourceThreadClient = {
sourceContents: function(sourceId) {
return new Promise((resolve, reject) => {
if (sources.includes(sourceId)) {
resolve(createSource(sourceId));
}
reject(`unknown source: ${sourceId}`);
});
},
threadClient: async () => {},
getFrameScopes: async () => {},
setPausePoints: async () => {},
evaluateExpressions: async () => {}
};