forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
148 lines (133 loc) · 3.59 KB
/
Copy pathclient.js
File metadata and controls
148 lines (133 loc) · 3.59 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* 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 type {
GripProperties,
ObjectClient,
PropertiesIterator,
Node,
LongStringClient
} from "../types";
const { getValue, nodeHasFullText } = require("../utils/node");
async function enumIndexedProperties(
objectClient: ObjectClient,
start: ?number,
end: ?number
): Promise<{ ownProperties?: Object }> {
try {
const { iterator } = await objectClient.enumProperties({
ignoreNonIndexedProperties: true
});
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumIndexedProperties", e);
return {};
}
}
async function enumNonIndexedProperties(
objectClient: ObjectClient,
start: ?number,
end: ?number
): Promise<{ ownProperties?: Object }> {
try {
const { iterator } = await objectClient.enumProperties({
ignoreIndexedProperties: true
});
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumNonIndexedProperties", e);
return {};
}
}
async function enumEntries(
objectClient: ObjectClient,
start: ?number,
end: ?number
): Promise<{ ownProperties?: Object }> {
try {
const { iterator } = await objectClient.enumEntries();
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumEntries", e);
return {};
}
}
async function enumSymbols(
objectClient: ObjectClient,
start: ?number,
end: ?number
): Promise<{ ownSymbols?: Array<Object> }> {
try {
const { iterator } = await objectClient.enumSymbols();
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumSymbols", e);
return {};
}
}
async function getPrototype(
objectClient: ObjectClient
): ?Promise<{ prototype?: Object }> {
if (typeof objectClient.getPrototype !== "function") {
console.error("objectClient.getPrototype is not a function");
return Promise.resolve({});
}
return objectClient.getPrototype();
}
async function getFullText(
longStringClient: LongStringClient,
item: Node
): Promise<{ fullText?: string }> {
const { initial, fullText, length } = getValue(item);
// Return fullText property if it exists so that it can be added to the
// loadedProperties map.
if (nodeHasFullText(item)) {
return Promise.resolve({ fullText });
}
return new Promise((resolve, reject) => {
longStringClient.substring(initial.length, length, response => {
if (response.error) {
console.error(
"LongStringClient.substring",
`${response.error}: ${response.message}`
);
reject({});
return;
}
resolve({
fullText: initial + response.substring
});
});
});
}
async function getProxySlots(
objectClient: ObjectClient
): Promise<{ proxyTarget?: Object, proxyHandler?: Object }> {
return objectClient.getProxySlots();
}
function iteratorSlice(
iterator: PropertiesIterator,
start: ?number,
end: ?number
): Promise<GripProperties> {
start = start || 0;
const count = end ? end - start + 1 : iterator.count;
if (count === 0) {
return Promise.resolve({});
}
return iterator.slice(start, count);
}
module.exports = {
enumEntries,
enumIndexedProperties,
enumNonIndexedProperties,
enumSymbols,
getPrototype,
getFullText,
getProxySlots
};