From 1b26c7568b0d09fd666d5a7bd37ecfdeb2759179 Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Thu, 28 Feb 2013 13:01:41 -0800 Subject: [PATCH] Bug 833877: Add a way to report exceptions in promises. r=Mossop --- lib/sdk/core/promise.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/sdk/core/promise.js b/lib/sdk/core/promise.js index 1c4400b9e..a6c172fb5 100644 --- a/lib/sdk/core/promise.js +++ b/lib/sdk/core/promise.js @@ -9,6 +9,13 @@ factory.call(this, require, exports, module); } else if (~String(this).indexOf('BackstagePass')) { // JSM this[factory.name] = {}; + try { + this.console = this['Components'].utils + .import('resource://gre/modules/devtools/Console.jsm', {}).console; + } + catch (ex) { + // Avoid failures on different toolkit configurations. + } factory(function require(uri) { var imports = {}; this['Components'].utils.import(uri, imports); @@ -53,7 +60,12 @@ function attempt(f) { **/ return function effort(options) { try { return f(options) } - catch(error) { return rejection(error) } + catch(error) { + if (exports._reportErrors && typeof(console) === 'object') { + console.error(error) + } + return rejection(error) + } } }