Bug 1132370 - Wrong State: Expected 'attached', but current state is 'detached', r=jsantell

This commit is contained in:
Victor Porof 2015-03-05 12:19:57 -05:00
parent 8ead3be5da
commit 376b2d5d77
3 changed files with 39 additions and 16 deletions

View File

@ -27,10 +27,11 @@ function MockFront (blueprint) {
function MockMemoryFront () {
MockFront.call(this, [
["attach"],
["detach"],
["initialize"],
["destroy"],
["attach"],
["detach"],
["getState", "detached"],
["startRecordingAllocations", 0],
["stopRecordingAllocations", 0],
["getAllocations", createMockAllocations],
@ -40,10 +41,10 @@ exports.MockMemoryFront = MockMemoryFront;
function MockTimelineFront () {
MockFront.call(this, [
["start", 0],
["stop", 0],
["initialize"],
["destroy"],
["start", 0],
["stop", 0],
]);
}
exports.MockTimelineFront = MockTimelineFront;

View File

@ -358,6 +358,7 @@ PerformanceFront.prototype = {
*/
_pullAllocationSites: Task.async(function *() {
let memoryData = yield this._request("memory", "getAllocations");
let isStillAttached = yield this._request("memory", "getState") == "attached";
this.emit("allocations", {
sites: memoryData.allocations,
@ -366,8 +367,10 @@ PerformanceFront.prototype = {
counts: memoryData.counts
});
let delay = DEFAULT_ALLOCATION_SITES_PULL_TIMEOUT;
this._sitesPullTimeout = setTimeout(this._pullAllocationSites, delay);
if (isStillAttached) {
let delay = DEFAULT_ALLOCATION_SITES_PULL_TIMEOUT;
this._sitesPullTimeout = setTimeout(this._pullAllocationSites, delay);
}
}),
/**

View File

@ -19,7 +19,8 @@ loader.lazyRequireGetter(this, "StackFrameCache",
*
* @param String expectedState
* The expected state.
*
* @param String activity
* Additional info about what's going on.
* @param Function method
* The actor method to proceed with when the actor is in the expected
* state.
@ -27,11 +28,12 @@ loader.lazyRequireGetter(this, "StackFrameCache",
* @returns Function
* The decorated method.
*/
function expectState(expectedState, method) {
function expectState(expectedState, method, activity) {
return function(...args) {
if (this.state !== expectedState) {
const msg = "Wrong State: Expected '" + expectedState + "', but current "
+ "state is '" + this.state + "'";
const msg = `Wrong state while ${activity}:` +
`Expected '${expectedState}',` +
`but current state is '${this.state}'.`;
return Promise.reject(new Error(msg));
}
@ -96,7 +98,8 @@ let MemoryActor = protocol.ActorClass({
attach: method(expectState("detached", function() {
this.dbg.addDebuggees();
this.state = "attached";
}), {
},
`attaching to the debugger`), {
request: {},
response: {
type: "attached"
@ -111,13 +114,25 @@ let MemoryActor = protocol.ActorClass({
this.dbg.enabled = false;
this._dbg = null;
this.state = "detached";
}), {
},
`detaching from the debugger`), {
request: {},
response: {
type: "detached"
}
}),
/**
* Gets the current MemoryActor attach/detach state.
*/
getState: method(function() {
return this.state;
}, {
response: {
state: RetVal(0, "string")
}
}),
_clearDebuggees: function() {
if (this._dbg) {
if (this.dbg.memory.trackingAllocationSites) {
@ -153,7 +168,8 @@ let MemoryActor = protocol.ActorClass({
*/
takeCensus: method(expectState("attached", function() {
return this.dbg.memory.takeCensus();
}), {
},
`taking census`), {
request: {},
response: RetVal("json")
}),
@ -175,7 +191,8 @@ let MemoryActor = protocol.ActorClass({
this.dbg.memory.trackingAllocationSites = true;
return Date.now();
}), {
},
`starting recording allocations`), {
request: {
options: Arg(0, "nullable:AllocationsRecordingOptions")
},
@ -193,7 +210,8 @@ let MemoryActor = protocol.ActorClass({
this._clearFrames();
return Date.now();
}), {
},
`stopping recording allocations`), {
request: {},
response: {
// Accept `nullable` in the case of server Gecko <= 37, handled on the front
@ -295,7 +313,8 @@ let MemoryActor = protocol.ActorClass({
}
return this._frameCache.updateFramePacket(packet);
}), {
},
`getting allocations`), {
request: {},
response: RetVal("json")
}),