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 23 matching lines...) Expand all Loading... |
174 const maxArrowFunctionCharacterLength = 60; | 174 const maxArrowFunctionCharacterLength = 60; |
175 var abbreviation = text; | 175 var abbreviation = text; |
176 if (defaultName) | 176 if (defaultName) |
177 abbreviation = defaultName + '()'; | 177 abbreviation = defaultName + '()'; |
178 else if (text.length > maxArrowFunctionCharacterLength) | 178 else if (text.length > maxArrowFunctionCharacterLength) |
179 abbreviation = text.substring(0, firstArrowIndex + 2) + ' {\u2026}'; | 179 abbreviation = text.substring(0, firstArrowIndex + 2) + ' {\u2026}'; |
180 addElements('', text, abbreviation); | 180 addElements('', text, abbreviation); |
181 } else { | 181 } else { |
182 addElements('function', text, nameAndArguments(text)); | 182 addElements('function', text, nameAndArguments(text)); |
183 } | 183 } |
| 184 valueElement.title = description || ''; |
184 return valueElement; | 185 return valueElement; |
185 | 186 |
186 /** | 187 /** |
187 * @param {string} contents | 188 * @param {string} contents |
188 * @return {string} | 189 * @return {string} |
189 */ | 190 */ |
190 function nameAndArguments(contents) { | 191 function nameAndArguments(contents) { |
191 var startOfArgumentsIndex = contents.indexOf('('); | 192 var startOfArgumentsIndex = contents.indexOf('('); |
192 var endOfArgumentsMatch = contents.match(/\)\s*{/); | 193 var endOfArgumentsMatch = contents.match(/\)\s*{/); |
193 if (startOfArgumentsIndex !== -1 && endOfArgumentsMatch && endOfArgumentsM
atch.index > startOfArgumentsIndex) { | 194 if (startOfArgumentsIndex !== -1 && endOfArgumentsMatch && endOfArgumentsM
atch.index > startOfArgumentsIndex) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 232 } |
232 | 233 |
233 /** | 234 /** |
234 * @param {!SDK.RemoteObject} value | 235 * @param {!SDK.RemoteObject} value |
235 * @param {boolean} wasThrown | 236 * @param {boolean} wasThrown |
236 * @param {!Element=} parentElement | 237 * @param {!Element=} parentElement |
237 * @param {!Components.Linkifier=} linkifier | 238 * @param {!Components.Linkifier=} linkifier |
238 * @return {!Element} | 239 * @return {!Element} |
239 */ | 240 */ |
240 static createValueElement(value, wasThrown, parentElement, linkifier) { | 241 static createValueElement(value, wasThrown, parentElement, linkifier) { |
241 var valueElement = createElementWithClass('span', 'value'); | 242 var valueElement; |
242 var type = value.type; | 243 var type = value.type; |
243 var subtype = value.subtype; | 244 var subtype = value.subtype; |
244 var description = value.description; | 245 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') { | 246 if (type === 'object' && subtype === 'internal#location') { |
295 var rawLocation = value.debuggerModel().createRawLocationByScriptId( | 247 var rawLocation = value.debuggerModel().createRawLocationByScriptId( |
296 value.value.scriptId, value.value.lineNumber, value.value.columnNumber
); | 248 value.value.scriptId, value.value.lineNumber, value.value.columnNumber
); |
297 if (rawLocation && linkifier) | 249 if (rawLocation && linkifier) |
298 return linkifier.linkifyRawLocation(rawLocation, ''); | 250 return linkifier.linkifyRawLocation(rawLocation, ''); |
299 valueElement.textContent = '<unknown>'; | 251 valueElement = createUnknownInternalLocationElement(); |
| 252 } else if (type === 'string' && typeof description === 'string') { |
| 253 valueElement = createStringElement(); |
| 254 } else if (type === 'function') { |
| 255 valueElement = Components.ObjectPropertiesSection.valueElementForFunctionD
escription(description); |
| 256 } else if (type === 'object' && subtype === 'node' && description) { |
| 257 valueElement = createNodeElement(); |
| 258 } else if (type === 'number' && description && description.indexOf('e') !==
-1) { |
| 259 valueElement = createNumberWithExponentElement(); |
| 260 if (parentElement) // FIXME: do it in the caller. |
| 261 parentElement.classList.add('hbox'); |
| 262 } else { |
| 263 valueElement = createElementWithClass('span', 'object-value-' + (subtype |
| type)); |
| 264 valueElement.setTextContentTruncatedIfNeeded(description); |
| 265 valueElement.title = description || ''; |
300 } | 266 } |
301 | 267 |
302 function mouseMove() { | 268 if (wasThrown) { |
303 SDK.DOMModel.highlightObjectAsDOMNode(value); | 269 var wrapperElement = createElementWithClass('span', 'error value'); |
| 270 wrapperElement.createTextChild('[' + Common.UIString('Exception') + ': '); |
| 271 wrapperElement.appendChild(valueElement); |
| 272 wrapperElement.createTextChild(']'); |
| 273 return wrapperElement; |
304 } | 274 } |
| 275 valueElement.classList.add('value'); |
| 276 return valueElement; |
305 | 277 |
306 function mouseLeave() { | 278 /** |
307 SDK.DOMModel.hideDOMNodeHighlight(); | 279 * @return {!Element} |
| 280 */ |
| 281 function createUnknownInternalLocationElement() { |
| 282 var valueElement = createElementWithClass('span'); |
| 283 valueElement.textContent = '<' + Common.UIString('unknown') + '>'; |
| 284 valueElement.title = description || ''; |
| 285 return valueElement; |
308 } | 286 } |
309 | 287 |
310 /** | 288 /** |
311 * @param {!Event} event | 289 * @return {!Element} |
312 */ | 290 */ |
313 function mouseClick(event) { | 291 function createStringElement() { |
314 Common.Revealer.reveal(value); | 292 var valueElement = createElementWithClass('span', 'object-value-string'); |
315 event.consume(true); | 293 valueElement.createChild('span', 'object-value-string-quote').textContent
= '"'; |
| 294 valueElement.createTextChild('').setTextContentTruncatedIfNeeded(descripti
on.replace(/\n/g, '\u21B5')); |
| 295 valueElement.createChild('span', 'object-value-string-quote').textContent
= '"'; |
| 296 valueElement.title = description || ''; |
| 297 return valueElement; |
316 } | 298 } |
317 | 299 |
318 return valueElement; | 300 /** |
| 301 * @return {!Element} |
| 302 */ |
| 303 function createNodeElement() { |
| 304 var valueElement = createElementWithClass('span', 'object-value-node'); |
| 305 Components.DOMPresentationUtils.createSpansForNodeTitle(valueElement, /**
@type {string} */ (description)); |
| 306 valueElement.addEventListener('click', event => { |
| 307 Common.Revealer.reveal(value); |
| 308 event.consume(true); |
| 309 }, false); |
| 310 valueElement.addEventListener('mousemove', () => SDK.DOMModel.highlightObj
ectAsDOMNode(value), false); |
| 311 valueElement.addEventListener('mouseleave', () => SDK.DOMModel.hideDOMNode
Highlight(), false); |
| 312 return valueElement; |
| 313 } |
| 314 |
| 315 /** |
| 316 * @return {!Element} |
| 317 */ |
| 318 function createNumberWithExponentElement() { |
| 319 var valueElement = createElementWithClass('span', 'object-value-number'); |
| 320 var numberParts = description.split('e'); |
| 321 valueElement.createChild('span', 'object-value-scientific-notation-mantiss
a').textContent = numberParts[0]; |
| 322 valueElement.createChild('span', 'object-value-scientific-notation-exponen
t').textContent = 'e' + numberParts[1]; |
| 323 valueElement.classList.add('object-value-scientific-notation-number'); |
| 324 valueElement.title = description || ''; |
| 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 |