Bug 1559717 - Fix displaying getter value for getter returning falsy values. r=davidwalsh.

We were displaying result.value.throw if result.value.return
was falsy. But it can happen that a getter does return a
falsy value, and we want to display it.
So now we turn the expression the other way around, we first
check result.value.throw, and then default to result.value.return.
A mochitest is added to ensure we hav expected value for different
getters returning falsy values.

Differential Revision: https://phabricator.services.mozilla.com/D39136

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nicolas Chevobbe 2019-07-25 13:55:14 +00:00
parent 6112863ed7
commit 14505fb3ac
3 changed files with 138 additions and 2 deletions

View File

@ -58,7 +58,7 @@ function reducer(
getterValue:
data.result &&
data.result.value &&
(data.result.value.return || data.result.value.throw),
(data.result.value.throw || data.result.value.return),
}),
});
}

View File

@ -2352,7 +2352,7 @@ function reducer(state = initialState(), action = {}) {
return cloneState({
actors: data.actor ? new Set(state.actors || []).add(data.result.from) : state.actors,
evaluations: new Map(state.evaluations).set(data.node.path, {
getterValue: data.result && data.result.value && (data.result.value.return || data.result.value.throw)
getterValue: data.result && data.result.value && (data.result.value.throw || data.result.value.return)
})
});
}

View File

@ -35,6 +35,18 @@ add_task(async function() {
get myNullGetter() {
return null;
},
get myZeroGetter() {
return 0;
},
get myEmptyStringGetter() {
return "";
},
get myFalseGetter() {
return false;
},
get myTrueGetter() {
return true;
},
get myObjectGetter() {
return { foo: "bar" };
},
@ -73,6 +85,10 @@ add_task(async function() {
await testNumberGetter(oi);
await testUndefinedGetter(oi);
await testNullGetter(oi);
await testZeroGetter(oi);
await testEmptyStringGetter(oi);
await testFalseGetter(oi);
await testTrueGetter(oi);
await testObjectGetter(oi);
await testArrayGetter(oi);
await testMapGetter(oi);
@ -201,6 +217,126 @@ async function testNullGetter(oi) {
);
}
async function testZeroGetter(oi) {
let node = findObjectInspectorNode(oi, "myZeroGetter");
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
const invokeButton = getObjectInspectorInvokeGetterButton(node);
ok(invokeButton, "There is an invoke button as expected");
invokeButton.click();
await waitFor(
() =>
!getObjectInspectorInvokeGetterButton(
findObjectInspectorNode(oi, "myZeroGetter")
)
);
node = findObjectInspectorNode(oi, "myZeroGetter");
ok(
node.textContent.includes(`myZeroGetter: 0`),
"0 getter now has the expected text content"
);
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
}
async function testEmptyStringGetter(oi) {
let node = findObjectInspectorNode(oi, "myEmptyStringGetter");
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
const invokeButton = getObjectInspectorInvokeGetterButton(node);
ok(invokeButton, "There is an invoke button as expected");
invokeButton.click();
await waitFor(
() =>
!getObjectInspectorInvokeGetterButton(
findObjectInspectorNode(oi, "myEmptyStringGetter")
)
);
node = findObjectInspectorNode(oi, "myEmptyStringGetter");
ok(
node.textContent.includes(`myEmptyStringGetter: ""`),
"empty string getter now has the expected text content"
);
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
}
async function testFalseGetter(oi) {
let node = findObjectInspectorNode(oi, "myFalseGetter");
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
const invokeButton = getObjectInspectorInvokeGetterButton(node);
ok(invokeButton, "There is an invoke button as expected");
invokeButton.click();
await waitFor(
() =>
!getObjectInspectorInvokeGetterButton(
findObjectInspectorNode(oi, "myFalseGetter")
)
);
node = findObjectInspectorNode(oi, "myFalseGetter");
ok(
node.textContent.includes(`myFalseGetter: false`),
"false getter now has the expected text content"
);
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
}
async function testTrueGetter(oi) {
let node = findObjectInspectorNode(oi, "myTrueGetter");
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
const invokeButton = getObjectInspectorInvokeGetterButton(node);
ok(invokeButton, "There is an invoke button as expected");
invokeButton.click();
await waitFor(
() =>
!getObjectInspectorInvokeGetterButton(
findObjectInspectorNode(oi, "myTrueGetter")
)
);
node = findObjectInspectorNode(oi, "myTrueGetter");
ok(
node.textContent.includes(`myTrueGetter: true`),
"false getter now has the expected text content"
);
is(
isObjectInspectorNodeExpandable(node),
false,
"The node can't be expanded"
);
}
async function testObjectGetter(oi) {
let node = findObjectInspectorNode(oi, "myObjectGetter");
is(