Backed out changeset 0f91a3f28a44 (bug 976205) per request - incorrect patch

This commit is contained in:
Carsten "Tomcat" Book 2014-04-04 14:46:51 +02:00
parent 4036f5469f
commit a084d4feba
3 changed files with 30 additions and 157 deletions

View File

@ -180,8 +180,7 @@ function _do_main() {
function _do_quit() {
_log("test_info",
{_message: "TEST-INFO | (xpcshell/head.js) | exiting test\n"});
let Promise = Components.utils.import("resource://gre/modules/Promise.jsm", null).Promise;
Promise.Debugging.flushUncaughtErrors();
_quit = true;
}
@ -349,15 +348,6 @@ function _execute_test() {
// Call do_get_idle() to restore the factory and get the service.
_fakeIdleService.activate();
let Promise = Components.utils.import("resource://gre/modules/Promise.jsm", null).Promise;
Promise.Debugging.clearUncaughtErrorObservers();
Promise.Debugging.addUncaughtErrorObserver(function observer({message, date, fileName, stack, lineNumber}) {
let text = "A promise chain failed to handle a rejection: " +
message + " - rejection date: " + date;
_log_message_with_stack("test_unexpected_fail",
text, stack, fileName);
});
// _HEAD_FILES is dynamically defined by <runxpcshelltests.py>.
_load_files(_HEAD_FILES);
// _TEST_FILE is dynamically defined by <runxpcshelltests.py>.

View File

@ -78,27 +78,8 @@ XPCOMUtils.defineLazyServiceGetter(this, "FinalizationWitnessService",
"nsIFinalizationWitnessService");
let PendingErrors = {
// An internal counter, used to generate unique id.
_counter: 0,
// Functions registered to be notified when a pending error
// is reported as uncaught.
_observers: new Set(),
_map: new Map(),
/**
* Initialize PendingErrors
*/
init: function() {
Services.obs.addObserver(function observe(aSubject, aTopic, aValue) {
PendingErrors.report(aValue);
}, "promise-finalization-witness", false);
},
/**
* Register an error as tracked.
*
* @return The unique identifier of the error.
*/
register: function(error) {
let id = "pending-error-" + (this._counter++);
//
@ -185,102 +166,46 @@ let PendingErrors = {
this._map.set(id, value);
return id;
},
/**
* Notify all observers that a pending error is now uncaught.
*
* @param id The identifier of the pending error, as returned by
* |register|.
*/
report: function(id) {
extract: function(id) {
let value = this._map.get(id);
if (!value) {
return; // The error has already been reported
}
this._map.delete(id);
for (let obs of this._observers.values()) {
obs(value);
}
return value;
},
/**
* Mark all pending errors are uncaught, notify the observers.
*/
flush: function() {
// Since we are going to modify the map while walking it,
// let's copying the keys first.
let keys = Array.slice(this._map.keys());
for (let key of keys) {
this.report(key);
}
},
/**
* Stop tracking an error, as this error has been caught,
* eventually.
*/
unregister: function(id) {
this._map.delete(id);
},
/**
* Add an observer notified when an error is reported as uncaught.
*
* @param {function} observer A function notified when an error is
* reported as uncaught. Its arguments are
* {message, date, fileName, stack, lineNumber}
* All arguments are optional.
*/
addObserver: function(observer) {
this._observers.add(observer);
},
/**
* Remove an observer added with addObserver
*/
removeObserver: function(observer) {
this._observers.delete(observer);
},
/**
* Remove all the observers added with addObserver
*/
removeAllObservers: function() {
this._observers.clear();
}
};
PendingErrors.init();
// Default mechanism for displaying errors
PendingErrors.addObserver(function(details) {
// Actually print the finalization warning.
Services.obs.addObserver(function observe(aSubject, aTopic, aValue) {
let error = PendingErrors.extract(aValue);
let {message, date, fileName, stack, lineNumber} = error;
let error = Cc['@mozilla.org/scripterror;1'].createInstance(Ci.nsIScriptError);
if (!error || !Services.console) {
// Too late during shutdown to use the nsIConsole
dump("*************************\n");
dump("A promise chain failed to handle a rejection\n\n");
dump("On: " + details.date + "\n");
dump("Full message: " + details.message + "\n");
dump("On: " + date + "\n");
dump("Full message: " + message + "\n");
dump("See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise\n");
dump("Full stack: " + (details.stack||"not available") + "\n");
dump("Full stack: " + (stack||"not available") + "\n");
dump("*************************\n");
return;
}
let message = details.message;
if (details.stack) {
message += "\nFull Stack: " + details.stack;
if (stack) {
message += "\nFull Stack: " + stack;
}
error.init(
/*message*/"A promise chain failed to handle a rejection.\n\n" +
"Date: " + details.date + "\nFull Message: " + details.message,
/*sourceName*/ details.fileName,
/*sourceLine*/ details.lineNumber?("" + details.lineNumber):0,
/*lineNumber*/ details.lineNumber || 0,
"Date: " + date + "\nFull Message: " + message,
/*sourceName*/ fileName,
/*sourceLine*/ lineNumber?("" + lineNumber):0,
/*lineNumber*/ lineNumber || 0,
/*columnNumber*/ 0,
/*flags*/ Ci.nsIScriptError.errorFlag,
/*category*/ "chrome javascript");
Services.console.logMessage(error);
});
}, "promise-finalization-witness", false);
///////// Additional warnings for developers
//
@ -571,45 +496,6 @@ Promise.race = function (aValues)
});
};
Promise.Debugging = {
/**
* Add an observer notified when an error is reported as uncaught.
*
* @param {function} observer A function notified when an error is
* reported as uncaught. Its arguments are
* {message, date, fileName, stack, lineNumber}
* All arguments are optional.
*/
addUncaughtErrorObserver: function(observer) {
PendingErrors.addObserver(observer);
},
/**
* Remove an observer added with addUncaughtErrorObserver
*
* @param {function} An observer registered with
* addUncaughtErrorObserver.
*/
removeUncaughtErrorObserver: function(observer) {
PendingErrors.removeObserver(observer);
},
/**
* Remove all the observers added with addUncaughtErrorObserver
*/
clearUncaughtErrorObservers: function() {
PendingErrors.removeAllObservers();
},
/**
* Force all pending errors to be reported immediately as uncaught.
* Note that this may cause some false positives.
*/
flushUncaughtErrors: function() {
PendingErrors.flush();
},
};
Object.freeze(Promise.Debugging);
Object.freeze(Promise);
////////////////////////////////////////////////////////////////////////////////

View File

@ -6,10 +6,6 @@ Components.utils.import("resource://gre/modules/Promise.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/Task.jsm");
// Deactivate the standard xpcshell observer, as it turns uncaught
// rejections into failures, which we don't want here.
Promise.Debugging.clearUncaughtErrorObservers();
////////////////////////////////////////////////////////////////////////////////
//// Test runner
@ -963,26 +959,28 @@ function wait_for_uncaught(aMustAppear, aTimeout = undefined) {
let deferred = Promise.defer();
let print = do_print;
let execute_soon = do_execute_soon;
let observer = function({message, stack}) {
let data = message + stack;
print("Observing " + message + ", looking for " + aMustAppear.join(", "));
for (let expected of remaining) {
if (data.indexOf(expected) != -1) {
print("I found " + expected);
remaining.delete(expected);
let observer = function(aMessage) {
execute_soon(function() {
let message = aMessage.message;
print("Observing " + message);
for (let expected of remaining) {
if (message.indexOf(expected) != -1) {
print("I found " + expected);
remaining.delete(expected);
}
}
if (remaining.size == 0 && observer) {
Promise.Debugging.removeUncaughtErrorObserver(observer);
Services.console.unregisterListener(observer);
observer = null;
deferred.resolve();
}
}
});
};
Promise.Debugging.addUncaughtErrorObserver(observer);
Services.console.registerListener(observer);
if (aTimeout) {
do_timeout(aTimeout, function timeout() {
if (observer) {
Promise.Debugging.removeUncaughtErrorObserver(observer);
Services.console.unregisterListener(observer);
observer = null;
}
deferred.reject(new Error("Timeout"));
@ -1057,7 +1055,6 @@ function wait_for_uncaught(aMustAppear, aTimeout = undefined) {
Promise.reject(error);
}
})();
do_print("Posted all rejections");
Components.utils.forceGC();
Components.utils.forceCC();
Components.utils.forceShrinkingGC();