Bug 1527238 - Speed up webconsole server's autocomplete function; r=Honza.

There are 2 changes in this patch.

In js-property-provider, we iterate over a Set
and delete item we don't want into instead of
turning the Set into an array, filter on it, and
convert it back to a new Set.

In the autocomplete function, we don't use regexp
anymore in the sort callback as we already have
a way to tell if we're performing an element access.

Differential Revision: https://phabricator.services.mozilla.com/D19471
This commit is contained in:
Nicolas Chevobbe
2019-02-15 15:02:51 +00:00
parent b6bbbc9582
commit 9ffa4a8b95
2 changed files with 8 additions and 10 deletions

View File

@@ -484,18 +484,16 @@ function JSPropertyProvider({
// If we're not performing an element access, we need to check that the property
// are suited for a dot access. (Reflect.jsm is not available in worker context yet,
// see Bug 1507181).
matches = new Set([...matches].filter(propertyName => {
let valid = true;
for (const match of matches) {
try {
// In order to know if the property is suited for dot notation, we use Reflect
// to parse an expression where we try to access the property with a dot. If it
// throws, this means that we need to do an element access instead.
Reflect.parse(`({${propertyName}: true})`);
Reflect.parse(`({${match}: true})`);
} catch (e) {
valid = false;
matches.delete(match);
}
return valid;
}));
}
}
return {isElementAccess, matchProp, matches};