diff --git a/browser/devtools/shared/test/browser_graphs-01.js b/browser/devtools/shared/test/browser_graphs-01.js index bbcc3eb6137f..38147731aefc 100644 --- a/browser/devtools/shared/test/browser_graphs-01.js +++ b/browser/devtools/shared/test/browser_graphs-01.js @@ -20,7 +20,12 @@ function* performTest() { doc.body.setAttribute("style", "position: fixed; width: 100%; height: 100%; margin: 0;"); let graph = new LineGraphWidget(doc.body, "fps"); - yield graph.once("ready"); + + let readyEventEmitted; + graph.once("ready", () => readyEventEmitted = true); + + yield graph.ready(); + ok(readyEventEmitted, "The 'ready' event should have been emitted"); testGraph(host, graph); diff --git a/browser/devtools/shared/widgets/Graphs.jsm b/browser/devtools/shared/widgets/Graphs.jsm index 6ef5b40ef623..8e628e30b77b 100644 --- a/browser/devtools/shared/widgets/Graphs.jsm +++ b/browser/devtools/shared/widgets/Graphs.jsm @@ -5,8 +5,9 @@ const Cu = Components.utils; -Cu.import("resource://gre/modules/devtools/event-emitter.js"); Cu.import("resource:///modules/devtools/ViewHelpers.jsm"); +const promise = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise; +const {EventEmitter} = Cu.import("resource://gre/modules/devtools/event-emitter.js", {}); this.EXPORTED_SYMBOLS = ["LineGraphWidget"]; @@ -116,6 +117,7 @@ GraphSelectionResizer.prototype = { this.AbstractCanvasGraph = function(parent, name, sharpness) { EventEmitter.decorate(this); + this._ready = promise.defer(); this._parent = parent; this._uid = "canvas-graph-" + Date.now(); @@ -165,6 +167,7 @@ this.AbstractCanvasGraph = function(parent, name, sharpness) { this._animationId = this._window.requestAnimationFrame(this._onAnimationFrame); + this._ready.resolve(this); this.emit("ready", this); }); } @@ -181,6 +184,13 @@ AbstractCanvasGraph.prototype = { return this._height; }, + /** + * Returns a promise resolved once this graph is ready to receive data. + */ + ready: function() { + return this._ready.promise; + }, + /** * Destroys this graph. */