forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.js
More file actions
102 lines (86 loc) · 2.22 KB
/
log.js
File metadata and controls
102 lines (86 loc) · 2.22 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
98
99
100
101
102
/* 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/. */
/* global window */
import { isTesting } from "devtools-config";
const blacklist = [
"SET_POPUP_OBJECT_PROPERTIES",
"SET_PAUSE_POINTS",
"SET_SYMBOLS",
"OUT_OF_SCOPE_LOCATIONS",
"MAP_SCOPES",
"MAP_FRAMES",
"ADD_SCOPES",
"IN_SCOPE_LINES",
"SET_EMPTY_LINES"
];
function cloneAction(action) {
action = action || {};
action = { ...action };
// ADD_TAB, ...
if (action.source && action.source.text) {
const source = { ...action.source, text: "" };
action.source = source;
}
if (action.sources) {
const sources = action.sources.slice(0, 20).map(source => {
const url = !source.url || source.url.includes("data:") ? "" : source.url;
return { ...source, url };
});
action.sources = sources;
}
// LOAD_SOURCE_TEXT
if (action.text) {
action.text = "";
}
if (action.value && action.value.text) {
const value = { ...action.value, text: "" };
action.value = value;
}
return action;
}
function formatFrame(frame) {
const { id, location, displayName } = frame;
return { id, location, displayName };
}
function formatPause(pause) {
return {
...pause,
pauseInfo: { why: pause.why },
scopes: [],
frames: pause.frames.map(formatFrame),
loadedObjects: []
};
}
function serializeAction(action) {
try {
action = cloneAction(action);
if (blacklist.includes(action.type)) {
action = {};
}
if (action.type === "PAUSED") {
action = formatPause(action);
}
// dump(`> ${action.type}...\n ${JSON.stringify(action)}\n`);
return JSON.stringify(action);
} catch (e) {
console.error(e);
}
}
/**
* A middleware that logs all actions coming through the system
* to the console.
*/
export function log({ dispatch, getState }) {
return next => action => {
const asyncMsg = !action.status ? "" : `[${action.status}]`;
if (isTesting()) {
dump(
`[ACTION] ${action.type} ${asyncMsg} - ${serializeAction(action)}\n`
);
} else {
console.log(action, asyncMsg);
}
next(action);
};
}