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
|
/* 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/>. */
const {
getValue,
nodeHasFullText,
} = require("resource://devtools/client/shared/components/object-inspector/utils/node.js");
async function enumIndexedProperties(objectFront, start, end) {
try {
const iterator = await objectFront.enumProperties({
ignoreNonIndexedProperties: true,
});
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumIndexedProperties", e);
return {};
}
}
async function enumNonIndexedProperties(objectFront, start, end) {
try {
const iterator = await objectFront.enumProperties({
ignoreIndexedProperties: true,
});
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumNonIndexedProperties", e);
return {};
}
}
async function enumEntries(objectFront, start, end) {
try {
const iterator = await objectFront.enumEntries();
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumEntries", e);
return {};
}
}
async function enumSymbols(objectFront, start, end) {
try {
const iterator = await objectFront.enumSymbols();
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumSymbols", e);
return {};
}
}
async function enumPrivateProperties(objectFront, start, end) {
try {
const iterator = await objectFront.enumPrivateProperties();
const response = await iteratorSlice(iterator, start, end);
return response;
} catch (e) {
console.error("Error in enumPrivateProperties", e);
return {};
}
}
async function getPrototype(objectFront) {
if (typeof objectFront.getPrototype !== "function") {
console.error("objectFront.getPrototype is not a function");
return Promise.resolve({});
}
return objectFront.getPrototype();
}
async function getFullText(longStringFront, item) {
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 { fullText };
}
try {
const substring = await longStringFront.substring(initial.length, length);
return {
fullText: initial + substring,
};
} catch (e) {
console.error("LongStringFront.substring", e);
throw e;
}
}
async function getPromiseState(objectFront) {
return objectFront.getPromiseState();
}
async function getProxySlots(objectFront) {
return objectFront.getProxySlots();
}
function iteratorSlice(iterator, start, end) {
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,
enumPrivateProperties,
enumSymbols,
getPrototype,
getFullText,
getPromiseState,
getProxySlots,
};
|