Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 89 lines (86 sloc) 3.618 kb
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
1 # HG changeset patch
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
2 # Parent 3281298476f0806b3d316075c30330414f2b0861
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
3 # User Thaddee Tyl <thaddee.tyl@gmail.com>
82ed03ad »
2012-08-04 WebConsole index completion: added patch message.
4 Bug 776106 — Autocompletion on arrays include numbers
cdf95523 »
2012-08-04 WebConsole index completion: removed `dump()`.
5
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
6 diff --git a/browser/devtools/webconsole/WebConsoleUtils.jsm b/browser/devtools/webconsole/WebConsoleUtils.jsm
7 --- a/browser/devtools/webconsole/WebConsoleUtils.jsm
8 +++ b/browser/devtools/webconsole/WebConsoleUtils.jsm
cdf95523 »
2012-08-04 WebConsole index completion: removed `dump()`.
9 @@ -953,7 +953,7 @@ function JSPropertyProvider(aScope, aInp
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
10 return null;
11 }
12
13 - let matches = Object.keys(getMatchedProps(obj, matchProp));
14 + let matches = Object.keys(getMatchedProps(obj, {matchProp:matchProp}));
15
16 return {
17 matchProp: matchProp,
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
18 @@ -969,15 +969,25 @@ function JSPropertyProvider(aScope, aInp
19 * @param mixed aObj
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
20 * JS value whose properties we want to collect.
21 *
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
22 - * @param string aMatchProp
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
23 - * Filter for properties that match this one.
24 - * Defaults to the empty string (which always matches).
25 + * @param object aOptions
26 + * Options that the algorithm takes.
27 + * - matchProp (string): Filter for properties that match this one.
28 + * Defaults to the empty string (which always matches).
29 + * - completeAfter (string): Character after which we are getting the
30 + * properties. Should be either "." or "[". Chooses how the properties
31 + * should look: "." gives the string directly, and doesn't give number
32 + * indices, whereas "[" surrounds the properties with '"' and gives
33 + * number indices.
34 *
35 * @return object
36 * Object whose keys are all accessible properties on the object.
37 */
38 -function getMatchedProps(aObj, aMatchProp = "")
39 +function getMatchedProps(aObj, aOptions = {matchProp: "", completeAfter: "."})
40 {
41 + // Argument defaults.
42 + aOptions.matchProp = aOptions.matchProp || "";
43 + aOptions.completeAfter = aOptions.completeAfter || ".";
44 +
45 if (aObj == null) { return {}; }
46 try {
47 Object.getPrototypeOf(aObj);
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
48 @@ -988,13 +998,30 @@ function getMatchedProps(aObj, aMatchPro
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
49 let names = {}; // Using an Object to avoid duplicates.
50 let ownNames = Object.getOwnPropertyNames(aObj);
51 for (let i = 0; i < ownNames.length; i++) {
52 - if (ownNames[i].indexOf(aMatchProp) == 0) {
53 + // Filtering happens here.
54 + if (ownNames[i].indexOf(aOptions.matchProp) == 0) {
55 + // If we already have it in, no need to append it.
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
56 if (names[ownNames[i]] != true) {
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
57 c--;
58 if (c < 0) {
59 return names;
60 }
61 - names[ownNames[i]] = true;
62 + if (aOptions.completeAfter[0] == ".") {
63 + // If it is an array index, we can't take it.
64 + // This uses a trick: converting a string to a number yields NaN if
65 + // the operation failed, and NaN is not equal to itself.
66 + if (+ownNames[i] != +ownNames[i]) {
67 + names[ownNames[i]] = true;
68 + }
69 + } else if (aOptions.completeAfter[0] == "[") {
70 + // See above for the following trick.
71 + if (+ownNames[i] != +ownNames[i]) {
72 + names['"' + ownNames[i] + '"'] = true;
73 + } else {
74 + // The property is a number index.
75 + names[ownNames[i]] = true;
76 + }
77 + }
78 }
79 }
80 }
34289f65 »
2012-08-06 Merged all current webconsole patches to nonobject
81 @@ -1002,7 +1029,7 @@ function getMatchedProps(aObj, aMatchPro
b1b4ace8 »
2012-08-04 WebConsole completion shouldn't show array indices
82 // We need to recursively go up the prototype chain.
83 aObj = Object.getPrototypeOf(aObj);
84 if (aObj !== null) {
85 - let parentScope = getMatchedProps(aObj, aMatchProp);
86 + let parentScope = getMatchedProps(aObj, aOptions);
87 for (let name in parentScope) {
88 if (names[name] != true) {
89 c--;
Something went wrong with that request. Please try again.