forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbg.js
More file actions
82 lines (70 loc) · 2.15 KB
/
dbg.js
File metadata and controls
82 lines (70 loc) · 2.15 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
import * as timings from "./timings";
import { prefs, features } from "./prefs";
import { isDevelopment } from "devtools-config";
import { formatPausePoints } from "./pause/pausePoints";
function findSource(dbg, url) {
const sources = dbg.selectors.getSources();
const source = sources.find(s => (s.get("url") || "").includes(url));
if (!source) {
return;
}
return source.toJS();
}
function sendPacket(dbg, packet, callback) {
dbg.client.sendPacket(packet, callback || console.log);
}
function sendPacketToThread(dbg, packet, callback) {
sendPacket(
dbg,
{ to: dbg.connection.tabConnection.threadClient.actor, ...packet },
callback
);
}
function evaluate(dbg, expression, callback) {
dbg.client.evaluate(expression).then(callback || console.log);
}
function bindSelectors(obj) {
return Object.keys(obj.selectors).reduce((bound, selector) => {
bound[selector] = (a, b, c) =>
obj.selectors[selector](obj.store.getState(), a, b, c);
return bound;
}, {});
}
function getCM() {
const cm = document.querySelector(".CodeMirror");
return cm && cm.CodeMirror;
}
function _formatPausePoints(dbg, url) {
const source = dbg.helpers.findSource(url);
const pausePoints = dbg.selectors.getPausePoints(source);
console.log(formatPausePoints(source.text, pausePoints));
}
export function setupHelper(obj) {
const selectors = bindSelectors(obj);
const dbg = {
...obj,
selectors,
prefs,
features,
timings,
getCM,
helpers: {
findSource: url => findSource(dbg, url),
evaluate: (expression, cbk) => evaluate(dbg, expression, cbk),
sendPacketToThread: (packet, cbk) => sendPacketToThread(dbg, packet, cbk),
sendPacket: (packet, cbk) => sendPacket(dbg, packet, cbk)
},
formatters: {
pausePoints: url => _formatPausePoints(dbg, url)
}
};
window.dbg = dbg;
if (isDevelopment()) {
console.group("Development Notes");
const baseUrl = "https://devtools-html.github.io/debugger.html";
const localDevelopmentUrl = `${baseUrl}/docs/dbg.html`;
console.log("Debugging Tips", localDevelopmentUrl);
console.log("dbg", window.dbg);
console.groupEnd();
}
}