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

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

Issue 2440953003: DevTools: use semicolons after each statement. (Closed)
Patch Set: rebaseline 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 /** @type {?WebInspector.SearchableView} */ 43 /** @type {?WebInspector.SearchableView} */
44 this._searchableView; 44 this._searchableView;
45 /** @type {!WebInspector.ObjectPropertiesSection} */ 45 /** @type {!WebInspector.ObjectPropertiesSection} */
46 this._treeOutline; 46 this._treeOutline;
47 /** @type {number} */ 47 /** @type {number} */
48 this._currentSearchFocusIndex = 0; 48 this._currentSearchFocusIndex = 0;
49 /** @type {!Array.<!TreeElement>} */ 49 /** @type {!Array.<!TreeElement>} */
50 this._currentSearchTreeElements = []; 50 this._currentSearchTreeElements = [];
51 /** @type {?RegExp} */ 51 /** @type {?RegExp} */
52 this._searchRegex = null; 52 this._searchRegex = null;
53 } 53 };
54 54
55 /** 55 /**
56 * @param {!WebInspector.ParsedJSON} parsedJSON 56 * @param {!WebInspector.ParsedJSON} parsedJSON
57 * @return {!WebInspector.SearchableView} 57 * @return {!WebInspector.SearchableView}
58 */ 58 */
59 WebInspector.JSONView.createSearchableView = function(parsedJSON) 59 WebInspector.JSONView.createSearchableView = function(parsedJSON)
60 { 60 {
61 var jsonView = new WebInspector.JSONView(parsedJSON); 61 var jsonView = new WebInspector.JSONView(parsedJSON);
62 var searchableView = new WebInspector.SearchableView(jsonView); 62 var searchableView = new WebInspector.SearchableView(jsonView);
63 searchableView.setPlaceholder(WebInspector.UIString("Find")); 63 searchableView.setPlaceholder(WebInspector.UIString("Find"));
64 jsonView._searchableView = searchableView; 64 jsonView._searchableView = searchableView;
65 jsonView.show(searchableView.element); 65 jsonView.show(searchableView.element);
66 jsonView.element.setAttribute("tabIndex", 0); 66 jsonView.element.setAttribute("tabIndex", 0);
67 return searchableView; 67 return searchableView;
68 } 68 };
69 69
70 /** 70 /**
71 * @param {?string} text 71 * @param {?string} text
72 * @return {!Promise<?WebInspector.ParsedJSON>} 72 * @return {!Promise<?WebInspector.ParsedJSON>}
73 */ 73 */
74 WebInspector.JSONView.parseJSON = function(text) 74 WebInspector.JSONView.parseJSON = function(text)
75 { 75 {
76 var returnObj = null; 76 var returnObj = null;
77 if (text) 77 if (text)
78 returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (te xt)); 78 returnObj = WebInspector.JSONView._extractJSON(/** @type {string} */ (te xt));
79 if (!returnObj) 79 if (!returnObj)
80 return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null)); 80 return Promise.resolve(/** @type {?WebInspector.ParsedJSON} */ (null));
81 return WebInspector.formatterWorkerPool.runTask("relaxedJSONParser", {conten t: returnObj.data}) 81 return WebInspector.formatterWorkerPool.runTask("relaxedJSONParser", {conten t: returnObj.data})
82 .then(handleReturnedJSON) 82 .then(handleReturnedJSON);
83 83
84 /** 84 /**
85 * @param {?MessageEvent} event 85 * @param {?MessageEvent} event
86 * @return {?WebInspector.ParsedJSON} 86 * @return {?WebInspector.ParsedJSON}
87 */ 87 */
88 function handleReturnedJSON(event) 88 function handleReturnedJSON(event)
89 { 89 {
90 if (!event || !event.data) 90 if (!event || !event.data)
91 return null; 91 return null;
92 returnObj.data = event.data; 92 returnObj.data = event.data;
93 return returnObj; 93 return returnObj;
94 } 94 }
95 } 95 };
96 96
97 /** 97 /**
98 * @param {string} text 98 * @param {string} text
99 * @return {?WebInspector.ParsedJSON} 99 * @return {?WebInspector.ParsedJSON}
100 */ 100 */
101 WebInspector.JSONView._extractJSON = function(text) 101 WebInspector.JSONView._extractJSON = function(text)
102 { 102 {
103 // Do not treat HTML as JSON. 103 // Do not treat HTML as JSON.
104 if (text.startsWith("<")) 104 if (text.startsWith("<"))
105 return null; 105 return null;
106 var inner = WebInspector.JSONView._findBrackets(text, "{", "}"); 106 var inner = WebInspector.JSONView._findBrackets(text, "{", "}");
107 var inner2 = WebInspector.JSONView._findBrackets(text, "[", "]"); 107 var inner2 = WebInspector.JSONView._findBrackets(text, "[", "]");
108 inner = inner2.length > inner.length ? inner2 : inner; 108 inner = inner2.length > inner.length ? inner2 : inner;
109 109
110 // Return on blank payloads or on payloads significantly smaller than origin al text. 110 // Return on blank payloads or on payloads significantly smaller than origin al text.
111 if (inner.length === -1 || text.length - inner.length > 80) 111 if (inner.length === -1 || text.length - inner.length > 80)
112 return null; 112 return null;
113 113
114 var prefix = text.substring(0, inner.start); 114 var prefix = text.substring(0, inner.start);
115 var suffix = text.substring(inner.end + 1); 115 var suffix = text.substring(inner.end + 1);
116 text = text.substring(inner.start, inner.end + 1); 116 text = text.substring(inner.start, inner.end + 1);
117 117
118 // Only process valid JSONP. 118 // Only process valid JSONP.
119 if (suffix.trim().length && !(suffix.trim().startsWith(")") && prefix.trim() .endsWith("("))) 119 if (suffix.trim().length && !(suffix.trim().startsWith(")") && prefix.trim() .endsWith("(")))
120 return null; 120 return null;
121 121
122 return new WebInspector.ParsedJSON(text, prefix, suffix); 122 return new WebInspector.ParsedJSON(text, prefix, suffix);
123 } 123 };
124 124
125 /** 125 /**
126 * @param {string} text 126 * @param {string} text
127 * @param {string} open 127 * @param {string} open
128 * @param {string} close 128 * @param {string} close
129 * @return {{start: number, end: number, length: number}} 129 * @return {{start: number, end: number, length: number}}
130 */ 130 */
131 WebInspector.JSONView._findBrackets = function(text, open, close) 131 WebInspector.JSONView._findBrackets = function(text, open, close)
132 { 132 {
133 var start = text.indexOf(open); 133 var start = text.indexOf(open);
134 var end = text.lastIndexOf(close); 134 var end = text.lastIndexOf(close);
135 var length = end - start - 1; 135 var length = end - start - 1;
136 if (start === -1 || end === -1 || end < start) 136 if (start === -1 || end === -1 || end < start)
137 length = -1; 137 length = -1;
138 return {start: start, end: end, length: length}; 138 return {start: start, end: end, length: length};
139 } 139 };
140 140
141 WebInspector.JSONView.prototype = { 141 WebInspector.JSONView.prototype = {
142 wasShown: function() 142 wasShown: function()
143 { 143 {
144 this._initialize(); 144 this._initialize();
145 }, 145 },
146 146
147 _initialize: function() 147 _initialize: function()
148 { 148 {
149 if (this._initialized) 149 if (this._initialized)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 /** 289 /**
290 * @override 290 * @override
291 * @return {boolean} 291 * @return {boolean}
292 */ 292 */
293 supportsRegexSearch: function() 293 supportsRegexSearch: function()
294 { 294 {
295 return true; 295 return true;
296 }, 296 },
297 297
298 __proto__: WebInspector.VBox.prototype 298 __proto__: WebInspector.VBox.prototype
299 } 299 };
300 300
301 /** 301 /**
302 * @constructor 302 * @constructor
303 * @param {*} data 303 * @param {*} data
304 * @param {string} prefix 304 * @param {string} prefix
305 * @param {string} suffix 305 * @param {string} suffix
306 */ 306 */
307 WebInspector.ParsedJSON = function(data, prefix, suffix) 307 WebInspector.ParsedJSON = function(data, prefix, suffix)
308 { 308 {
309 this.data = data; 309 this.data = data;
310 this.prefix = prefix; 310 this.prefix = prefix;
311 this.suffix = suffix; 311 this.suffix = suffix;
312 } 312 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698