Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/common/FormatterWorkerPool.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/common/FormatterWorkerPool.js b/third_party/WebKit/Source/devtools/front_end/common/FormatterWorkerPool.js |
| index 3e3ed6801d3a04d0187618438f130e4f73231504..c3fffd59084a309fa94dcab88dbbf370f1bc664b 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/common/FormatterWorkerPool.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/common/FormatterWorkerPool.js |
| @@ -43,13 +43,13 @@ Common.FormatterWorkerPool = class { |
| _onWorkerMessage(worker, event) { |
| var task = this._workerTasks.get(worker); |
| if (task.isChunked && event.data && !event.data['isLastChunk']) { |
| - task.callback(event); |
| + task.callback(event.data); |
| return; |
| } |
| this._workerTasks.set(worker, null); |
| this._processNextTask(); |
| - task.callback(event.data ? event : null); |
| + task.callback(event.data ? event.data : null); |
| } |
| /** |
| @@ -71,20 +71,33 @@ Common.FormatterWorkerPool = class { |
| /** |
| * @param {string} methodName |
| * @param {!Object<string, string>} params |
| - * @param {function(?MessageEvent)} callback |
| + * @param {function(boolean, ?Object)} callback |
| */ |
| - runChunkedTask(methodName, params, callback) { |
| - var task = new Common.FormatterWorkerPool.Task(methodName, params, callback, true); |
| + _runChunkedTask(methodName, params, callback) { |
| + var task = new Common.FormatterWorkerPool.Task(methodName, params, onData, true); |
| this._taskQueue.push(task); |
| this._processNextTask(); |
| + |
| + /** |
| + * @param {?Object} data |
| + */ |
| + function onData(data) { |
| + if (!data) { |
| + callback(true, null); |
| + return; |
| + } |
| + var isLastChunk = !!data['isLastChunk']; |
| + var chunk = /** @type {?Object} */ (data['chunk']); |
| + callback(isLastChunk, chunk); |
| + } |
| } |
| /** |
| * @param {string} methodName |
| * @param {!Object<string, string>} params |
| - * @return {!Promise<?MessageEvent>} |
| + * @return {!Promise<?Object>} |
|
dgozman
2016/12/14 19:32:59
*
lushnikov
2016/12/14 23:36:56
Done.
|
| */ |
| - runTask(methodName, params) { |
| + _runTask(methodName, params) { |
| var callback; |
| var promise = new Promise(fulfill => callback = fulfill); |
| var task = new Common.FormatterWorkerPool.Task(methodName, params, callback, false); |
| @@ -92,6 +105,83 @@ Common.FormatterWorkerPool = class { |
| this._processNextTask(); |
| return promise; |
| } |
| + |
| + /** |
| + * @param {string} content |
| + * @return {!Promise<?Object>} |
|
dgozman
2016/12/14 19:32:59
*
lushnikov
2016/12/14 23:36:56
Done.
|
| + */ |
| + relaxedJSONParser(content) { |
|
dgozman
2016/12/14 19:32:59
parseJSONRelaxed
lushnikov
2016/12/14 23:36:56
Done.
|
| + return this._runTask('relaxedJSONParser', {content: content}); |
| + } |
| + |
| + /** |
| + * @param {string} content |
| + * @return {!Promise<!Array<!Object>>} |
|
dgozman
2016/12/14 19:32:59
Let's add types.
lushnikov
2016/12/14 23:36:56
Done.
|
| + */ |
| + parseSCSS(content) { |
| + return this._runTask('parseSCSS', {content: content}).then(rules => rules || []); |
| + } |
| + |
| + /** |
| + * @param {string} mimeType |
| + * @param {string} content |
| + * @param {string} indentString |
| + * @return {!Promise<?Common.FormatterWorkerPool.FormatResult>} |
| + */ |
| + format(mimeType, content, indentString) { |
| + var parameters = {mimeType: mimeType, content: content, indentString: indentString}; |
| + return /** @type {!Promise<?Common.FormatterWorkerPool.FormatResult>} */ (this._runTask('format', parameters)); |
| + } |
| + |
| + /** |
| + * @param {string} content |
| + * @return {!Promise<!Array<!{name: string, offset: number}>>} |
| + */ |
| + javaScriptIdentifiers(content) { |
| + return this._runTask('javaScriptIdentifiers', {content: content}).then(ids => ids || []); |
| + } |
| + |
| + /** |
| + * @param {string} content |
| + * @return {!Promise<string>} |
| + */ |
| + evaluatableJavaScriptSubstring(content) { |
| + return this._runTask('evaluatableJavaScriptSubstring', {content: content}).then(text => text || ''); |
| + } |
| + |
| + /** |
| + * @param {string} content |
| + * @param {function(boolean, !Array<!Common.FormatterWorkerPool.CSSRule>)} callback |
| + */ |
| + parseCSS(content, callback) { |
| + this._runChunkedTask('parseCSS', {content: content}, onDataChunk); |
| + |
| + /** |
| + * @param {boolean} isLastChunk |
| + * @param {?Object} data |
| + */ |
| + function onDataChunk(isLastChunk, data) { |
| + var rules = /** @type {!Array<!Common.FormatterWorkerPool.CSSRule>} */ (data || []); |
| + callback(isLastChunk, rules); |
| + } |
| + } |
| + |
| + /** |
| + * @param {string} content |
| + * @param {function(boolean, !Array<!Common.FormatterWorkerPool.JSOutlineItem>)} callback |
| + */ |
| + javaScriptOutline(content, callback) { |
| + this._runChunkedTask('javaScriptOutline', {content: content}, onDataChunk); |
| + |
| + /** |
| + * @param {boolean} isLastChunk |
| + * @param {?Object} data |
| + */ |
| + function onDataChunk(isLastChunk, data) { |
| + var items = /** @type {!Array.<!Common.FormatterWorkerPool.JSOutlineItem>} */ (data || []); |
| + callback(isLastChunk, items); |
| + } |
| + } |
| }; |
| Common.FormatterWorkerPool.MaxWorkers = 2; |
| @@ -114,5 +204,77 @@ Common.FormatterWorkerPool.Task = class { |
| } |
| }; |
| +Common.FormatterWorkerPool.FormatResult = class { |
| + constructor() { |
| + /** @type {string} */ |
| + this.content; |
| + /** @type {!Common.FormatterWorkerPool.FormatMapping} */ |
| + this.mapping; |
| + } |
| +}; |
| + |
| +/** @typedef {{original: !Array<number>, formatted: !Array<number>}} */ |
| +Common.FormatterWorkerPool.FormatMapping; |
| + |
| +Common.FormatterWorkerPool.JSOutlineItem = class { |
| + constructor() { |
| + /** @type {string} */ |
| + this.name; |
| + /** @type {(string|undefined)} */ |
| + this.arguments; |
| + /** @type {number} */ |
| + this.line; |
| + /** @type {number} */ |
| + this.column; |
| + } |
| +}; |
| + |
| +Common.FormatterWorkerPool.CSSStyleRule = class { |
| + constructor() { |
| + /** @type {string} */ |
| + this.selectorText; |
| + /** @type {!Common.FormatterWorkerPool.CSSRange} */ |
| + this.styleRange; |
| + /** @type {number} */ |
| + this.lineNumber; |
| + /** @type {number} */ |
| + this.columnNumber; |
| + /** @type {!Array.<!Common.FormatterWorkerPool.CSSProperty>} */ |
| + this.properties; |
| + } |
| +}; |
| + |
| +/** |
| + * @typedef {{atRule: string, lineNumber: number, columnNumber: number}} |
| + */ |
| +Common.FormatterWorkerPool.CSSAtRule; |
| + |
| +/** |
| + * @typedef {(Common.FormatterWorkerPool.CSSStyleRule|Common.FormatterWorkerPool.CSSAtRule)} |
| + */ |
| +Common.FormatterWorkerPool.CSSRule; |
| + |
| +/** |
| + * @typedef {{startLine: number, startColumn: number, endLine: number, endColumn: number}} |
| + */ |
| +Common.FormatterWorkerPool.CSSRange; |
| + |
| +Common.FormatterWorkerPool.CSSProperty = class { |
| + constructor() { |
| + /** @type {string} */ |
| + this.name; |
| + /** @type {!Common.FormatterWorkerPool.CSSRange} */ |
| + this.nameRange; |
| + /** @type {string} */ |
| + this.value; |
| + /** @type {!Common.FormatterWorkerPool.CSSRange} */ |
| + this.valueRange; |
| + /** @type {!Common.FormatterWorkerPool.CSSRange} */ |
| + this.range; |
| + /** @type {(boolean|undefined)} */ |
| + this.disabled; |
| + } |
| +}; |
| + |
| /** @type {!Common.FormatterWorkerPool} */ |
| Common.formatterWorkerPool; |