Skip to content
This repository was archived by the owner on Sep 21, 2021. It is now read-only.

Commit 6483ac5

Browse files
committed
Fix make node for properties
1 parent 634bea8 commit 6483ac5

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

packages/devtools-reps/src/object-inspector/tests/utils/make-node-for-properties.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,25 @@ describe("makeNodesForProperties", () => {
8484
expect(paths).toEqual(["root/bar", "root/baz", "root/foo", "root/__proto__"]);
8585
});
8686

87+
it("does not include unrelevant properties", () => {
88+
const nodes = makeNodesForProperties(
89+
{
90+
ownProperties: {
91+
foo: undefined,
92+
bar: null,
93+
baz: {}
94+
},
95+
},
96+
root
97+
);
98+
99+
const names = nodes.map(n => n.name);
100+
const paths = nodes.map(n => n.path);
101+
102+
expect(names).toEqual([]);
103+
expect(paths).toEqual([]);
104+
});
105+
87106
it("sorts keys", () => {
88107
const nodes = makeNodesForProperties(
89108
{

packages/devtools-reps/src/object-inspector/utils/node.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,15 @@ function makeNodesForProperties(
506506
let allProperties = Object.assign({}, ownProperties, safeGetterValues);
507507

508508
// Ignore properties that are neither non-concrete nor getters/setters.
509-
const propertiesNames = sortProperties(Object.keys(allProperties)).filter(name =>
510-
allProperties[name].hasOwnProperty("value")
511-
|| allProperties[name].hasOwnProperty("getterValue")
512-
|| allProperties[name].hasOwnProperty("get")
513-
|| allProperties[name].hasOwnProperty("set")
514-
);
509+
const propertiesNames = sortProperties(Object.keys(allProperties)).filter(name => {
510+
if (!allProperties[name]) {
511+
return false;
512+
}
513+
514+
const properties = Object.getOwnPropertyNames(allProperties[name]);
515+
return properties
516+
.some(property => ["value", "getterValue", "get", "set"].includes(property));
517+
});
515518

516519
let nodes = [];
517520
if (parentValue && parentValue.class == "Window") {

0 commit comments

Comments
 (0)