Index: Source/devtools/front_end/sources/ScriptFormatter.js |
diff --git a/Source/devtools/front_end/sources/ScriptFormatter.js b/Source/devtools/front_end/sources/ScriptFormatter.js |
index 13b0814a2c947a0ee229d27a3830737f25e1390f..dcd4b1ada993d0ab1f6c8efe497d914bd3759cfc 100644 |
--- a/Source/devtools/front_end/sources/ScriptFormatter.js |
+++ b/Source/devtools/front_end/sources/ScriptFormatter.js |
@@ -105,7 +105,7 @@ WebInspector.ScriptFormatter.prototype = { |
const method = "format"; |
var parameters = { mimeType: mimeType, content: content, indentString: WebInspector.settings.textEditorIndent.get() }; |
this._tasks.push({ data: parameters, callback: callback }); |
- this._worker.postMessage({ method: method, params: parameters }); |
+ this._postMessage({ method: method, params: parameters }); |
}, |
_didFormatContent: function(event) |
@@ -119,15 +119,40 @@ WebInspector.ScriptFormatter.prototype = { |
}, |
/** |
- * @return {!Worker} |
+ * @param {!Object} message |
*/ |
- get _worker() |
+ _postMessage: function(message) |
{ |
- if (!this._cachedWorker) { |
- this._cachedWorker = Runtime.startWorker("script_formatter_worker"); |
+ this._workerPromise().then(postMessage.bind(this)); |
+ |
+ /** |
+ * @this {WebInspector.ScriptFormatter} |
+ */ |
+ function postMessage() |
+ { |
+ this._cachedWorker.postMessage(message); |
+ } |
+ }, |
+ |
+ /** |
+ * @return {!Promise.<undefined>} |
+ */ |
+ _workerPromise: function() |
+ { |
+ if (this._cachedWorker) |
+ return Promise.resolve(this._cachedWorker); |
+ |
+ return Runtime.startWorker("script_formatter_worker").then(started.bind(this)); |
pfeldman
2014/11/07 14:51:17
You want to store this resulting promise and retur
apavlov
2014/11/10 07:44:12
Done.
|
+ |
+ /** |
+ * @param {!Worker} worker |
+ * @this {WebInspector.ScriptFormatter} |
+ */ |
+ function started(worker) |
+ { |
+ this._cachedWorker = worker; |
this._cachedWorker.onmessage = /** @type {function(this:Worker)} */ (this._didFormatContent.bind(this)); |
} |
- return this._cachedWorker; |
} |
} |