OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 * @param {!SDK.RemoteObject} value | 234 * @param {!SDK.RemoteObject} value |
235 * @param {boolean} wasThrown | 235 * @param {boolean} wasThrown |
236 * @param {!Element=} parentElement | 236 * @param {!Element=} parentElement |
237 * @param {!Components.Linkifier=} linkifier | 237 * @param {!Components.Linkifier=} linkifier |
238 * @return {!Element} | 238 * @return {!Element} |
239 */ | 239 */ |
240 static createValueElement(value, wasThrown, parentElement, linkifier) { | 240 static createValueElement(value, wasThrown, parentElement, linkifier) { |
241 var valueElement = createElementWithClass('span', 'value'); | 241 var valueElement = createElementWithClass('span', 'value'); |
242 var type = value.type; | 242 var type = value.type; |
243 var subtype = value.subtype; | 243 var subtype = value.subtype; |
244 var description = value.description; | 244 var description = value.description || ''; |
dgozman
2016/12/28 00:17:44
Let's not do || ''
| |
245 var prefix; | 245 var isInternalLocation = type === 'object' && subtype === 'internal#location '; |
246 var valueText; | 246 var isString = type === 'string' && typeof description === 'string'; |
247 var suffix; | 247 var isNode = type === 'object' && subtype === 'node' && description; |
248 if (wasThrown) { | 248 var isNumberWithExponent = type === 'number' && description.indexOf('e') !== -1; |
dgozman
2016/12/28 00:17:44
Let's structure it differently:
var valueElement
luoe
2017/01/03 21:52:31
Done.
| |
249 prefix = '[Exception: '; | 249 if (isInternalLocation) { |
250 valueText = description; | 250 var rawLocation = value.debuggerModel().createRawLocationByScriptId( |
251 suffix = ']'; | 251 value.value.scriptId, value.value.lineNumber, value.value.columnNumber ); |
252 } else if (type === 'string' && typeof description === 'string') { | 252 // Return early if there is a linkified raw location. |
253 // Render \n as a nice unicode cr symbol. | 253 if (rawLocation && linkifier) |
254 prefix = '"'; | 254 return linkifier.linkifyRawLocation(rawLocation, ''); |
255 valueText = description.replace(/\n/g, '\u21B5'); | 255 valueElement.textContent = '<unknown>'; |
256 suffix = '"'; | 256 } else if (isString) { |
257 } else if (type !== 'object' || subtype !== 'node') { | 257 valueElement.createChild('span', 'object-value-string-quote').textContent = '"'; |
258 valueText = description; | 258 valueElement.createTextChild('').setTextContentTruncatedIfNeeded(descripti on.replace(/\n/g, '\u21B5')); |
259 } | 259 valueElement.createChild('span', 'object-value-string-quote').textContent = '"'; |
260 | 260 } else if (type === 'function') { |
261 if (type === 'function') { | |
262 valueElement = Components.ObjectPropertiesSection.valueElementForFunctionD escription(description); | 261 valueElement = Components.ObjectPropertiesSection.valueElementForFunctionD escription(description); |
263 } else if (type !== 'number' || valueText.indexOf('e') === -1) { | 262 } else if (isNode) { |
264 valueElement.setTextContentTruncatedIfNeeded(valueText || ''); | 263 Components.DOMPresentationUtils.createSpansForNodeTitle(valueElement, /** @type {string} */ (description)); |
265 if (prefix) | 264 valueElement.addEventListener('click', mouseClick, false); |
dgozman
2016/12/28 00:17:44
Inline the listeners.
luoe
2017/01/03 21:52:30
Done.
| |
266 valueElement.insertBefore(createTextNode(prefix), valueElement.firstChil d); | 265 valueElement.addEventListener('mousemove', mouseMove, false); |
267 if (suffix) | 266 valueElement.addEventListener('mouseleave', mouseLeave, false); |
268 valueElement.createTextChild(suffix); | 267 } else if (isNumberWithExponent) { |
269 } else { | 268 var numberParts = description.split('e'); |
270 var numberParts = valueText.split('e'); | 269 valueElement.createChild('span', 'object-value-scientific-notation-mantiss a').textContent = numberParts[0]; |
271 var mantissa = valueElement.createChild('span', 'object-value-scientific-n otation-mantissa'); | 270 valueElement.createChild('span', 'object-value-scientific-notation-exponen t').textContent = 'e' + numberParts[1]; |
272 mantissa.textContent = numberParts[0]; | |
273 var exponent = valueElement.createChild('span', 'object-value-scientific-n otation-exponent'); | |
274 exponent.textContent = 'e' + numberParts[1]; | |
275 valueElement.classList.add('object-value-scientific-notation-number'); | 271 valueElement.classList.add('object-value-scientific-notation-number'); |
276 if (parentElement) // FIXME: do it in the caller. | 272 if (parentElement) // FIXME: do it in the caller. |
277 parentElement.classList.add('hbox'); | 273 parentElement.classList.add('hbox'); |
274 } else { | |
275 valueElement.setTextContentTruncatedIfNeeded(description); | |
278 } | 276 } |
279 | 277 |
280 if (wasThrown) | 278 if (!isNode) |
281 valueElement.classList.add('error'); | 279 valueElement.title = description; |
dgozman
2016/12/28 00:17:44
Let's move these into the cases.
luoe
2017/01/03 21:52:30
Done.
| |
282 if (subtype || type) | 280 if (subtype || type) |
283 valueElement.classList.add('object-value-' + (subtype || type)); | 281 valueElement.classList.add('object-value-' + (subtype || type)); |
284 | 282 if (wasThrown) { |
dgozman
2016/12/28 00:17:44
Let's do at the start:
if (wasThrown) {
valueEle
luoe
2017/01/03 21:52:30
Done.
| |
285 if (type === 'object' && subtype === 'node' && description) { | 283 valueElement.classList.add('error'); |
286 Components.DOMPresentationUtils.createSpansForNodeTitle(valueElement, desc ription); | 284 valueElement.insertBefore(createTextNode('[Exception: '), valueElement.fir stChild); |
287 valueElement.addEventListener('click', mouseClick, false); | 285 valueElement.createTextChild(']'); |
288 valueElement.addEventListener('mousemove', mouseMove, false); | |
289 valueElement.addEventListener('mouseleave', mouseLeave, false); | |
290 } else { | |
291 valueElement.title = description || ''; | |
292 } | 286 } |
293 | 287 return valueElement; |
294 if (type === 'object' && subtype === 'internal#location') { | |
295 var rawLocation = value.debuggerModel().createRawLocationByScriptId( | |
296 value.value.scriptId, value.value.lineNumber, value.value.columnNumber ); | |
297 if (rawLocation && linkifier) | |
298 return linkifier.linkifyRawLocation(rawLocation, ''); | |
299 valueElement.textContent = '<unknown>'; | |
300 } | |
301 | 288 |
302 function mouseMove() { | 289 function mouseMove() { |
303 SDK.DOMModel.highlightObjectAsDOMNode(value); | 290 SDK.DOMModel.highlightObjectAsDOMNode(value); |
304 } | 291 } |
305 | 292 |
306 function mouseLeave() { | 293 function mouseLeave() { |
307 SDK.DOMModel.hideDOMNodeHighlight(); | 294 SDK.DOMModel.hideDOMNodeHighlight(); |
308 } | 295 } |
309 | 296 |
310 /** | 297 /** |
311 * @param {!Event} event | 298 * @param {!Event} event |
312 */ | 299 */ |
313 function mouseClick(event) { | 300 function mouseClick(event) { |
314 Common.Revealer.reveal(value); | 301 Common.Revealer.reveal(value); |
315 event.consume(true); | 302 event.consume(true); |
316 } | 303 } |
317 | |
318 return valueElement; | |
319 } | 304 } |
320 | 305 |
321 /** | 306 /** |
322 * @param {!SDK.RemoteObject} object | 307 * @param {!SDK.RemoteObject} object |
323 * @return {boolean} | 308 * @return {boolean} |
324 */ | 309 */ |
325 static _needsAlternateTitle(object) { | 310 static _needsAlternateTitle(object) { |
326 return object && object.hasChildren && !object.customPreview() && object.sub type !== 'node' && | 311 return object && object.hasChildren && !object.customPreview() && object.sub type !== 'node' && |
327 object.type !== 'function' && (object.type !== 'object' || object.previe w); | 312 object.type !== 'function' && (object.type !== 'object' || object.previe w); |
328 } | 313 } |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 } | 1342 } |
1358 var treeOutlineId = treeElement.treeOutline[Components.ObjectPropertiesSecti onExpandController._treeOutlineId]; | 1343 var treeOutlineId = treeElement.treeOutline[Components.ObjectPropertiesSecti onExpandController._treeOutlineId]; |
1359 result = treeOutlineId + (result ? ':' + result : ''); | 1344 result = treeOutlineId + (result ? ':' + result : ''); |
1360 treeElement[Components.ObjectPropertiesSectionExpandController._cachedPathSy mbol] = result; | 1345 treeElement[Components.ObjectPropertiesSectionExpandController._cachedPathSy mbol] = result; |
1361 return result; | 1346 return result; |
1362 } | 1347 } |
1363 }; | 1348 }; |
1364 | 1349 |
1365 Components.ObjectPropertiesSectionExpandController._cachedPathSymbol = Symbol('c achedPath'); | 1350 Components.ObjectPropertiesSectionExpandController._cachedPathSymbol = Symbol('c achedPath'); |
1366 Components.ObjectPropertiesSectionExpandController._treeOutlineId = Symbol('tree OutlineId'); | 1351 Components.ObjectPropertiesSectionExpandController._treeOutlineId = Symbol('tree OutlineId'); |
OLD | NEW |