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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 } | 130 } |
131 | 131 |
132 /** | 132 /** |
133 * @param {?string=} description | 133 * @param {?string=} description |
134 * @param {boolean=} includePreview | 134 * @param {boolean=} includePreview |
135 * @param {string=} defaultName | 135 * @param {string=} defaultName |
136 * @return {!Element} valueElement | 136 * @return {!Element} valueElement |
137 */ | 137 */ |
138 static valueElementForFunctionDescription(description, includePreview, default Name) { | 138 static valueElementForFunctionDescription(description, includePreview, default Name) { |
139 var valueElement = createElementWithClass('span', 'object-value-function'); | 139 var valueElement = createElementWithClass('span', 'object-value-function'); |
140 var text = description.replace(/^function [gs]et /, 'function '); | 140 var text = description ? description.replace(/^function [gs]et /, 'function ') : ''; |
141 defaultName = defaultName || ''; | 141 defaultName = defaultName || ''; |
142 | 142 |
143 // This set of best-effort regular expressions captures common function desc riptions. | 143 // This set of best-effort regular expressions captures common function desc riptions. |
144 // Ideally, some parser would provide prefix, arguments, function body text separately. | 144 // Ideally, some parser would provide prefix, arguments, function body text separately. |
145 var isAsync = text.startsWith('async function '); | 145 var isAsync = text.startsWith('async function '); |
146 var isGenerator = text.startsWith('function* '); | 146 var isGenerator = text.startsWith('function* '); |
147 var isGeneratorShorthand = text.startsWith('*'); | 147 var isGeneratorShorthand = text.startsWith('*'); |
148 var isBasic = !isGenerator && text.startsWith('function '); | 148 var isBasic = !isGenerator && text.startsWith('function '); |
149 var isClass = text.startsWith('class ') || text.startsWith('class{'); | 149 var isClass = text.startsWith('class ') || text.startsWith('class{'); |
150 var firstArrowIndex = text.indexOf('=>'); | 150 var firstArrowIndex = text.indexOf('=>'); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 231 } |
232 | 232 |
233 /** | 233 /** |
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; |
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; |
245 var prefix; | |
246 var valueText; | |
247 var suffix; | |
248 if (wasThrown) { | |
249 prefix = '[Exception: '; | |
250 valueText = description; | |
251 suffix = ']'; | |
252 } else if (type === 'string' && typeof description === 'string') { | |
253 // Render \n as a nice unicode cr symbol. | |
254 prefix = '"'; | |
255 valueText = description.replace(/\n/g, '\u21B5'); | |
256 suffix = '"'; | |
257 } else if (type !== 'object' || subtype !== 'node') { | |
258 valueText = description; | |
259 } | |
260 | |
261 if (type === 'function') { | |
262 valueElement = Components.ObjectPropertiesSection.valueElementForFunctionD escription(description); | |
263 } else if (type !== 'number' || valueText.indexOf('e') === -1) { | |
264 valueElement.setTextContentTruncatedIfNeeded(valueText || ''); | |
265 if (prefix) | |
266 valueElement.insertBefore(createTextNode(prefix), valueElement.firstChil d); | |
267 if (suffix) | |
268 valueElement.createTextChild(suffix); | |
269 } else { | |
270 var numberParts = valueText.split('e'); | |
271 var mantissa = valueElement.createChild('span', 'object-value-scientific-n otation-mantissa'); | |
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'); | |
276 if (parentElement) // FIXME: do it in the caller. | |
277 parentElement.classList.add('hbox'); | |
278 } | |
279 | |
280 if (wasThrown) | |
281 valueElement.classList.add('error'); | |
282 if (subtype || type) | |
283 valueElement.classList.add('object-value-' + (subtype || type)); | |
284 | |
285 if (type === 'object' && subtype === 'node' && description) { | |
286 Components.DOMPresentationUtils.createSpansForNodeTitle(valueElement, desc ription); | |
287 valueElement.addEventListener('click', mouseClick, false); | |
288 valueElement.addEventListener('mousemove', mouseMove, false); | |
289 valueElement.addEventListener('mouseleave', mouseLeave, false); | |
290 } else { | |
291 valueElement.title = description || ''; | |
292 } | |
293 | |
294 if (type === 'object' && subtype === 'internal#location') { | 245 if (type === 'object' && subtype === 'internal#location') { |
295 var rawLocation = value.debuggerModel().createRawLocationByScriptId( | 246 var rawLocation = value.debuggerModel().createRawLocationByScriptId( |
296 value.value.scriptId, value.value.lineNumber, value.value.columnNumber ); | 247 value.value.scriptId, value.value.lineNumber, value.value.columnNumber ); |
297 if (rawLocation && linkifier) | 248 if (rawLocation && linkifier) |
298 return linkifier.linkifyRawLocation(rawLocation, ''); | 249 return linkifier.linkifyRawLocation(rawLocation, ''); |
299 valueElement.textContent = '<unknown>'; | 250 valueElement = createUnknownInternalLocationElement(); |
251 valueElement.title = description; | |
252 } else if (type === 'string' && typeof description === 'string') { | |
253 valueElement = createStringElement(); | |
254 valueElement.title = description; | |
dgozman
2017/01/09 23:58:52
Let's set title inside of respective functions.
luoe
2017/01/10 22:22:11
Done.
| |
255 } else if (type === 'function') { | |
256 valueElement = Components.ObjectPropertiesSection.valueElementForFunctionD escription(description); | |
257 valueElement.title = description; | |
258 } else if (type === 'object' && subtype === 'node' && description) { | |
259 valueElement = createNodeElement(); | |
260 } else if (type === 'number' && description && description.indexOf('e') !== -1) { | |
261 valueElement = createNumberWithExponentElement(); | |
262 valueElement.title = description; | |
263 if (parentElement) // FIXME: do it in the caller. | |
264 parentElement.classList.add('hbox'); | |
265 } else { | |
266 valueElement = createElementWithClass('span', 'object-value-' + (subtype | | type)); | |
267 valueElement.setTextContentTruncatedIfNeeded(description); | |
268 valueElement.title = description; | |
dgozman
2017/01/09 23:58:52
description || ''
luoe
2017/01/10 22:22:11
Done.
| |
300 } | 269 } |
301 | 270 |
302 function mouseMove() { | 271 if (wasThrown) { |
303 SDK.DOMModel.highlightObjectAsDOMNode(value); | 272 var wrapperElement = createElementWithClass('span', 'error value'); |
273 wrapperElement.createTextChild('[' + Common.UIString('Exception') + ': '); | |
274 wrapperElement.appendChild(valueElement); | |
275 wrapperElement.createTextChild(']'); | |
276 return wrapperElement; | |
304 } | 277 } |
278 valueElement.classList.add('value'); | |
dgozman
2017/01/09 23:58:52
Don't you need this in case of wasThrown?
luoe
2017/01/10 22:22:11
It's covered in line 272 on the wrapper.
| |
279 return valueElement; | |
305 | 280 |
306 function mouseLeave() { | 281 /** |
307 SDK.DOMModel.hideDOMNodeHighlight(); | 282 * @return {!Element} |
283 */ | |
284 function createUnknownInternalLocationElement() { | |
285 var valueElement = createElementWithClass('span'); | |
286 valueElement.textContent = '<' + Common.UIString('unknown') + '>'; | |
287 return valueElement; | |
308 } | 288 } |
309 | 289 |
310 /** | 290 /** |
311 * @param {!Event} event | 291 * @return {!Element} |
312 */ | 292 */ |
313 function mouseClick(event) { | 293 function createStringElement() { |
314 Common.Revealer.reveal(value); | 294 var valueElement = createElementWithClass('span', 'object-value-string'); |
315 event.consume(true); | 295 valueElement.createChild('span', 'object-value-string-quote').textContent = '"'; |
296 valueElement.createTextChild('').setTextContentTruncatedIfNeeded(descripti on.replace(/\n/g, '\u21B5')); | |
297 valueElement.createChild('span', 'object-value-string-quote').textContent = '"'; | |
298 return valueElement; | |
316 } | 299 } |
317 | 300 |
318 return valueElement; | 301 /** |
302 * @return {!Element} | |
303 */ | |
304 function createNodeElement() { | |
305 var valueElement = createElementWithClass('span', 'object-value-node'); | |
306 Components.DOMPresentationUtils.createSpansForNodeTitle(valueElement, /** @type {string} */ (description)); | |
307 valueElement.addEventListener('click', event => { | |
308 Common.Revealer.reveal(value); | |
309 event.consume(true); | |
310 }, false); | |
311 valueElement.addEventListener('mousemove', () => SDK.DOMModel.highlightObj ectAsDOMNode(value), false); | |
312 valueElement.addEventListener('mouseleave', SDK.DOMModel.hideDOMNodeHighli ght, false); | |
dgozman
2017/01/09 23:58:52
() => SDK.DOMModel.hideDOMNodeHighlight()
luoe
2017/01/10 22:22:11
Done.
| |
313 return valueElement; | |
314 } | |
315 | |
316 /** | |
317 * @return {!Element} | |
318 */ | |
319 function createNumberWithExponentElement() { | |
320 var valueElement = createElementWithClass('span', 'object-value-number'); | |
321 var numberParts = description.split('e'); | |
322 valueElement.createChild('span', 'object-value-scientific-notation-mantiss a').textContent = numberParts[0]; | |
323 valueElement.createChild('span', 'object-value-scientific-notation-exponen t').textContent = 'e' + numberParts[1]; | |
324 valueElement.classList.add('object-value-scientific-notation-number'); | |
325 return valueElement; | |
326 } | |
319 } | 327 } |
320 | 328 |
321 /** | 329 /** |
322 * @param {!SDK.RemoteObject} object | 330 * @param {!SDK.RemoteObject} object |
323 * @return {boolean} | 331 * @return {boolean} |
324 */ | 332 */ |
325 static _needsAlternateTitle(object) { | 333 static _needsAlternateTitle(object) { |
326 return object && object.hasChildren && !object.customPreview() && object.sub type !== 'node' && | 334 return object && object.hasChildren && !object.customPreview() && object.sub type !== 'node' && |
327 object.type !== 'function' && (object.type !== 'object' || object.previe w); | 335 object.type !== 'function' && (object.type !== 'object' || object.previe w); |
328 } | 336 } |
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 } | 1365 } |
1358 var treeOutlineId = treeElement.treeOutline[Components.ObjectPropertiesSecti onExpandController._treeOutlineId]; | 1366 var treeOutlineId = treeElement.treeOutline[Components.ObjectPropertiesSecti onExpandController._treeOutlineId]; |
1359 result = treeOutlineId + (result ? ':' + result : ''); | 1367 result = treeOutlineId + (result ? ':' + result : ''); |
1360 treeElement[Components.ObjectPropertiesSectionExpandController._cachedPathSy mbol] = result; | 1368 treeElement[Components.ObjectPropertiesSectionExpandController._cachedPathSy mbol] = result; |
1361 return result; | 1369 return result; |
1362 } | 1370 } |
1363 }; | 1371 }; |
1364 | 1372 |
1365 Components.ObjectPropertiesSectionExpandController._cachedPathSymbol = Symbol('c achedPath'); | 1373 Components.ObjectPropertiesSectionExpandController._cachedPathSymbol = Symbol('c achedPath'); |
1366 Components.ObjectPropertiesSectionExpandController._treeOutlineId = Symbol('tree OutlineId'); | 1374 Components.ObjectPropertiesSectionExpandController._treeOutlineId = Symbol('tree OutlineId'); |
OLD | NEW |