diff --git a/monitor/PromiseMonitor.js b/monitor/PromiseMonitor.js index 5d74dbb4..924bdbfd 100644 --- a/monitor/PromiseMonitor.js +++ b/monitor/PromiseMonitor.js @@ -12,7 +12,7 @@ define(function(require) { var error = require('./error'); function PromiseMonitor(reporter) { - this.traces = {}; + this._traces = {}; this.traceTask = 0; this.logDelay = 100; this.stackFilter = defaultStackFilter; @@ -21,6 +21,10 @@ define(function(require) { this._reporter = reporter; + if(typeof reporter.configurePromiseMonitor === 'function') { + reporter.configurePromiseMonitor(this); + } + var self = this; this._doLogTraces = function() { self._logTraces(); @@ -32,7 +36,7 @@ define(function(require) { }; PromiseMonitor.prototype.addTrace = function(handler, extraContext) { - this.traces[handler.id] = { + this._traces[handler.id] = { error: handler.value, context: handler.context, extraContext: extraContext @@ -41,8 +45,8 @@ define(function(require) { }; PromiseMonitor.prototype.removeTrace = function(handler) { - if(handler.id in this.traces) { - delete this.traces[handler.id]; + if(handler.id in this._traces) { + delete this._traces[handler.id]; this.logTraces(); } }; @@ -63,7 +67,7 @@ define(function(require) { PromiseMonitor.prototype._logTraces = function() { this.traceTask = void 0; - this._reporter.log(this.formatTraces(this.traces)); + this._reporter.log(this.formatTraces(this._traces)); }; diff --git a/test/monitor/PromiseMonitor-test.js b/test/monitor/PromiseMonitor-test.js index 9c947711..e263ef69 100644 --- a/test/monitor/PromiseMonitor-test.js +++ b/test/monitor/PromiseMonitor-test.js @@ -44,6 +44,15 @@ define('when/monitor/PromiseMonitor-test', function (require) { }}); Promise.reject(); + }, + + 'should call reporter.configurePromiseMonitor with self': function() { + var spy = this.spy(); + var m = new PromiseMonitor({ + configurePromiseMonitor: spy + }); + + assert.calledOnceWith(spy, m); } });