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
91 lines (77 loc) · 2.55 KB
/
dbg.js
File metadata and controls
91 lines (77 loc) · 2.55 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
/* 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/>. */
// @flow
import * as timings from "./timings";
import { prefs, features } from "./prefs";
import { isDevelopment, isTesting } from "devtools-environment";
import { formatPausePoints } from "./pause/pausePoints";
function findSource(dbg: any, url: string) {
const sources = dbg.selectors.getSources();
const source = sources.find(s => (s.url || "").includes(url));
if (!source) {
return;
}
return source;
}
function sendPacket(dbg: any, packet: any, callback: () => void) {
dbg.client.sendPacket(packet, callback || console.log);
}
function sendPacketToThread(dbg: Object, packet: any, callback: () => void) {
sendPacket(
dbg,
{ to: dbg.connection.tabConnection.threadClient.actor, ...packet },
callback
);
}
function evaluate(dbg: Object, expression: any, callback: () => void) {
dbg.client.evaluate(expression).then(callback || console.log);
}
function bindSelectors(obj: Object): Object {
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: any = document.querySelector(".CodeMirror");
return cm && cm.CodeMirror;
}
function _formatPausePoints(dbg: Object, url: string) {
const source = dbg.helpers.findSource(url);
const pausePoints = dbg.selectors.getPausePoints(source);
console.log(formatPausePoints(source.text, pausePoints));
}
export function setupHelper(obj: Object) {
const selectors = bindSelectors(obj);
const dbg: Object = {
...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)
},
_telemetry: {
events: {}
}
};
window.dbg = dbg;
if (isDevelopment() && !isTesting()) {
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();
}
}