Bug 1426219 - Extend PromiseTestUtils to uncaught JavaScript Developer Errors;r?florian
This patch uses (and somewhat abuses) the existing PromiseTestUtils
mechanism to also be able to whitelist uncaught errors that are not
actual Promise rejections.
This uses `ChromeUtils.recentJSDevError`, which lets us find out
whether there is a recent ReferenceError/SyntaxError/TypeError in
chrome code, even if that error was caught.
MozReview-Commit-ID: 5z1pffURNYm
--- a/toolkit/modules/tests/modules/PromiseTestUtils.jsm
+++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm
@@ -87,16 +87,34 @@ this.PromiseTestUtils = {
PromiseDebugging.removeUncaughtRejectionObserver(this);
JSMPromise.Debugging.clearUncaughtErrorObservers();
this._initialized = false;
},
/**
+ * Called only by the test infrastructure, collect all the
+ * JavaScript Developer Errors that have been thrown and
+ * treat them as uncaught promise rejections.
+ */
+ collectJSDevErrors() {
+ if (!("recentJSDevError" in ChromeUtils)) {
+ // For the time being, recentJSDevError/clearRecentJSDevError is only available on Nightly builds.
+ return;
+ }
+ let recentJSDevError = ChromeUtils.recentJSDevError;
+ if (recentJSDevError) {
+ ChromeUtils.clearRecentJSDevError();
+ let message = recentJSDevError.message + "\n" + recentJSDevError.stack + "\n----\n Detected at\n";
+ Promise.reject(message);
+ }
+ },
+
+ /**
* Called only by the test infrastructure, spins the event loop until the
* messages for pending DOM Promise rejections have been processed.
*/
ensureDOMPromiseRejectionsProcessed() {
let observed = false;
let observer = {
onLeftUncaught: promise => {
if (PromiseDebugging.getState(promise).reason ===