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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sources/JavaScriptSourceFrame.js

Issue 2505413002: [DevTools] Prepare JavaScriptSourceFrame for multiple breakpoints per line (Closed)
Patch Set: addressed all comments 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 this.uiSourceCode().addEventListener( 61 this.uiSourceCode().addEventListener(
62 Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappin gChanged, this); 62 Workspace.UISourceCode.Events.SourceMappingChanged, this._onSourceMappin gChanged, this);
63 this.uiSourceCode().addEventListener( 63 this.uiSourceCode().addEventListener(
64 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this); 64 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this);
65 this.uiSourceCode().addEventListener( 65 this.uiSourceCode().addEventListener(
66 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this); 66 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this);
67 this.uiSourceCode().addEventListener( 67 this.uiSourceCode().addEventListener(
68 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this); 68 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this);
69 69
70 /** @type {!Set<!Sources.JavaScriptSourceFrame.BreakpointDecoration>} */
71 this._breakpointDecorations = new Set();
72
70 /** @type {!Map.<!SDK.Target, !Bindings.ResourceScriptFile>}*/ 73 /** @type {!Map.<!SDK.Target, !Bindings.ResourceScriptFile>}*/
71 this._scriptFileForTarget = new Map(); 74 this._scriptFileForTarget = new Map();
72 var targets = SDK.targetManager.targets(); 75 var targets = SDK.targetManager.targets();
73 for (var i = 0; i < targets.length; ++i) { 76 for (var i = 0; i < targets.length; ++i) {
74 var scriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(uiSourceCode , targets[i]); 77 var scriptFile = Bindings.debuggerWorkspaceBinding.scriptFile(uiSourceCode , targets[i]);
75 if (scriptFile) 78 if (scriptFile)
76 this._updateScriptFile(targets[i]); 79 this._updateScriptFile(targets[i]);
77 } 80 }
78 81
79 if (this._scriptFileForTarget.size || uiSourceCode.extension() === 'js' || 82 if (this._scriptFileForTarget.size || uiSourceCode.extension() === 'js' ||
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 */ 222 */
220 willHide() { 223 willHide() {
221 super.willHide(); 224 super.willHide();
222 this._popoverHelper.hidePopover(); 225 this._popoverHelper.hidePopover();
223 } 226 }
224 227
225 /** 228 /**
226 * @override 229 * @override
227 */ 230 */
228 onUISourceCodeContentChanged() { 231 onUISourceCodeContentChanged() {
229 this._removeAllBreakpoints(); 232 for (var decoration of this._breakpointDecorations)
233 decoration.breakpoint.remove();
230 super.onUISourceCodeContentChanged(); 234 super.onUISourceCodeContentChanged();
231 } 235 }
232 236
233 /** 237 /**
234 * @override 238 * @override
235 */ 239 */
236 onTextChanged(oldRange, newRange) { 240 onTextChanged(oldRange, newRange) {
237 this._scriptsPanel.updateLastModificationTime(); 241 this._scriptsPanel.updateLastModificationTime();
238 super.onTextChanged(oldRange, newRange); 242 super.onTextChanged(oldRange, newRange);
239 if (this._compiler) 243 if (this._compiler)
240 this._compiler.scheduleCompile(); 244 this._compiler.scheduleCompile();
241 } 245 }
242 246
243 /** 247 /**
244 * @override 248 * @override
245 * @return {!Promise} 249 * @return {!Promise}
246 */ 250 */
247 populateLineGutterContextMenu(contextMenu, lineNumber) { 251 populateLineGutterContextMenu(contextMenu, lineNumber) {
248 /** 252 /**
249 * @this {Sources.JavaScriptSourceFrame} 253 * @this {Sources.JavaScriptSourceFrame}
250 */ 254 */
251 function populate(resolve, reject) { 255 function populate(resolve, reject) {
252 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0); 256 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0);
253 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation); 257 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation);
254 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCod e(), lineNumber); 258 var breakpoints = this._lineBreakpointDecorations(lineNumber).map(decorati on => decoration.breakpoint);
255 if (!breakpoints.length) { 259 if (!breakpoints.length) {
256 // This row doesn't have a breakpoint: We want to show Add Breakpoint an d Add and Edit Breakpoint. 260 // This row doesn't have a breakpoint: We want to show Add Breakpoint an d Add and Edit Breakpoint.
257 contextMenu.appendItem( 261 contextMenu.appendItem(
258 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true)); 262 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true));
259 contextMenu.appendItem( 263 contextMenu.appendItem(
260 Common.UIString('Add conditional breakpoint'), this._editBreakpoint Condition.bind(this, lineNumber)); 264 Common.UIString('Add conditional breakpoint\u2026'), this._editBreak pointCondition.bind(this, lineNumber));
261 contextMenu.appendItem( 265 contextMenu.appendItem(
262 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true)); 266 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true));
263 } else { 267 } else {
264 var breakpoint = breakpoints[0]; 268 var hasOneBreakpoint = breakpoints.length === 1;
265 269 var removeTitle =
266 // This row has a breakpoint, we want to show edit and remove breakpoint , and either disable or enable. 270 hasOneBreakpoint ? Common.UIString('Remove breakpoint') : Common.UIS tring('Remove all breakpoints in line');
267 contextMenu.appendItem(Common.UIString('Remove breakpoint'), breakpoint. remove.bind(breakpoint)); 271 contextMenu.appendItem(removeTitle, () => breakpoints.map(breakpoint => breakpoint.remove()));
268 contextMenu.appendItem( 272 if (hasOneBreakpoint) {
269 Common.UIString('Edit breakpoint…'), this._editBreakpointCondition.b ind(this, lineNumber, breakpoint)); 273 contextMenu.appendItem(
270 if (breakpoint.enabled()) 274 Common.UIString('Edit breakpoint\u2026'),
271 contextMenu.appendItem(Common.UIString('Disable breakpoint'), breakpoi nt.setEnabled.bind(breakpoint, false)); 275 this._editBreakpointCondition.bind(this, lineNumber, breakpoints[0 ]));
272 else 276 }
273 contextMenu.appendItem(Common.UIString('Enable breakpoint'), breakpoin t.setEnabled.bind(breakpoint, true)); 277 var hasEnabled = breakpoints.some(breakpoint => breakpoint.enabled());
278 if (hasEnabled) {
279 var title = hasOneBreakpoint ? Common.UIString('Disable breakpoint') :
280 Common.UIString('Disable all breakpoint s in line');
281 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(false)));
282 }
283 var hasDisabled = breakpoints.some(breakpoint => !breakpoint.enabled());
284 if (hasDisabled) {
285 var title = hasOneBreakpoint ? Common.UIString('Enable breakpoint') :
286 Common.UIString('Enabled all breakpoint s in line');
287 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(true)));
288 }
274 } 289 }
275 resolve(); 290 resolve();
276 } 291 }
277 return new Promise(populate.bind(this)); 292 return new Promise(populate.bind(this));
278 } 293 }
279 294
280 /** 295 /**
281 * @override 296 * @override
282 * @return {!Promise} 297 * @return {!Promise}
283 */ 298 */
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 _didDivergeFromVM() { 363 _didDivergeFromVM() {
349 if (this._supportsEnabledBreakpointsWhileEditing()) 364 if (this._supportsEnabledBreakpointsWhileEditing())
350 return; 365 return;
351 this._updateDivergedInfobar(); 366 this._updateDivergedInfobar();
352 this._muteBreakpointsWhileEditing(); 367 this._muteBreakpointsWhileEditing();
353 } 368 }
354 369
355 _muteBreakpointsWhileEditing() { 370 _muteBreakpointsWhileEditing() {
356 if (this._muted) 371 if (this._muted)
357 return; 372 return;
358 for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNum ber) { 373 for (var decoration of this._breakpointDecorations)
359 var breakpointDecoration = this._textEditor.getAttribute(lineNumber, 'brea kpoint'); 374 this._updateBreakpointDecoration(decoration);
360 if (!breakpointDecoration)
361 continue;
362 this._removeBreakpointDecoration(lineNumber);
363 this._addBreakpointDecoration(
364 lineNumber, breakpointDecoration.columnNumber, breakpointDecoration.co ndition, breakpointDecoration.enabled,
365 true);
366 }
367 this._muted = true; 375 this._muted = true;
368 } 376 }
369 377
370 _updateDivergedInfobar() { 378 _updateDivergedInfobar() {
371 if (this.uiSourceCode().project().type() !== Workspace.projectTypes.FileSyst em) { 379 if (this.uiSourceCode().project().type() !== Workspace.projectTypes.FileSyst em) {
372 this._hideDivergedInfobar(); 380 this._hideDivergedInfobar();
373 return; 381 return;
374 } 382 }
375 383
376 var scriptFiles = this._scriptFileForTarget.valuesArray(); 384 var scriptFiles = this._scriptFileForTarget.valuesArray();
(...skipping 19 matching lines...) Expand all
396 for (var i = 0; i < scriptFiles.length; ++i) { 404 for (var i = 0; i < scriptFiles.length; ++i) {
397 if (scriptFiles[i].hasDivergedFromVM() || scriptFiles[i].isMergingToVM()) 405 if (scriptFiles[i].hasDivergedFromVM() || scriptFiles[i].isMergingToVM())
398 return; 406 return;
399 } 407 }
400 408
401 this._restoreBreakpointsAfterEditing(); 409 this._restoreBreakpointsAfterEditing();
402 } 410 }
403 411
404 _restoreBreakpointsAfterEditing() { 412 _restoreBreakpointsAfterEditing() {
405 delete this._muted; 413 delete this._muted;
406 var breakpoints = {}; 414 var decorations = Array.from(this._breakpointDecorations);
407 // Save and remove muted breakpoint decorations. 415 this._breakpointDecorations.clear();
408 for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNum ber) { 416 for (var decoration of decorations) {
409 var breakpointDecoration = this._textEditor.getAttribute(lineNumber, 'brea kpoint'); 417 decoration.breakpoint.remove();
410 if (breakpointDecoration) { 418 var location = decoration.handle.resolve();
411 breakpoints[lineNumber] = breakpointDecoration; 419 if (location)
412 this._removeBreakpointDecoration(lineNumber); 420 this._setBreakpoint(location.lineNumber, location.columnNumber, decorati on.condition, decoration.enabled);
413 }
414 }
415
416 // Remove all breakpoints.
417 this._removeAllBreakpoints();
418
419 // Restore all breakpoints from saved decorations.
420 for (var lineNumberString in breakpoints) {
421 var lineNumber = parseInt(lineNumberString, 10);
422 if (isNaN(lineNumber))
423 continue;
424 var breakpointDecoration = breakpoints[lineNumberString];
425 this._setBreakpoint(
426 lineNumber, breakpointDecoration.columnNumber, breakpointDecoration.co ndition, breakpointDecoration.enabled);
427 } 421 }
428 } 422 }
429 423
430 _removeAllBreakpoints() {
431 var breakpoints = this._breakpointManager.breakpointsForUISourceCode(this.ui SourceCode());
432 for (var i = 0; i < breakpoints.length; ++i)
433 breakpoints[i].remove();
434 }
435
436 /** 424 /**
437 * @param {string} tokenType 425 * @param {string} tokenType
438 * @return {boolean} 426 * @return {boolean}
439 */ 427 */
440 _isIdentifier(tokenType) { 428 _isIdentifier(tokenType) {
441 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def'; 429 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def';
442 } 430 }
443 431
444 _getPopoverAnchor(element, event) { 432 _getPopoverAnchor(element, event) {
445 var target = UI.context.flavor(SDK.Target); 433 var target = UI.context.flavor(SDK.Target);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 538 }
551 539
552 _onHidePopover() { 540 _onHidePopover() {
553 if (!this._popoverAnchorBox) 541 if (!this._popoverAnchorBox)
554 return; 542 return;
555 if (this._popoverAnchorBox._highlightDescriptor) 543 if (this._popoverAnchorBox._highlightDescriptor)
556 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r); 544 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r);
557 delete this._popoverAnchorBox; 545 delete this._popoverAnchorBox;
558 } 546 }
559 547
560 /**
561 * @param {number} lineNumber
562 * @param {number} columnNumber
563 * @param {string} condition
564 * @param {boolean} enabled
565 * @param {boolean} mutedWhileEditing
566 */
567 _addBreakpointDecoration(lineNumber, columnNumber, condition, enabled, mutedWh ileEditing) {
568 var breakpoint = {condition: condition, enabled: enabled, columnNumber: colu mnNumber};
569
570 this.textEditor.setAttribute(lineNumber, 'breakpoint', breakpoint);
571
572 var disabled = !enabled || mutedWhileEditing;
573 this.textEditor.addBreakpoint(lineNumber, disabled, !!condition);
574 }
575
576 _removeBreakpointDecoration(lineNumber) {
577 this.textEditor.removeAttribute(lineNumber, 'breakpoint');
578 this.textEditor.removeBreakpoint(lineNumber);
579 }
580
581 _onKeyDown(event) { 548 _onKeyDown(event) {
582 if (event.key === 'Escape') { 549 if (event.key === 'Escape') {
583 if (this._popoverHelper.isPopoverVisible()) { 550 if (this._popoverHelper.isPopoverVisible()) {
584 this._popoverHelper.hidePopover(); 551 this._popoverHelper.hidePopover();
585 event.consume(); 552 event.consume();
586 } 553 }
587 } 554 }
588 } 555 }
589 556
590 /** 557 /**
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 } 787 }
821 788
822 _clearValueWidgets() { 789 _clearValueWidgets() {
823 delete this._clearValueWidgetsTimer; 790 delete this._clearValueWidgetsTimer;
824 for (var line of this._valueWidgets.keys()) 791 for (var line of this._valueWidgets.keys())
825 this.textEditor.removeDecoration(this._valueWidgets.get(line), line); 792 this.textEditor.removeDecoration(this._valueWidgets.get(line), line);
826 this._valueWidgets.clear(); 793 this._valueWidgets.clear();
827 } 794 }
828 795
829 /** 796 /**
797 * @param {number} lineNumber
798 * @return {!Array<!Sources.JavaScriptSourceFrame.BreakpointDecoration>}
799 */
800 _lineBreakpointDecorations(lineNumber) {
801 return Array.from(this._breakpointDecorations)
802 .filter(decoration => (decoration.handle.resolve() || {}).lineNumber === lineNumber);
803 }
804
805 /**
806 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration
807 */
808 _updateBreakpointDecoration(decoration) {
809 if (!this._scheduledBreakpointDecorationUpdates) {
810 this._scheduledBreakpointDecorationUpdates = new Set();
lushnikov 2016/11/21 19:17:23 nit: jsdoc
kozy 2016/11/21 19:40:10 Done.
811 setImmediate(() => this.textEditor.operation(update.bind(this)));
812 }
813 this._scheduledBreakpointDecorationUpdates.add(decoration);
814 /**
lushnikov 2016/11/21 19:17:23 newline
kozy 2016/11/21 19:40:10 Done.
815 * @this {Sources.JavaScriptSourceFrame}
816 */
817 function update() {
818 var lineNumbers = new Set();
819 for (var decoration of this._scheduledBreakpointDecorationUpdates) {
820 var location = decoration.handle.resolve();
821 if (!location)
822 continue;
823 lineNumbers.add(location.lineNumber);
824 }
825 for (var lineNumber of lineNumbers) {
826 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', false);
827 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', fa lse);
828 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', false);
829 var decorations = this._lineBreakpointDecorations(lineNumber);
830 if (!decorations.length)
831 continue;
832 decorations.sort(Sources.JavaScriptSourceFrame.BreakpointDecoration.most SpecificFirst);
833 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', true);
834 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', !d ecorations[0].enabled || this._muted);
835 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', !!decorations[0].condition);
836 }
837 delete this._scheduledBreakpointDecorationUpdates;
838 this._breakpointDecorationsUpdatedForTest();
839 }
840 }
841
842 _breakpointDecorationsUpdatedForTest() {
843 }
844
845 /**
846 * @param {!Common.Event} event
830 * @return {boolean} 847 * @return {boolean}
831 */ 848 */
832 _shouldIgnoreExternalBreakpointEvents() { 849 _shouldIgnoreExternalBreakpointEvents(event) {
850 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
851 if (uiLocation.uiSourceCode !== this.uiSourceCode() || !this.loaded)
852 return true;
833 if (this._supportsEnabledBreakpointsWhileEditing()) 853 if (this._supportsEnabledBreakpointsWhileEditing())
834 return false; 854 return false;
835 if (this._muted) 855 if (this._muted)
836 return true; 856 return true;
837 var scriptFiles = this._scriptFileForTarget.valuesArray(); 857 var scriptFiles = this._scriptFileForTarget.valuesArray();
838 for (var i = 0; i < scriptFiles.length; ++i) { 858 for (var i = 0; i < scriptFiles.length; ++i) {
839 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM()) 859 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM())
840 return true; 860 return true;
841 } 861 }
842 return false; 862 return false;
843 } 863 }
844 864
865 /**
866 * @param {!Common.Event} event
867 */
845 _breakpointAdded(event) { 868 _breakpointAdded(event) {
869 if (this._shouldIgnoreExternalBreakpointEvents(event))
870 return;
846 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation ); 871 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
847 if (uiLocation.uiSourceCode !== this.uiSourceCode()) 872 var handle = this._textEditor.textEditorPositionHandle(uiLocation.lineNumber , uiLocation.columnNumber);
848 return;
849 if (this._shouldIgnoreExternalBreakpointEvents())
850 return;
851
852 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint); 873 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
853 if (this.loaded) { 874 var decoration = new Sources.JavaScriptSourceFrame.BreakpointDecoration(hand le, breakpoint);
854 this._addBreakpointDecoration( 875 this._breakpointDecorations.add(decoration);
855 uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condition() , breakpoint.enabled(), false); 876 breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSym bol] = decoration;
856 } 877 this._updateBreakpointDecoration(decoration);
857 }
858
859 _breakpointRemoved(event) {
860 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
861 if (uiLocation.uiSourceCode !== this.uiSourceCode())
862 return;
863 if (this._shouldIgnoreExternalBreakpointEvents())
864 return;
865
866 var remainingBreakpoints = this._breakpointManager.findBreakpoints(this.uiSo urceCode(), uiLocation.lineNumber);
867 if (!remainingBreakpoints.length && this.loaded)
868 this._removeBreakpointDecoration(uiLocation.lineNumber);
869 } 878 }
870 879
871 /** 880 /**
881 * @param {!Common.Event} event
882 */
883 _breakpointRemoved(event) {
884 if (this._shouldIgnoreExternalBreakpointEvents(event))
885 return;
886 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
887 var decoration = breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecorati on._decorationSymbol];
888 if (!decoration)
889 return;
890 this._breakpointDecorations.delete(decoration);
891 delete breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decora tionSymbol];
892 this._updateBreakpointDecoration(decoration);
893 }
894
895 /**
872 * @param {!Common.Event} event 896 * @param {!Common.Event} event
873 */ 897 */
874 _onSourceMappingChanged(event) { 898 _onSourceMappingChanged(event) {
875 var data = /** @type {{target: !SDK.Target}} */ (event.data); 899 var data = /** @type {{target: !SDK.Target}} */ (event.data);
876 this._updateScriptFile(data.target); 900 this._updateScriptFile(data.target);
877 this._updateLinesWithoutMappingHighlight(); 901 this._updateLinesWithoutMappingHighlight();
878 } 902 }
879 903
880 _updateLinesWithoutMappingHighlight() { 904 _updateLinesWithoutMappingHighlight() {
881 var linesCount = this.textEditor.linesCount; 905 var linesCount = this.textEditor.linesCount;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 /** 955 /**
932 * @override 956 * @override
933 */ 957 */
934 onTextEditorContentSet() { 958 onTextEditorContentSet() {
935 super.onTextEditorContentSet(); 959 super.onTextEditorContentSet();
936 if (this._executionLocation) 960 if (this._executionLocation)
937 this.setExecutionLocation(this._executionLocation); 961 this.setExecutionLocation(this._executionLocation);
938 962
939 var breakpointLocations = this._breakpointManager.breakpointLocationsForUISo urceCode(this.uiSourceCode()); 963 var breakpointLocations = this._breakpointManager.breakpointLocationsForUISo urceCode(this.uiSourceCode());
940 for (var i = 0; i < breakpointLocations.length; ++i) 964 for (var i = 0; i < breakpointLocations.length; ++i)
941 this._breakpointAdded({data: breakpointLocations[i]}); 965 this._breakpointAdded(/** @type {!Common.Event} */ ({data: breakpointLocat ions[i]}));
942 966
943 var scriptFiles = this._scriptFileForTarget.valuesArray(); 967 var scriptFiles = this._scriptFileForTarget.valuesArray();
944 for (var i = 0; i < scriptFiles.length; ++i) 968 for (var i = 0; i < scriptFiles.length; ++i)
945 scriptFiles[i].checkMapping(); 969 scriptFiles[i].checkMapping();
946 970
947 this._updateLinesWithoutMappingHighlight(); 971 this._updateLinesWithoutMappingHighlight();
948 this._detectMinified(); 972 this._detectMinified();
949 } 973 }
950 974
951 _detectMinified() { 975 _detectMinified() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 1026
1003 this._toggleBreakpoint(lineNumber, eventObject.shiftKey); 1027 this._toggleBreakpoint(lineNumber, eventObject.shiftKey);
1004 eventObject.consume(true); 1028 eventObject.consume(true);
1005 } 1029 }
1006 1030
1007 /** 1031 /**
1008 * @param {number} lineNumber 1032 * @param {number} lineNumber
1009 * @param {boolean} onlyDisable 1033 * @param {boolean} onlyDisable
1010 */ 1034 */
1011 _toggleBreakpoint(lineNumber, onlyDisable) { 1035 _toggleBreakpoint(lineNumber, onlyDisable) {
1012 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCode( ), lineNumber); 1036 var decorations = this._lineBreakpointDecorations(lineNumber);
1013 if (breakpoints.length) { 1037 if (!decorations.length) {
1038 this._createNewBreakpoint(lineNumber, '', true);
1039 return;
1040 }
1041 var hasDisabled = this._textEditor.hasLineClass(lineNumber, 'cm-breakpoint-d isabled');
1042 var breakpoints = decorations.map(decoration => decoration.breakpoint);
1043 for (var breakpoint of breakpoints) {
1014 if (onlyDisable) 1044 if (onlyDisable)
1015 breakpoints[0].setEnabled(!breakpoints[0].enabled()); 1045 breakpoint.setEnabled(hasDisabled);
1016 else 1046 else
1017 breakpoints[0].remove(); 1047 breakpoint.remove();
1018 } else {
1019 this._createNewBreakpoint(lineNumber, '', true);
1020 } 1048 }
1021 } 1049 }
1022 1050
1023 /** 1051 /**
1024 * @param {number} lineNumber 1052 * @param {number} lineNumber
1025 * @param {string} condition 1053 * @param {string} condition
1026 * @param {boolean} enabled 1054 * @param {boolean} enabled
1027 */ 1055 */
1028 _createNewBreakpoint(lineNumber, condition, enabled) { 1056 _createNewBreakpoint(lineNumber, condition, enabled) {
1029 findPossibleBreakpoints.call(this, lineNumber) 1057 findPossibleBreakpoints.call(this, lineNumber)
1030 .then(checkNextLineIfNeeded.bind(this, lineNumber, 4)) 1058 .then(checkNextLineIfNeeded.bind(this, lineNumber, 4))
1031 .then(setBreakpoint.bind(this)); 1059 .then(setBreakpoint.bind(this, condition, enabled));
1032 1060
1033 /** 1061 /**
1034 * @this {!Sources.JavaScriptSourceFrame} 1062 * @this {!Sources.JavaScriptSourceFrame}
1035 * @param {number} lineNumber 1063 * @param {number} lineNumber
1036 * @return {!Promise<?Array<!Workspace.UILocation>>} 1064 * @return {!Promise<?Array<!Workspace.UILocation>>}
1037 */ 1065 */
1038 function findPossibleBreakpoints(lineNumber) { 1066 function findPossibleBreakpoints(lineNumber) {
1039 const maxLengthToCheck = 1024; 1067 const maxLengthToCheck = 1024;
1040 if (lineNumber >= this._textEditor.linesCount) 1068 if (lineNumber >= this._textEditor.linesCount)
1041 return Promise.resolve(/** @type {?Array<!Workspace.UILocation>} */ ([]) ); 1069 return Promise.resolve(/** @type {?Array<!Workspace.UILocation>} */ ([]) );
(...skipping 13 matching lines...) Expand all
1055 */ 1083 */
1056 function checkNextLineIfNeeded(currentLineNumber, linesToCheck, locations) { 1084 function checkNextLineIfNeeded(currentLineNumber, linesToCheck, locations) {
1057 if (locations || linesToCheck <= 0) 1085 if (locations || linesToCheck <= 0)
1058 return Promise.resolve(locations); 1086 return Promise.resolve(locations);
1059 return findPossibleBreakpoints.call(this, currentLineNumber + 1) 1087 return findPossibleBreakpoints.call(this, currentLineNumber + 1)
1060 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1)); 1088 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1));
1061 } 1089 }
1062 1090
1063 /** 1091 /**
1064 * @this {!Sources.JavaScriptSourceFrame} 1092 * @this {!Sources.JavaScriptSourceFrame}
1093 * @param {string} condition
1094 * @param {boolean} enabled
1065 * @param {?Array<!Workspace.UILocation>} locations 1095 * @param {?Array<!Workspace.UILocation>} locations
1066 */ 1096 */
1067 function setBreakpoint(locations) { 1097 function setBreakpoint(condition, enabled, locations) {
1068 if (!locations || !locations.length) 1098 if (!locations || !locations.length)
1069 this._setBreakpoint(lineNumber, 0, condition, enabled); 1099 this._setBreakpoint(lineNumber, 0, condition, enabled);
1070 else 1100 else
1071 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled); 1101 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled);
1072 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet) ; 1102 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet) ;
1073 } 1103 }
1074 } 1104 }
1075 1105
1076 toggleBreakpointOnCurrentLine() { 1106 toggleBreakpointOnCurrentLine() {
1077 if (this._muted) 1107 if (this._muted)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this); 1150 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this);
1121 this.uiSourceCode().removeEventListener( 1151 this.uiSourceCode().removeEventListener(
1122 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this); 1152 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this);
1123 this.uiSourceCode().removeEventListener( 1153 this.uiSourceCode().removeEventListener(
1124 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this); 1154 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this);
1125 Common.moduleSetting('skipStackFramesPattern').removeChangeListener(this._sh owBlackboxInfobarIfNeeded, this); 1155 Common.moduleSetting('skipStackFramesPattern').removeChangeListener(this._sh owBlackboxInfobarIfNeeded, this);
1126 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this); 1156 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this);
1127 super.dispose(); 1157 super.dispose();
1128 } 1158 }
1129 }; 1159 };
1160
1161 /**
1162 * @unrestricted
1163 */
1164 Sources.JavaScriptSourceFrame.BreakpointDecoration = class {
1165 /**
1166 * @param {!TextEditor.TextEditorPositionHandle} handle
1167 * @param {!Bindings.BreakpointManager.Breakpoint} breakpoint
1168 */
1169 constructor(handle, breakpoint) {
1170 this.handle = handle;
1171 this.condition = breakpoint.condition();
1172 this.enabled = breakpoint.enabled();
1173 this.breakpoint = breakpoint;
1174 }
1175
1176 /**
1177 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration1
1178 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration2
1179 * @return {number}
1180 */
1181 static mostSpecificFirst(decoration1, decoration2) {
1182 if (!!decoration1.condition !== !!decoration2.condition)
1183 return !!decoration1.condition ? -1 : 1;
1184 if (decoration1.enabled !== decoration2.enabled)
1185 return decoration1.enabled ? -1 : 1;
1186 return 0;
1187 }
1188 };
1189
1190 Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSymbol = Symbol('d ecoration');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698