Skip to content

Commit

Permalink
[Scopes] expanded properties are not updated while stepping (firefox-…
Browse files Browse the repository at this point in the history
…devtools#2509)

* Fix expanded properties are not updated while stepping

* Revert yarn.lock

* Move code logic to ObjectInspector

* Made a few corrections

* Retrieve property values

* Remove code from previous commit

* Revert to previous implementation

* Revert yarn.lock

* Move code logic to object-inspector and add a unit test

* Simplify code
  • Loading branch information
arthur801031 authored and DanUgelow committed May 4, 2017
1 parent 5c3496b commit 768ad01
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/utils/object-inspector.js
Expand Up @@ -181,6 +181,10 @@ function getChildren(
// node would be a new instance every render.
const key = item.path;
if (actors && actors[key]) {
if (item.contents.value && item.contents.value.preview) {
actors[key] = updateActor(item, actors, key);
}

return actors[key];
}

Expand All @@ -203,6 +207,21 @@ function getChildren(
return children;
}

function updateActor(item, actors, key) {
const properties = item.contents.value.preview.ownProperties;
for (let pKey in properties) {
if (properties.hasOwnProperty(pKey)) {
const cacheObject = actors[key].filter(a => a.name == pKey)[0];
const cacheObjectIndex = actors[key].findIndex(a => a.name == pKey);
// Assign new values to the cache actor if it goes stale
if (cacheObject && cacheObject.contents.value != properties[pKey].value) {
actors[key][cacheObjectIndex].contents = properties[pKey];
}
}
}
return actors[key];
}

module.exports = {
nodeHasChildren,
nodeIsOptimizedOut,
Expand Down
36 changes: 35 additions & 1 deletion src/utils/tests/object-inspector.js
Expand Up @@ -3,7 +3,8 @@ const expect = require("expect.js");
const {
makeNodesForProperties,
isPromise,
getPromiseProperties
getPromiseProperties,
getChildren
} = require("../object-inspector");

const objProperties = {
Expand Down Expand Up @@ -221,4 +222,37 @@ describe("promises", () => {
const node = getPromiseProperties(promise);
expect(node.contents.value.type).to.eql("3");
});

it("update actors when necessary", () => {
const item = {
contents: {
value: {
preview: {
ownProperties: {
color: {
value: "red"
}
}
},
type: "object"
}
},
name: "car",
path: "Block/car"
};

let actors = new Object();
actors["Block/car"] = [
{
contents: {
value: "white"
},
name: "color",
path: "Block/car/color"
}
];

const children = getChildren({ function() {}, actors, item });
expect(children[0].contents.value).to.eql("red");
});
});

0 comments on commit 768ad01

Please sign in to comment.