Bug 1619993 - Use Debugger.Object values consistently across watchpoints. r=jlast

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2020-03-06 18:00:54 +00:00
Родитель 5b855de25b
Коммит 576f75f1f3
3 изменённых файлов: 40 добавлений и 47 удалений

Просмотреть файл

@ -2,6 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
async function getScopeValue(dbg, index) {
return (await waitForElement(dbg, "scopeValue", index)).innerText;
}
// - Tests adding a watchpoint // - Tests adding a watchpoint
// - Tests removing a watchpoint // - Tests removing a watchpoint
// - Tests adding a watchpoint, resuming to after the youngest frame has popped, // - Tests adding a watchpoint, resuming to after the youngest frame has popped,
@ -30,6 +34,7 @@ add_task(async function() {
await waitForPaused(dbg); await waitForPaused(dbg);
await waitForState(dbg, () => dbg.selectors.getSelectedInlinePreviews()); await waitForState(dbg, () => dbg.selectors.getSelectedInlinePreviews());
assertPausedAtSourceAndLine(dbg, sourceId, 17); assertPausedAtSourceAndLine(dbg, sourceId, 17);
is(await getScopeValue(dbg, 5), "3");
info("Resume and wait to pause at the access to b in the first `obj.b;`"); info("Resume and wait to pause at the access to b in the first `obj.b;`");
resume(dbg); resume(dbg);
@ -62,7 +67,7 @@ add_task(async function() {
getWatchpointItem2.click(); getWatchpointItem2.click();
pressKey(dbg, "Escape"); pressKey(dbg, "Escape");
await addedWatchpoint2; await addedWatchpoint2;
info("Resume and wait to pause at the access to b in getB"); info("Resume and wait to pause at the access to b in getB");
resume(dbg); resume(dbg);
await waitForPaused(dbg); await waitForPaused(dbg);
@ -81,7 +86,7 @@ add_task(async function() {
el2.scrollIntoView(); el2.scrollIntoView();
clickElementWithSelector(dbg, ".remove-get-watchpoint"); clickElementWithSelector(dbg, ".remove-get-watchpoint");
await removedWatchpoint2; await removedWatchpoint2;
info("Add back the get watchpoint on b"); info("Add back the get watchpoint on b");
const addedWatchpoint3 = waitForDispatch(dbg, "SET_WATCHPOINT"); const addedWatchpoint3 = waitForDispatch(dbg, "SET_WATCHPOINT");
await rightClickScopeNode(dbg, 5); await rightClickScopeNode(dbg, 5);

Просмотреть файл

@ -780,9 +780,7 @@ const proto = {
retval.value = this.hooks.createValueGrip(desc.value); retval.value = this.hooks.createValueGrip(desc.value);
} else if (this.thread.getWatchpoint(obj, name.toString())) { } else if (this.thread.getWatchpoint(obj, name.toString())) {
const watchpoint = this.thread.getWatchpoint(obj, name.toString()); const watchpoint = this.thread.getWatchpoint(obj, name.toString());
retval.value = this.hooks.createValueGrip( retval.value = this.hooks.createValueGrip(watchpoint.desc.value);
this.obj.makeDebuggeeValue(watchpoint.desc.value)
);
retval.watchpoint = watchpoint.watchpointType; retval.watchpoint = watchpoint.watchpointType;
} else { } else {
if ("get" in desc) { if ("get" in desc) {

Просмотреть файл

@ -10,28 +10,33 @@ class WatchpointMap {
this._watchpoints = new Map(); this._watchpoints = new Map();
} }
setWatchpoint(objActor, data) { _setWatchpoint(objActor, data) {
const { property, label, watchpointType } = data; const { property, label, watchpointType } = data;
const obj = objActor.rawValue(); const obj = objActor.rawValue();
if (this.has(obj, property)) { const desc = objActor.obj.getOwnPropertyDescriptor(property);
return;
if (this.has(obj, property) || desc.set || desc.get || !desc.configurable) {
return null;
} }
const desc = function getValue() {
Object.getOwnPropertyDescriptor(obj, property) || return typeof desc.value === "object" && desc.value
objActor.obj.getOwnPropertyDescriptor(property); ? desc.value.unsafeDereference()
: desc.value;
if (desc.set || desc.get || !desc.configurable) {
return;
} }
function setValue(v) {
const pauseAndRespond = type => { desc.value = objActor.obj.makeDebuggeeValue(v);
}
const maybeHandlePause = type => {
const frame = this.thread.dbg.getNewestFrame(); const frame = this.thread.dbg.getNewestFrame();
this.thread._pauseAndRespond(frame, {
type: type, if (this.thread.hasMoved(frame, type) && !this.thread.skipBreakpoints) {
message: label, this.thread._pauseAndRespond(frame, {
}); type: type,
message: label,
});
}
}; };
if (watchpointType === "get") { if (watchpointType === "get") {
@ -39,20 +44,11 @@ class WatchpointMap {
configurable: desc.configurable, configurable: desc.configurable,
enumerable: desc.enumerable, enumerable: desc.enumerable,
set: objActor.obj.makeDebuggeeValue(v => { set: objActor.obj.makeDebuggeeValue(v => {
desc.value = v; setValue(v);
}), }),
get: objActor.obj.makeDebuggeeValue(() => { get: objActor.obj.makeDebuggeeValue(() => {
const frame = this.thread.dbg.getNewestFrame(); maybeHandlePause("getWatchpoint");
return getValue();
if (!this.thread.hasMoved(frame, "getWatchpoint")) {
return false;
}
if (!this.thread.skipBreakpoints) {
pauseAndRespond("getWatchpoint");
}
return desc.value;
}), }),
}); });
} }
@ -62,31 +58,25 @@ class WatchpointMap {
configurable: desc.configurable, configurable: desc.configurable,
enumerable: desc.enumerable, enumerable: desc.enumerable,
set: objActor.obj.makeDebuggeeValue(v => { set: objActor.obj.makeDebuggeeValue(v => {
const frame = this.thread.dbg.getNewestFrame(); maybeHandlePause("setWatchpoint");
setValue(v);
if (!this.thread.hasMoved(frame, "setWatchpoint")) {
desc.value = v;
return;
}
if (!this.thread.skipBreakpoints) {
pauseAndRespond("setWatchpoint");
}
desc.value = v;
}), }),
get: objActor.obj.makeDebuggeeValue(() => { get: objActor.obj.makeDebuggeeValue(() => {
return desc.value; return getValue();
}), }),
}); });
} }
return desc;
} }
add(objActor, data) { add(objActor, data) {
// Get the object's description before calling setWatchpoint, // Get the object's description before calling setWatchpoint,
// otherwise we'll get the modified property descriptor instead // otherwise we'll get the modified property descriptor instead
const desc = objActor.obj.getOwnPropertyDescriptor(data.property); const desc = this._setWatchpoint(objActor, data);
this.setWatchpoint(objActor, data); if (!desc) {
return;
}
const objWatchpoints = const objWatchpoints =
this._watchpoints.get(objActor.rawValue()) || new Map(); this._watchpoints.get(objActor.rawValue()) || new Map();