Skip to content

Commit 4dcf905

Browse files
authored
Fix default bucketing (firefox-devtools#2897)
* Fix default bucketing * tidy up * tweaks
1 parent ea8b5f3 commit 4dcf905

8 files changed

Lines changed: 790 additions & 44 deletions

File tree

assets/module-manifest.json

Lines changed: 636 additions & 2 deletions
Large diffs are not rendered by default.

src/components/shared/ObjectInspector.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ export type ObjectInspectorItemContentsValue = {
3333
type: string
3434
};
3535

36-
type ObjectInspectorItemContents = {
36+
export type ObjectInspectorItemContents = {
3737
value: ObjectInspectorItemContentsValue
3838
};
3939

40-
type ObjectInspectorItem = {
40+
export type ObjectInspectorItem = {
4141
contents: Array<ObjectInspectorItem> & ObjectInspectorItemContents,
4242
name: string,
4343
path: string

src/components/stories/Preview.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,57 @@ import "../App.css";
1010
import "../SecondaryPanes/Frames/Frames.css";
1111
import "devtools-launchpad/src/lib/themes/dark-theme.css";
1212

13+
function createArrayPreview(name) {
14+
return {
15+
enumerable: true,
16+
writerable: true,
17+
configurable: true,
18+
value: {
19+
type: "object",
20+
actor: `server2.conn45.child1/${name}`,
21+
class: "Object",
22+
ownPropertyLength: 2,
23+
preview: {
24+
kind: "ArrayLike",
25+
ownProperties: {},
26+
ownPropertiesLength: 0,
27+
length: 1
28+
}
29+
}
30+
};
31+
}
32+
33+
function createObjectPreview(name) {
34+
return {
35+
enumerable: true,
36+
writerable: true,
37+
configurable: true,
38+
value: {
39+
type: "Object",
40+
actor: `server2.conn45.child1/${name}`,
41+
class: "Object",
42+
ownPropertyLength: 2,
43+
preview: {
44+
kind: "object",
45+
ownProperties: {},
46+
ownPropertiesLength: 0,
47+
length: 1
48+
}
49+
}
50+
};
51+
}
52+
53+
function createObjectGrip(id) {
54+
return {
55+
actor: `server2.conn45.child1/${id}`,
56+
type: "object",
57+
class: "Object",
58+
ownProperties: {},
59+
ownSymbols: {},
60+
safeGetters: {}
61+
};
62+
}
63+
1364
const obj = {
1465
actor: "server2.conn45.child1/pausedobj81",
1566
type: "object",
@@ -141,5 +192,32 @@ options.forEach(option => {
141192
},
142193
option
143194
);
195+
})
196+
.add(`Object with window keys ${optionLabel}`, () => {
197+
let grip = createObjectGrip("foo");
198+
grip.ownProperties.arr = createArrayPreview("arr");
199+
grip.ownProperties.location = createObjectPreview("location");
200+
return PreviewFactory(
201+
{
202+
value: grip,
203+
expression: "this",
204+
loadedObjects: I.Map().set(grip.actor, grip)
205+
},
206+
option
207+
);
208+
})
209+
.add(`Window Preview ${optionLabel}`, () => {
210+
let grip = createObjectGrip("foo");
211+
grip.class = "Window";
212+
grip.ownProperties.arr = createArrayPreview("arr");
213+
grip.ownProperties.location = createObjectPreview("location");
214+
return PreviewFactory(
215+
{
216+
value: grip,
217+
expression: "this",
218+
loadedObjects: I.Map().set(grip.actor, grip)
219+
},
220+
option
221+
);
144222
});
145223
});

src/test/integration/tests/scopes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ async function expandingProperties(ctx) {
4141

4242
toggleNode(dbg, 4);
4343
await waitForDispatch(dbg, "LOAD_OBJECT_PROPERTIES");
44-
is(getLabel(dbg, 5), "prototype");
44+
is(getLabel(dbg, 5), "length");
4545

4646
await stepOver(dbg);
4747
is(getLabel(dbg, 4), "foo()");
48-
is(getLabel(dbg, 5), "prototype");
48+
is(getLabel(dbg, 5), "Window");
4949
}
5050

5151
async function changingScopes(ctx) {

src/test/mochitest/browser_dbg-scopes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_task(function*() {
2323

2424
toggleNode(dbg, 4);
2525
yield waitForDispatch(dbg, "LOAD_OBJECT_PROPERTIES");
26-
is(getLabel(dbg, 5), "prototype");
26+
is(getLabel(dbg, 5), "length");
2727

2828
yield stepOver(dbg);
2929
is(getLabel(dbg, 4), "foo()");

src/utils/object-inspector.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,7 @@ function makeDefaultPropsBucket(props, parentPath, ownProperties) {
111111
const userProps = props.filter(name => !isDefault({ name }));
112112
const defaultProps = props.filter(name => isDefault({ name }));
113113

114-
let nodes = userProps.map(name =>
115-
createNode(
116-
maybeEscapePropertyName(name),
117-
`${parentPath}/${name}`,
118-
ownProperties[name]
119-
)
120-
);
114+
let nodes = makeNodesForOwnProps(userProps, parentPath, ownProperties);
121115

122116
if (defaultProps.length > 0) {
123117
const defaultNodes = defaultProps.map((name, index) =>
@@ -128,24 +122,34 @@ function makeDefaultPropsBucket(props, parentPath, ownProperties) {
128122
)
129123
);
130124
nodes.push(
131-
createNode("[default properties]", `${parentPath}/default`, defaultNodes)
125+
createNode(
126+
"[default properties]",
127+
`${parentPath}/##-default`,
128+
defaultNodes
129+
)
132130
);
133131
}
134132
return nodes;
135133
}
136134

137-
/*
135+
function makeNodesForOwnProps(properties, parentPath, ownProperties) {
136+
return properties.map(name =>
137+
createNode(
138+
maybeEscapePropertyName(name),
139+
`${parentPath}/${name}`,
140+
ownProperties[name]
141+
)
142+
);
143+
}
138144

145+
/*
139146
* Ignore non-concrete values like getters and setters
140147
* for now by making sure we have a value.
141148
*/
142-
function makeNodesForProperties(
143-
objProps,
144-
parentPath,
145-
{ bucketSize = 100 } = {}
146-
) {
149+
function makeNodesForProperties(objProps, parent, { bucketSize = 100 } = {}) {
147150
const { ownProperties, prototype, ownSymbols } = objProps;
148-
151+
const parentPath = parent.path;
152+
const parentValue = parent.contents.value;
149153
const properties = sortProperties(Object.keys(ownProperties)).filter(name =>
150154
ownProperties[name].hasOwnProperty("value")
151155
);
@@ -160,8 +164,10 @@ function makeNodesForProperties(
160164
parentPath,
161165
ownProperties
162166
);
163-
} else {
167+
} else if (parentValue.class == "Window") {
164168
nodes = makeDefaultPropsBucket(properties, parentPath, ownProperties);
169+
} else {
170+
nodes = makeNodesForOwnProps(properties, parentPath, ownProperties);
165171
}
166172

167173
for (let index in ownSymbols) {
@@ -230,7 +236,7 @@ function getChildren({ getObjectProperties, actors, item }) {
230236
return [];
231237
}
232238

233-
let children = makeNodesForProperties(loadedProps, item.path);
239+
let children = makeNodesForProperties(loadedProps, item);
234240
if (isPromise(item)) {
235241
children.unshift(getPromiseProperties(item));
236242
}

src/utils/tests/object-inspector.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const {
66
getPromiseProperties
77
} = require("../object-inspector");
88

9+
const root = {
10+
path: "root",
11+
contents: { value: {} }
12+
};
13+
914
const objProperties = {
1015
ownProperties: {
1116
"0": {
@@ -26,13 +31,14 @@ const objProperties = {
2631
describe("object-inspector", () => {
2732
describe("makeNodesForProperties", () => {
2833
it("kitchen sink", () => {
29-
const nodes = makeNodesForProperties(objProperties, "root");
34+
// console.log(this.root);
35+
const nodes = makeNodesForProperties(objProperties, root);
3036

3137
const names = nodes.map(n => n.name);
32-
expect(names).to.eql(["0", "[default properties]", "__proto__"]);
38+
expect(names).to.eql(["0", "length", "__proto__"]);
3339

3440
const paths = nodes.map(n => n.path);
35-
expect(paths).to.eql(["root/0", "root/default", "root/__proto__"]);
41+
expect(paths).to.eql(["root/0", "root/length", "root/__proto__"]);
3642
});
3743

3844
it("excludes getters", () => {
@@ -46,7 +52,7 @@ describe("object-inspector", () => {
4652
class: "bla"
4753
}
4854
},
49-
"root"
55+
root
5056
);
5157

5258
const names = nodes.map(n => n.name);
@@ -70,7 +76,7 @@ describe("object-inspector", () => {
7076
class: "bla"
7177
}
7278
},
73-
"root"
79+
root
7480
);
7581

7682
const names = nodes.map(n => n.name);
@@ -95,7 +101,7 @@ describe("object-inspector", () => {
95101
},
96102
prototype: { value: {}, class: "bla" }
97103
},
98-
"root"
104+
root
99105
);
100106

101107
const names = nodes.map(n => n.name);
@@ -105,13 +111,35 @@ describe("object-inspector", () => {
105111
expect(paths).to.eql(["root/bar", "root/__proto__"]);
106112
});
107113

114+
it("window object", () => {
115+
const nodes = makeNodesForProperties(
116+
{
117+
ownProperties: {
118+
bar: { value: {} },
119+
location: { value: {} }
120+
},
121+
class: "Window"
122+
},
123+
{
124+
path: "root",
125+
contents: { value: { class: "Window" } }
126+
}
127+
);
128+
129+
const names = nodes.map(n => n.name);
130+
const paths = nodes.map(n => n.path);
131+
132+
expect(names).to.eql(["bar", "[default properties]"]);
133+
expect(paths).to.eql(["root/bar", "root/##-default"]);
134+
});
135+
108136
// For large arrays
109137
it("numerical buckets", () => {
110138
let objProps = { ownProperties: {}, prototype: { class: "Array" } };
111139
for (let i = 0; i < 331; i++) {
112140
objProps.ownProperties[i] = { value: {} };
113141
}
114-
const nodes = makeNodesForProperties(objProps, "root");
142+
const nodes = makeNodesForProperties(objProps, root);
115143

116144
const names = nodes.map(n => n.name);
117145
const paths = nodes.map(n => n.path);
@@ -147,7 +175,7 @@ describe("object-inspector", () => {
147175
class: "WindowPrototype"
148176
}
149177
},
150-
"root"
178+
root
151179
);
152180

153181
const names = nodes.map(n => n.name);

yarn.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,8 +1444,8 @@ balanced-match@^0.4.0, balanced-match@^0.4.1, balanced-match@^0.4.2:
14441444
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838"
14451445

14461446
base62@^1.1.0:
1447-
version "1.1.2"
1448-
resolved "https://registry.yarnpkg.com/base62/-/base62-1.1.2.tgz#22ced6a49913565bc0b8d9a11563a465c084124c"
1447+
version "1.2.0"
1448+
resolved "https://registry.yarnpkg.com/base62/-/base62-1.2.0.tgz#31e7e560dc846c9f44c1a531df6514da35474157"
14491449

14501450
base64-js@^1.0.2, base64-js@^1.1.2:
14511451
version "1.2.0"
@@ -1660,8 +1660,8 @@ caniuse-api@^1.5.2:
16601660
lodash.uniq "^4.5.0"
16611661

16621662
caniuse-db@^1.0.30000187, caniuse-db@^1.0.30000529, caniuse-db@^1.0.30000634, caniuse-db@^1.0.30000639:
1663-
version "1.0.30000667"
1664-
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000667.tgz#fb6060dbf349c101df26f421442419802fc6dab1"
1663+
version "1.0.30000670"
1664+
resolved "https://registry.yarnpkg.com/caniuse-db/-/caniuse-db-1.0.30000670.tgz#90d33b79e3090e25829c311113c56d6b1788bf43"
16651665

16661666
capture-stack-trace@^1.0.0:
16671667
version "1.0.0"
@@ -2864,8 +2864,8 @@ es-to-primitive@^1.1.1:
28642864
is-symbol "^1.0.1"
28652865

28662866
es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14:
2867-
version "0.10.16"
2868-
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.16.tgz#1ef1b04f3d09db6a5d630226d62202f2e425e45a"
2867+
version "0.10.18"
2868+
resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.18.tgz#dc239d3dce4c22b9c939aa180878837a3c0b5c92"
28692869
dependencies:
28702870
es6-iterator "2"
28712871
es6-symbol "~3.1"
@@ -2966,8 +2966,8 @@ eslint-plugin-babel@^3.3.0:
29662966
resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-3.3.0.tgz#2f494aedcf6f4aa4e75b9155980837bc1fbde193"
29672967

29682968
eslint-plugin-flowtype@^2.20.0:
2969-
version "2.32.1"
2970-
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.32.1.tgz#bbee185dedf97e5f63ec975cdcddd199bd2a2501"
2969+
version "2.33.0"
2970+
resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.33.0.tgz#b2783814ed2ddcf729953b8f65ff73c90cabee4b"
29712971
dependencies:
29722972
lodash "^4.15.0"
29732973

@@ -4971,8 +4971,8 @@ jsprim@^1.2.2:
49714971
verror "1.3.6"
49724972

49734973
jssha@^2.1.0:
4974-
version "2.2.0"
4975-
resolved "https://registry.yarnpkg.com/jssha/-/jssha-2.2.0.tgz#87dcf60821dc3bec593f3855bbebccd276aacc1c"
4974+
version "2.3.0"
4975+
resolved "https://registry.yarnpkg.com/jssha/-/jssha-2.3.0.tgz#bb375f545c59f3ffda7c1e80fd0b3c0867586ab8"
49764976

49774977
jstransform@^11.0.3:
49784978
version "11.0.3"
@@ -5591,8 +5591,8 @@ mobx@^2.3.4:
55915591
resolved "https://registry.yarnpkg.com/mobx/-/mobx-2.7.0.tgz#cf3d82d18c0ca7f458d8f2a240817b3dc7e54a01"
55925592

55935593
mocha@^3.1.2:
5594-
version "3.3.0"
5595-
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.3.0.tgz#d29b7428d3f52c82e2e65df1ecb7064e1aabbfb5"
5594+
version "3.4.1"
5595+
resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.4.1.tgz#a3802b4aa381934cacb38de70cf771621da8f9af"
55965596
dependencies:
55975597
browser-stdout "1.3.0"
55985598
commander "2.9.0"

0 commit comments

Comments
 (0)