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

Unified Diff: third_party/WebKit/Source/devtools/front_end/network/JSONView.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 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: third_party/WebKit/Source/devtools/front_end/network/JSONView.js
diff --git a/third_party/WebKit/Source/devtools/front_end/network/JSONView.js b/third_party/WebKit/Source/devtools/front_end/network/JSONView.js
index 7b830c80c254050031c592b118b5f78358a48a43..dafb969d0cd34e63aa4695a9db2f7e9e460ab6f7 100644
--- a/third_party/WebKit/Source/devtools/front_end/network/JSONView.js
+++ b/third_party/WebKit/Source/devtools/front_end/network/JSONView.js
@@ -27,18 +27,18 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
/**
- * @constructor
- * @extends {WebInspector.VBox}
* @implements {WebInspector.Searchable}
- * @param {!WebInspector.ParsedJSON} parsedJSON
+ * @unrestricted
*/
-WebInspector.JSONView = function(parsedJSON)
-{
- WebInspector.VBox.call(this);
+WebInspector.JSONView = class extends WebInspector.VBox {
+ /**
+ * @param {!WebInspector.ParsedJSON} parsedJSON
+ */
+ constructor(parsedJSON) {
+ super();
this._parsedJSON = parsedJSON;
- this.element.classList.add("json-view");
+ this.element.classList.add('json-view');
/** @type {?WebInspector.SearchableView} */
this._searchableView;
@@ -50,263 +50,251 @@ WebInspector.JSONView = function(parsedJSON)
this._currentSearchTreeElements = [];
/** @type {?RegExp} */
this._searchRegex = null;
-};
+ }
-/**
- * @param {!WebInspector.ParsedJSON} parsedJSON
- * @return {!WebInspector.SearchableView}
- */
-WebInspector.JSONView.createSearchableView = function(parsedJSON)
-{
+ /**
+ * @param {!WebInspector.ParsedJSON} parsedJSON
+ * @return {!WebInspector.SearchableView}
+ */
+ static createSearchableView(parsedJSON) {
var jsonView = new WebInspector.JSONView(parsedJSON);
var searchableView = new WebInspector.SearchableView(jsonView);
- searchableView.setPlaceholder(WebInspector.UIString("Find"));
+ searchableView.setPlaceholder(WebInspector.UIString('Find'));
jsonView._searchableView = searchableView;
jsonView.show(searchableView.element);
- jsonView.element.setAttribute("tabIndex", 0);
+ jsonView.element.setAttribute('tabIndex', 0);
return searchableView;
-};
+ }
-/**
- * @param {?string} text
- * @return {!Promise<?WebInspector.ParsedJSON>}
- */
-WebInspector.JSONView.parseJSON = function(text)
-{
+ /**
+ * @param {?string} text
+ * @return {!Promise<?WebInspector.ParsedJSON>}
+ */
+ static parseJSON(text) {
var returnObj = null;
if (text)
- returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (text));
+ returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (text));
if (!returnObj)
- return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null));
- return WebInspector.formatterWorkerPool.runTask("relaxedJSONParser", {content: returnObj.data})
+ return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null));
+ return WebInspector.formatterWorkerPool.runTask('relaxedJSONParser', {content: returnObj.data})
.then(handleReturnedJSON);
/**
* @param {?MessageEvent} event
* @return {?WebInspector.ParsedJSON}
*/
- function handleReturnedJSON(event)
- {
- if (!event || !event.data)
- return null;
- returnObj.data = event.data;
- return returnObj;
+ function handleReturnedJSON(event) {
+ if (!event || !event.data)
+ return null;
+ returnObj.data = event.data;
+ return returnObj;
}
-};
+ }
-/**
- * @param {string} text
- * @return {?WebInspector.ParsedJSON}
- */
-WebInspector.JSONView._extractJSON = function(text)
-{
+ /**
+ * @param {string} text
+ * @return {?WebInspector.ParsedJSON}
+ */
+ static _extractJSON(text) {
// Do not treat HTML as JSON.
- if (text.startsWith("<"))
- return null;
- var inner = WebInspector.JSONView._findBrackets(text, "{", "}");
- var inner2 = WebInspector.JSONView._findBrackets(text, "[", "]");
+ if (text.startsWith('<'))
+ return null;
+ var inner = WebInspector.JSONView._findBrackets(text, '{', '}');
+ var inner2 = WebInspector.JSONView._findBrackets(text, '[', ']');
inner = inner2.length > inner.length ? inner2 : inner;
// Return on blank payloads or on payloads significantly smaller than original text.
if (inner.length === -1 || text.length - inner.length > 80)
- return null;
+ return null;
var prefix = text.substring(0, inner.start);
var suffix = text.substring(inner.end + 1);
text = text.substring(inner.start, inner.end + 1);
// Only process valid JSONP.
- if (suffix.trim().length && !(suffix.trim().startsWith(")") && prefix.trim().endsWith("(")))
- return null;
+ if (suffix.trim().length && !(suffix.trim().startsWith(')') && prefix.trim().endsWith('(')))
+ return null;
return new WebInspector.ParsedJSON(text, prefix, suffix);
-};
+ }
-/**
- * @param {string} text
- * @param {string} open
- * @param {string} close
- * @return {{start: number, end: number, length: number}}
- */
-WebInspector.JSONView._findBrackets = function(text, open, close)
-{
+ /**
+ * @param {string} text
+ * @param {string} open
+ * @param {string} close
+ * @return {{start: number, end: number, length: number}}
+ */
+ static _findBrackets(text, open, close) {
var start = text.indexOf(open);
var end = text.lastIndexOf(close);
var length = end - start - 1;
if (start === -1 || end === -1 || end < start)
- length = -1;
+ length = -1;
return {start: start, end: end, length: length};
-};
+ }
-WebInspector.JSONView.prototype = {
- wasShown: function()
- {
- this._initialize();
- },
+ /**
+ * @override
+ */
+ wasShown() {
+ this._initialize();
+ }
- _initialize: function()
- {
- if (this._initialized)
- return;
- this._initialized = true;
+ _initialize() {
+ if (this._initialized)
+ return;
+ this._initialized = true;
- var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data);
- var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suffix;
- this._treeOutline = new WebInspector.ObjectPropertiesSection(obj, title);
- this._treeOutline.setEditable(false);
- this._treeOutline.expand();
- this.element.appendChild(this._treeOutline.element);
- },
+ var obj = WebInspector.RemoteObject.fromLocalObject(this._parsedJSON.data);
+ var title = this._parsedJSON.prefix + obj.description + this._parsedJSON.suffix;
+ this._treeOutline = new WebInspector.ObjectPropertiesSection(obj, title);
+ this._treeOutline.setEditable(false);
+ this._treeOutline.expand();
+ this.element.appendChild(this._treeOutline.element);
+ }
- /**
- * @param {number} index
- */
- _jumpToMatch: function(index)
- {
- if (!this._searchRegex)
- return;
- var previousFocusElement = this._currentSearchTreeElements[this._currentSearchFocusIndex];
- if (previousFocusElement)
- previousFocusElement.setSearchRegex(this._searchRegex);
+ /**
+ * @param {number} index
+ */
+ _jumpToMatch(index) {
+ if (!this._searchRegex)
+ return;
+ var previousFocusElement = this._currentSearchTreeElements[this._currentSearchFocusIndex];
+ if (previousFocusElement)
+ previousFocusElement.setSearchRegex(this._searchRegex);
- var newFocusElement = this._currentSearchTreeElements[index];
- if (newFocusElement) {
- this._updateSearchIndex(index);
- newFocusElement.setSearchRegex(this._searchRegex, WebInspector.highlightedCurrentSearchResultClassName);
- newFocusElement.reveal();
- } else {
- this._updateSearchIndex(0);
- }
- },
-
- /**
- * @param {number} count
- */
- _updateSearchCount: function(count)
- {
- if (!this._searchableView)
- return;
- this._searchableView.updateSearchMatchesCount(count);
- },
+ var newFocusElement = this._currentSearchTreeElements[index];
+ if (newFocusElement) {
+ this._updateSearchIndex(index);
+ newFocusElement.setSearchRegex(this._searchRegex, WebInspector.highlightedCurrentSearchResultClassName);
+ newFocusElement.reveal();
+ } else {
+ this._updateSearchIndex(0);
+ }
+ }
- /**
- * @param {number} index
- */
- _updateSearchIndex: function(index)
- {
- this._currentSearchFocusIndex = index;
- if (!this._searchableView)
- return;
- this._searchableView.updateCurrentMatchIndex(index);
- },
+ /**
+ * @param {number} count
+ */
+ _updateSearchCount(count) {
+ if (!this._searchableView)
+ return;
+ this._searchableView.updateSearchMatchesCount(count);
+ }
- /**
- * @override
- */
- searchCanceled: function()
- {
- this._searchRegex = null;
- this._currentSearchTreeElements = [];
+ /**
+ * @param {number} index
+ */
+ _updateSearchIndex(index) {
+ this._currentSearchFocusIndex = index;
+ if (!this._searchableView)
+ return;
+ this._searchableView.updateCurrentMatchIndex(index);
+ }
- for (var element = this._treeOutline.rootElement(); element; element = element.traverseNextTreeElement(false)) {
- if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
- continue;
- element.revertHighlightChanges();
- }
- this._updateSearchCount(0);
- this._updateSearchIndex(0);
- },
+ /**
+ * @override
+ */
+ searchCanceled() {
+ this._searchRegex = null;
+ this._currentSearchTreeElements = [];
- /**
- * @override
- * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
- * @param {boolean} shouldJump
- * @param {boolean=} jumpBackwards
- */
- performSearch: function(searchConfig, shouldJump, jumpBackwards)
- {
- var newIndex = this._currentSearchFocusIndex;
- var previousSearchFocusElement = this._currentSearchTreeElements[newIndex];
- this.searchCanceled();
- this._searchRegex = searchConfig.toSearchRegex(true);
+ for (var element = this._treeOutline.rootElement(); element; element = element.traverseNextTreeElement(false)) {
+ if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
+ continue;
+ element.revertHighlightChanges();
+ }
+ this._updateSearchCount(0);
+ this._updateSearchIndex(0);
+ }
- for (var element = this._treeOutline.rootElement(); element; element = element.traverseNextTreeElement(false)) {
- if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
- continue;
- var hasMatch = element.setSearchRegex(this._searchRegex);
- if (hasMatch)
- this._currentSearchTreeElements.push(element);
- if (previousSearchFocusElement === element) {
- var currentIndex = this._currentSearchTreeElements.length - 1;
- if (hasMatch || jumpBackwards)
- newIndex = currentIndex;
- else
- newIndex = currentIndex + 1;
- }
- }
- this._updateSearchCount(this._currentSearchTreeElements.length);
+ /**
+ * @override
+ * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
+ * @param {boolean} shouldJump
+ * @param {boolean=} jumpBackwards
+ */
+ performSearch(searchConfig, shouldJump, jumpBackwards) {
+ var newIndex = this._currentSearchFocusIndex;
+ var previousSearchFocusElement = this._currentSearchTreeElements[newIndex];
+ this.searchCanceled();
+ this._searchRegex = searchConfig.toSearchRegex(true);
- if (!this._currentSearchTreeElements.length) {
- this._updateSearchIndex(0);
- return;
- }
- newIndex = mod(newIndex, this._currentSearchTreeElements.length);
+ for (var element = this._treeOutline.rootElement(); element; element = element.traverseNextTreeElement(false)) {
+ if (!(element instanceof WebInspector.ObjectPropertyTreeElement))
+ continue;
+ var hasMatch = element.setSearchRegex(this._searchRegex);
+ if (hasMatch)
+ this._currentSearchTreeElements.push(element);
+ if (previousSearchFocusElement === element) {
+ var currentIndex = this._currentSearchTreeElements.length - 1;
+ if (hasMatch || jumpBackwards)
+ newIndex = currentIndex;
+ else
+ newIndex = currentIndex + 1;
+ }
+ }
+ this._updateSearchCount(this._currentSearchTreeElements.length);
- this._jumpToMatch(newIndex);
- },
+ if (!this._currentSearchTreeElements.length) {
+ this._updateSearchIndex(0);
+ return;
+ }
+ newIndex = mod(newIndex, this._currentSearchTreeElements.length);
- /**
- * @override
- */
- jumpToNextSearchResult: function()
- {
- if (!this._currentSearchTreeElements.length)
- return;
- var newIndex = mod(this._currentSearchFocusIndex + 1, this._currentSearchTreeElements.length);
- this._jumpToMatch(newIndex);
- },
+ this._jumpToMatch(newIndex);
+ }
- /**
- * @override
- */
- jumpToPreviousSearchResult: function()
- {
- if (!this._currentSearchTreeElements.length)
- return;
- var newIndex = mod(this._currentSearchFocusIndex - 1, this._currentSearchTreeElements.length);
- this._jumpToMatch(newIndex);
- },
+ /**
+ * @override
+ */
+ jumpToNextSearchResult() {
+ if (!this._currentSearchTreeElements.length)
+ return;
+ var newIndex = mod(this._currentSearchFocusIndex + 1, this._currentSearchTreeElements.length);
+ this._jumpToMatch(newIndex);
+ }
- /**
- * @override
- * @return {boolean}
- */
- supportsCaseSensitiveSearch: function()
- {
- return true;
- },
+ /**
+ * @override
+ */
+ jumpToPreviousSearchResult() {
+ if (!this._currentSearchTreeElements.length)
+ return;
+ var newIndex = mod(this._currentSearchFocusIndex - 1, this._currentSearchTreeElements.length);
+ this._jumpToMatch(newIndex);
+ }
- /**
- * @override
- * @return {boolean}
- */
- supportsRegexSearch: function()
- {
- return true;
- },
+ /**
+ * @override
+ * @return {boolean}
+ */
+ supportsCaseSensitiveSearch() {
+ return true;
+ }
- __proto__: WebInspector.VBox.prototype
+ /**
+ * @override
+ * @return {boolean}
+ */
+ supportsRegexSearch() {
+ return true;
+ }
};
+
/**
- * @constructor
- * @param {*} data
- * @param {string} prefix
- * @param {string} suffix
+ * @unrestricted
*/
-WebInspector.ParsedJSON = function(data, prefix, suffix)
-{
+WebInspector.ParsedJSON = class {
+ /**
+ * @param {*} data
+ * @param {string} prefix
+ * @param {string} suffix
+ */
+ constructor(data, prefix, suffix) {
this.data = data;
this.prefix = prefix;
this.suffix = suffix;
+ }
};

Powered by Google App Engine
This is Rietveld 408576698