Bug 1014473 - Trivial code cleanup on AsyncShutdown. r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2014-05-27 14:21:00 -04:00
parent 291270aec6
commit a53cdb2cf0

View File

@ -107,15 +107,15 @@ function err(msg, error = null) {
// of a blocker.
// We are a little paranoid here to ensure that in case of evaluation
// error we do not block the AsyncShutdown.
function safeGetState(state) {
if (!state) {
function safeGetState(fetchState) {
if (!fetchState) {
return "(none)";
}
let data, string;
try {
// Evaluate state(), normalize the result into something that we can
// Evaluate fetchState(), normalize the result into something that we can
// safely stringify or upload.
string = JSON.stringify(state());
string = JSON.stringify(fetchState());
data = JSON.parse(string);
// Simplify the rest of the code by ensuring that we can simply
// concatenate the result to a message.
@ -215,7 +215,7 @@ function getPhase(topic) {
* resulting promise is either resolved or rejected. If
* |condition| is not a function but another value |v|, it behaves
* as if it were a function returning |v|.
* @param {function*} state Optionally, a function returning
* @param {function*} fetchState Optionally, a function returning
* information about the current state of the blocker as an
* object. Used for providing more details when logging errors or
* crashing.
@ -241,8 +241,8 @@ function getPhase(topic) {
* // No specific guarantee about completion of profileBeforeChange
* });
*/
addBlocker: function(name, condition, state = null) {
spinner.addBlocker(name, condition, state);
addBlocker: function(name, condition, fetchState = null) {
spinner.addBlocker(name, condition, fetchState);
},
/**
* Remove the blocker for a condition.
@ -306,8 +306,8 @@ Spinner.prototype = {
* we wait until the promise is resolved/rejected before proceeding
* to the next runstate.
*/
addBlocker: function(name, condition, state) {
this._barrier.client.addBlocker(name, condition, state);
addBlocker: function(name, condition, fetchState) {
this._barrier.client.addBlocker(name, condition, fetchState);
},
/**
* Remove the blocker for a condition.
@ -364,7 +364,7 @@ function Barrier(name) {
* The set of conditions registered by clients, as a map.
*
* Key: condition (function)
* Value: Array of {name: string, state: function}
* Value: Array of {name: string, fetchState: function}
*/
this._conditions = new Map();
@ -411,16 +411,16 @@ function Barrier(name) {
* resulting promise is either resolved or rejected. If
* |condition| is not a function but another value |v|, it behaves
* as if it were a function returning |v|.
* @param {function*} state Optionally, a function returning
* @param {function*} fetchState Optionally, a function returning
* information about the current state of the blocker as an
* object. Used for providing more details when logging errors or
* crashing.
*/
addBlocker: function(name, condition, state) {
addBlocker: function(name, condition, fetchState) {
if (typeof name != "string") {
throw new TypeError("Expected a human-readable name as first argument");
}
if (state && typeof state != "function") {
if (fetchState && typeof fetchState != "function") {
throw new TypeError("Expected nothing or a function as third argument");
}
if (!this._conditions) {
@ -433,7 +433,7 @@ function Barrier(name) {
set = [];
this._conditions.set(condition, set);
}
set.push({name: name, state: state});
set.push({name: name, fetchState: fetchState});
}.bind(this),
/**
@ -480,9 +480,9 @@ Barrier.prototype = Object.freeze({
return "Complete";
}
let frozen = [];
for (let {name, isComplete, state} of this._monitors) {
for (let {name, isComplete, fetchState} of this._monitors) {
if (!isComplete) {
frozen.push({name: name, state: safeGetState(state)});
frozen.push({name: name, state: safeGetState(fetchState)});
}
}
return frozen;
@ -536,7 +536,7 @@ Barrier.prototype = Object.freeze({
for (let _condition of conditions.keys()) {
for (let current of conditions.get(_condition)) {
let condition = _condition; // Avoid capturing the wrong variable
let {name, state} = current;
let {name, fetchState} = current;
// An indirection on top of condition, used to let clients
// cancel a blocker through removeBlocker.
@ -565,7 +565,7 @@ Barrier.prototype = Object.freeze({
let monitor = {
isComplete: false,
name: name,
state: state
fetchState: fetchState
};
condition = condition.then(null, function onError(error) {
@ -573,7 +573,7 @@ Barrier.prototype = Object.freeze({
" while we were spinning the event loop." +
" Condition: " + name +
" Phase: " + topic +
" State: " + safeGetState(state);
" State: " + safeGetState(fetchState);
warn(msg, error);
});
condition.then(() => indirection.resolve());
@ -587,7 +587,7 @@ Barrier.prototype = Object.freeze({
" while we were initializing the phase." +
" Condition: " + name +
" Phase: " + topic +
" State: " + safeGetState(state);
" State: " + safeGetState(fetchState);
warn(msg, error);
}