Guard against null event.data from worker in the script formatter

The FormatterWorkerPool._onWorkerMessage method can call its current
task's callback with null as its parameter.
This happen when the formatter work doesn't send event data back.

When this happens, it creates exceptions in the ScriptFormatter class.
So, this change simply guards against this.

Bug: 1132284
Change-Id: I9a995a2b81b5e211ae1690caad7bf56a4772c354
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2431404
Reviewed-by: Jose Leal <joselea@microsoft.com>
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Patrick Brosset <patrick.brosset@microsoft.com>
This commit is contained in:
Patrick Brosset
2020-10-01 13:10:14 +00:00
committed by Commit Bot
parent 141a204367
commit 8e5cecab9e
+15 -5
View File
@@ -91,13 +91,23 @@ export class ScriptFormatter {
* @param {function(string, !FormatterSourceMapping)} callback
*/
constructor(mimeType, content, callback) {
content = content.replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '');
this._mimeType = mimeType;
this._originalContent = content.replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '');
this._callback = callback;
this._originalContent = content;
formatterWorkerPool()
.format(mimeType, content, Common.Settings.Settings.instance().moduleSetting('textEditorIndent').get())
.then(this._didFormatContent.bind(this));
this._initialize();
}
async _initialize() {
const pool = formatterWorkerPool();
const indent = Common.Settings.Settings.instance().moduleSetting('textEditorIndent').get();
const formatResult = await pool.format(this._mimeType, this._originalContent, indent);
if (!formatResult) {
this._callback(this._originalContent, new IdentityFormatterSourceMapping());
} else {
this._didFormatContent(formatResult);
}
}
/**