Bug 1574190 - Add watchpoint as a trait in the server, remove watchpoints when object actor is released, add watchpoint to property descriptor object r=jlast

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Miriam 2019-09-06 18:12:06 +00:00
Родитель 1ba46b8359
Коммит 9b093489d4
2 изменённых файлов: 26 добавлений и 7 удалений

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

@ -108,17 +108,20 @@ const proto = {
}, },
addWatchpoint(property, label, watchpointType) { addWatchpoint(property, label, watchpointType) {
// We promote the object actor to the thread pool
// so that it lives for the lifetime of the watchpoint.
this.thread.threadObjectGrip(this);
if (this._originalDescriptors.has(property)) { if (this._originalDescriptors.has(property)) {
return; return;
} }
const desc = this.obj.getOwnPropertyDescriptor(property); const desc = this.obj.getOwnPropertyDescriptor(property);
//If there is already a setter or getter, don't add watchpoint.
if (desc.set || desc.get) { if (desc.set || desc.get) {
return; return;
} }
this._originalDescriptors.set(property, desc); this._originalDescriptors.set(property, { desc, watchpointType });
const pauseAndRespond = () => { const pauseAndRespond = () => {
const frame = this.thread.dbg.getNewestFrame(); const frame = this.thread.dbg.getNewestFrame();
@ -137,6 +140,7 @@ const proto = {
}), }),
get: this.obj.makeDebuggeeValue(() => { get: this.obj.makeDebuggeeValue(() => {
pauseAndRespond(); pauseAndRespond();
return desc.value;
}), }),
}); });
} }
@ -146,8 +150,11 @@ const proto = {
configurable: desc.configurable, configurable: desc.configurable,
enumerable: desc.enumerable, enumerable: desc.enumerable,
set: this.obj.makeDebuggeeValue(v => { set: this.obj.makeDebuggeeValue(v => {
desc.value = v;
pauseAndRespond(); pauseAndRespond();
desc.value = v;
}),
get: this.obj.makeDebuggeeValue(v => {
return desc.value;
}), }),
}); });
} }
@ -158,11 +165,17 @@ const proto = {
return; return;
} }
const desc = this._originalDescriptors.get(property); const desc = this._originalDescriptors.get(property).desc;
this._originalDescriptors.delete(property); this._originalDescriptors.delete(property);
this.obj.defineProperty(property, desc); this.obj.defineProperty(property, desc);
}, },
removeWatchpoints() {
this._originalDescriptors.forEach(property =>
this.removeWatchpoint(property)
);
},
/** /**
* Returns a grip for this actor for returning in a protocol message. * Returns a grip for this actor for returning in a protocol message.
*/ */
@ -781,8 +794,10 @@ const proto = {
retval.writable = desc.writable; retval.writable = desc.writable;
retval.value = this.hooks.createValueGrip(desc.value); retval.value = this.hooks.createValueGrip(desc.value);
} else if (this._originalDescriptors.has(name)) { } else if (this._originalDescriptors.has(name)) {
const value = this._originalDescriptors.get(name).value; const watchpointType = this._originalDescriptors.get(name).watchpointType;
retval.value = this.hooks.createValueGrip(value); desc = this._originalDescriptors.get(name).desc;
retval.value = this.hooks.createValueGrip(desc.value);
retval.watchpoint = watchpointType;
} else { } else {
if ("get" in desc) { if ("get" in desc) {
retval.get = this.hooks.createValueGrip(desc.get); retval.get = this.hooks.createValueGrip(desc.get);
@ -1016,7 +1031,9 @@ const proto = {
* Release the actor, when it isn't needed anymore. * Release the actor, when it isn't needed anymore.
* Protocol.js uses this release method to call the destroy method. * Protocol.js uses this release method to call the destroy method.
*/ */
release: function() {}, release: function() {
this.removeWatchpoints();
},
}; };
exports.ObjectActor = protocol.ActorClassWithSpec(objectSpec, proto); exports.ObjectActor = protocol.ActorClassWithSpec(objectSpec, proto);

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

@ -182,6 +182,8 @@ RootActor.prototype = {
nativeLogpoints: true, nativeLogpoints: true,
// support older browsers for Fx69+ // support older browsers for Fx69+
hasThreadFront: true, hasThreadFront: true,
// Support watchpoints in the server for Fx71+
watchpoints: true,
}, },
/** /**