Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1379)

Unified Diff: Source/devtools/front_end/sources/ScriptFormatter.js

Issue 685203003: DevTools: Get rid of synchronous XHRs in the frontend code (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..285fc7099dc06854cc13379165c95e11a0b66d80 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);
pfeldman 2014/11/10 10:23:26 It would have deferred postMessage on its own.
+ }
+ },
+
+ /**
+ * @return {!Promise.<undefined>}
+ */
+ _workerPromise: function()
+ {
+ if (!this._pendingWorkerPromise)
+ this._pendingWorkerPromise = WorkerRuntime.startWorker("script_formatter_worker").then(started.bind(this));
+
+ return this._pendingWorkerPromise;
+
+ /**
+ * @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;
}
}

Powered by Google App Engine
This is Rietveld 408576698