| 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..da21e10c4b8677bcb430bab0b0e477d5bc027b11 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, *)} 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 = data['chunk'];
|
| + callback(isLastChunk, chunk);
|
| + }
|
| }
|
|
|
| /**
|
| * @param {string} methodName
|
| * @param {!Object<string, string>} params
|
| - * @return {!Promise<?MessageEvent>}
|
| + * @return {!Promise<*>}
|
| */
|
| - 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<*>}
|
| + */
|
| + parseJSONRelaxed(content) {
|
| + return this._runTask('parseJSONRelaxed', {content: content});
|
| + }
|
| +
|
| + /**
|
| + * @param {string} content
|
| + * @return {!Promise<!Array<!Common.FormatterWorkerPool.SCSSRule>>}
|
| + */
|
| + 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 {*} 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 {*} data
|
| + */
|
| + function onDataChunk(isLastChunk, data) {
|
| + var items = /** @type {!Array.<!Common.FormatterWorkerPool.JSOutlineItem>} */ (data || []);
|
| + callback(isLastChunk, items);
|
| + }
|
| + }
|
| };
|
|
|
| Common.FormatterWorkerPool.MaxWorkers = 2;
|
| @@ -114,5 +204,101 @@ 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;
|
| + }
|
| +};
|
| +
|
| +/**
|
| + * @typedef {{startLine: number, startColumn: number, endLine: number, endColumn: number}}
|
| + */
|
| +Common.FormatterWorkerPool.TextRange;
|
| +
|
| +Common.FormatterWorkerPool.CSSProperty = class {
|
| + constructor() {
|
| + /** @type {string} */
|
| + this.name;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.nameRange;
|
| + /** @type {string} */
|
| + this.value;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.valueRange;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.range;
|
| + /** @type {(boolean|undefined)} */
|
| + this.disabled;
|
| + }
|
| +};
|
| +
|
| +Common.FormatterWorkerPool.CSSStyleRule = class {
|
| + constructor() {
|
| + /** @type {string} */
|
| + this.selectorText;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + 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;
|
| +
|
| +Common.FormatterWorkerPool.SCSSProperty = class {
|
| + constructor() {
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.range;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.name;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.value;
|
| + /** @type {boolean} */
|
| + this.disabled;
|
| + }
|
| +};
|
| +
|
| +Common.FormatterWorkerPool.SCSSRule = class {
|
| + constructor() {
|
| + /** @type {!Array<!Common.FormatterWorkerPool.TextRange>} */
|
| + this.selectors;
|
| + /** @type {!Array<!Common.FormatterWorkerPool.SCSSProperty>} */
|
| + this.properties;
|
| + /** @type {!Common.FormatterWorkerPool.TextRange} */
|
| + this.styleRange;
|
| + }
|
| +};
|
| +
|
| /** @type {!Common.FormatterWorkerPool} */
|
| Common.formatterWorkerPool;
|
|
|