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

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 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 */ 178 */
176 willHide() { 179 willHide() {
177 super.willHide(); 180 super.willHide();
178 this._popoverHelper.hidePopover(); 181 this._popoverHelper.hidePopover();
179 } 182 }
180 183
181 /** 184 /**
182 * @override 185 * @override
183 */ 186 */
184 onUISourceCodeContentChanged() { 187 onUISourceCodeContentChanged() {
185 this._removeAllBreakpoints(); 188 for (var decoration of this._breakpointDecorations)
189 decoration.breakpoint.remove();
186 super.onUISourceCodeContentChanged(); 190 super.onUISourceCodeContentChanged();
187 } 191 }
188 192
189 /** 193 /**
190 * @override 194 * @override
191 */ 195 */
192 onTextChanged(oldRange, newRange) { 196 onTextChanged(oldRange, newRange) {
193 this._scriptsPanel.updateLastModificationTime(); 197 this._scriptsPanel.updateLastModificationTime();
194 super.onTextChanged(oldRange, newRange); 198 super.onTextChanged(oldRange, newRange);
195 if (this._compiler) 199 if (this._compiler)
196 this._compiler.scheduleCompile(); 200 this._compiler.scheduleCompile();
197 } 201 }
198 202
199 /** 203 /**
200 * @override 204 * @override
201 * @return {!Promise} 205 * @return {!Promise}
202 */ 206 */
203 populateLineGutterContextMenu(contextMenu, lineNumber) { 207 populateLineGutterContextMenu(contextMenu, lineNumber) {
204 /** 208 /**
205 * @this {Sources.JavaScriptSourceFrame} 209 * @this {Sources.JavaScriptSourceFrame}
206 */ 210 */
207 function populate(resolve, reject) { 211 function populate(resolve, reject) {
208 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0); 212 var uiLocation = new Workspace.UILocation(this.uiSourceCode(), lineNumber, 0);
209 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation); 213 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation);
210 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCod e(), lineNumber); 214 var breakpoints = this._lineBreakpointDecorations(lineNumber).map(decorati on => decoration.breakpoint);
211 if (!breakpoints.length) { 215 if (!breakpoints.length) {
212 // This row doesn't have a breakpoint: We want to show Add Breakpoint an d Add and Edit Breakpoint. 216 // This row doesn't have a breakpoint: We want to show Add Breakpoint an d Add and Edit Breakpoint.
213 contextMenu.appendItem( 217 contextMenu.appendItem(
214 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true)); 218 Common.UIString('Add breakpoint'), this._createNewBreakpoint.bind(th is, lineNumber, '', true));
215 contextMenu.appendItem( 219 contextMenu.appendItem(
216 Common.UIString('Add conditional breakpoint'), this._editBreakpoint Condition.bind(this, lineNumber)); 220 Common.UIString('Add conditional breakpoint\u2026'), this._editBreak pointCondition.bind(this, lineNumber));
217 contextMenu.appendItem( 221 contextMenu.appendItem(
218 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true)); 222 Common.UIString('Never pause here'), this._createNewBreakpoint.bind( this, lineNumber, 'false', true));
219 } else { 223 } else {
220 var breakpoint = breakpoints[0]; 224 var hasOneBreakpoint = breakpoints.length === 1;
221 225 var removeTitle =
222 // This row has a breakpoint, we want to show edit and remove breakpoint , and either disable or enable. 226 hasOneBreakpoint ? Common.UIString('Remove breakpoint') : Common.UIS tring('Remove all breakpoints in line');
223 contextMenu.appendItem(Common.UIString('Remove breakpoint'), breakpoint. remove.bind(breakpoint)); 227 contextMenu.appendItem(removeTitle, () => breakpoints.map(breakpoint => breakpoint.remove()));
224 contextMenu.appendItem( 228 if (hasOneBreakpoint) {
225 Common.UIString('Edit breakpoint…'), this._editBreakpointCondition.b ind(this, lineNumber, breakpoint)); 229 contextMenu.appendItem(
226 if (breakpoint.enabled()) 230 Common.UIString('Edit breakpoint\u2026'),
227 contextMenu.appendItem(Common.UIString('Disable breakpoint'), breakpoi nt.setEnabled.bind(breakpoint, false)); 231 this._editBreakpointCondition.bind(this, lineNumber, breakpoints[0 ]));
228 else 232 }
229 contextMenu.appendItem(Common.UIString('Enable breakpoint'), breakpoin t.setEnabled.bind(breakpoint, true)); 233 var hasEnabled = breakpoints.some(breakpoint => breakpoint.enabled());
234 if (hasEnabled) {
235 var title = hasOneBreakpoint ? Common.UIString('Disable breakpoint') :
236 Common.UIString('Disable all breakpoint s in line');
237 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(false)));
238 }
239 var hasDisabled = breakpoints.some(breakpoint => !breakpoint.enabled());
240 if (hasDisabled) {
241 var title = hasOneBreakpoint ? Common.UIString('Enable breakpoint') :
242 Common.UIString('Enabled all breakpoint s in line');
243 contextMenu.appendItem(title, () => breakpoints.map(breakpoint => brea kpoint.setEnabled(true)));
244 }
230 } 245 }
231 resolve(); 246 resolve();
232 } 247 }
233 return new Promise(populate.bind(this)); 248 return new Promise(populate.bind(this));
234 } 249 }
235 250
236 /** 251 /**
237 * @override 252 * @override
238 * @return {!Promise} 253 * @return {!Promise}
239 */ 254 */
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 317
303 _didDivergeFromVM() { 318 _didDivergeFromVM() {
304 if (this._supportsEnabledBreakpointsWhileEditing()) 319 if (this._supportsEnabledBreakpointsWhileEditing())
305 return; 320 return;
306 this._muteBreakpointsWhileEditing(); 321 this._muteBreakpointsWhileEditing();
307 } 322 }
308 323
309 _muteBreakpointsWhileEditing() { 324 _muteBreakpointsWhileEditing() {
310 if (this._muted) 325 if (this._muted)
311 return; 326 return;
312 for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNum ber) { 327 for (var decoration of this._breakpointDecorations)
313 var breakpointDecoration = this._textEditor.getAttribute(lineNumber, 'brea kpoint'); 328 this._updateBreakpointDecoration(decoration);
314 if (!breakpointDecoration)
315 continue;
316 this._removeBreakpointDecoration(lineNumber);
317 this._addBreakpointDecoration(
318 lineNumber, breakpointDecoration.columnNumber, breakpointDecoration.co ndition, breakpointDecoration.enabled,
319 true);
320 }
321 this._muted = true; 329 this._muted = true;
322 } 330 }
323 331
324 _supportsEnabledBreakpointsWhileEditing() { 332 _supportsEnabledBreakpointsWhileEditing() {
325 return this.uiSourceCode().project().type() === Workspace.projectTypes.Snipp ets; 333 return this.uiSourceCode().project().type() === Workspace.projectTypes.Snipp ets;
326 } 334 }
327 335
328 _restoreBreakpointsIfConsistentScripts() { 336 _restoreBreakpointsIfConsistentScripts() {
329 var scriptFiles = this._scriptFileForTarget.valuesArray(); 337 var scriptFiles = this._scriptFileForTarget.valuesArray();
330 for (var i = 0; i < scriptFiles.length; ++i) { 338 for (var i = 0; i < scriptFiles.length; ++i) {
331 if (scriptFiles[i].hasDivergedFromVM() || scriptFiles[i].isMergingToVM()) 339 if (scriptFiles[i].hasDivergedFromVM() || scriptFiles[i].isMergingToVM())
332 return; 340 return;
333 } 341 }
334 342
335 this._restoreBreakpointsAfterEditing(); 343 this._restoreBreakpointsAfterEditing();
336 } 344 }
337 345
338 _restoreBreakpointsAfterEditing() { 346 _restoreBreakpointsAfterEditing() {
339 delete this._muted; 347 delete this._muted;
340 var breakpoints = {}; 348 var decorations = Array.from(this._breakpointDecorations);
341 // Save and remove muted breakpoint decorations. 349 this._breakpointDecorations.clear();
342 for (var lineNumber = 0; lineNumber < this._textEditor.linesCount; ++lineNum ber) { 350 for (var decoration of decorations) {
343 var breakpointDecoration = this._textEditor.getAttribute(lineNumber, 'brea kpoint'); 351 decoration.breakpoint.remove();
344 if (breakpointDecoration) { 352 var location = decoration.handle.resolve();
345 breakpoints[lineNumber] = breakpointDecoration; 353 if (location)
346 this._removeBreakpointDecoration(lineNumber); 354 this._setBreakpoint(location.lineNumber, location.columnNumber, decorati on.condition, decoration.enabled);
347 }
348 }
349
350 // Remove all breakpoints.
351 this._removeAllBreakpoints();
352
353 // Restore all breakpoints from saved decorations.
354 for (var lineNumberString in breakpoints) {
355 var lineNumber = parseInt(lineNumberString, 10);
356 if (isNaN(lineNumber))
357 continue;
358 var breakpointDecoration = breakpoints[lineNumberString];
359 this._setBreakpoint(
360 lineNumber, breakpointDecoration.columnNumber, breakpointDecoration.co ndition, breakpointDecoration.enabled);
361 } 355 }
362 } 356 }
363 357
364 _removeAllBreakpoints() {
365 var breakpoints = this._breakpointManager.breakpointsForUISourceCode(this.ui SourceCode());
366 for (var i = 0; i < breakpoints.length; ++i)
367 breakpoints[i].remove();
368 }
369
370 /** 358 /**
371 * @param {string} tokenType 359 * @param {string} tokenType
372 * @return {boolean} 360 * @return {boolean}
373 */ 361 */
374 _isIdentifier(tokenType) { 362 _isIdentifier(tokenType) {
375 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def'; 363 return tokenType.startsWith('js-variable') || tokenType.startsWith('js-prope rty') || tokenType === 'js-def';
376 } 364 }
377 365
378 _getPopoverAnchor(element, event) { 366 _getPopoverAnchor(element, event) {
379 var target = UI.context.flavor(SDK.Target); 367 var target = UI.context.flavor(SDK.Target);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 472 }
485 473
486 _onHidePopover() { 474 _onHidePopover() {
487 if (!this._popoverAnchorBox) 475 if (!this._popoverAnchorBox)
488 return; 476 return;
489 if (this._popoverAnchorBox._highlightDescriptor) 477 if (this._popoverAnchorBox._highlightDescriptor)
490 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r); 478 this.textEditor.removeHighlight(this._popoverAnchorBox._highlightDescripto r);
491 delete this._popoverAnchorBox; 479 delete this._popoverAnchorBox;
492 } 480 }
493 481
494 /**
495 * @param {number} lineNumber
496 * @param {number} columnNumber
497 * @param {string} condition
498 * @param {boolean} enabled
499 * @param {boolean} mutedWhileEditing
500 */
501 _addBreakpointDecoration(lineNumber, columnNumber, condition, enabled, mutedWh ileEditing) {
502 var breakpoint = {condition: condition, enabled: enabled, columnNumber: colu mnNumber};
503
504 this.textEditor.setAttribute(lineNumber, 'breakpoint', breakpoint);
505
506 var disabled = !enabled || mutedWhileEditing;
507 this.textEditor.addBreakpoint(lineNumber, disabled, !!condition);
508 }
509
510 _removeBreakpointDecoration(lineNumber) {
511 this.textEditor.removeAttribute(lineNumber, 'breakpoint');
512 this.textEditor.removeBreakpoint(lineNumber);
513 }
514
515 _onKeyDown(event) { 482 _onKeyDown(event) {
516 if (event.key === 'Escape') { 483 if (event.key === 'Escape') {
517 if (this._popoverHelper.isPopoverVisible()) { 484 if (this._popoverHelper.isPopoverVisible()) {
518 this._popoverHelper.hidePopover(); 485 this._popoverHelper.hidePopover();
519 event.consume(); 486 event.consume();
520 } 487 }
521 } 488 }
522 } 489 }
523 490
524 /** 491 /**
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 721 }
755 722
756 _clearValueWidgets() { 723 _clearValueWidgets() {
757 delete this._clearValueWidgetsTimer; 724 delete this._clearValueWidgetsTimer;
758 for (var line of this._valueWidgets.keys()) 725 for (var line of this._valueWidgets.keys())
759 this.textEditor.removeDecoration(this._valueWidgets.get(line), line); 726 this.textEditor.removeDecoration(this._valueWidgets.get(line), line);
760 this._valueWidgets.clear(); 727 this._valueWidgets.clear();
761 } 728 }
762 729
763 /** 730 /**
731 * @param {number} lineNumber
732 * @return {!Array<!Sources.JavaScriptSourceFrame.BreakpointDecoration>}
733 */
734 _lineBreakpointDecorations(lineNumber) {
735 return Array.from(this._breakpointDecorations)
736 .filter(decoration => (decoration.handle.resolve() || {}).lineNumber === lineNumber);
737 }
738
739 /**
740 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration
741 */
742 _updateBreakpointDecoration(decoration) {
743 if (!this._scheduledBreakpointDecorationUpdates) {
744 /** @type {!Set<!Sources.JavaScriptSourceFrame.BreakpointDecoration>} */
745 this._scheduledBreakpointDecorationUpdates = new Set();
746 setImmediate(() => this.textEditor.operation(update.bind(this)));
747 }
748 this._scheduledBreakpointDecorationUpdates.add(decoration);
749
750 /**
751 * @this {Sources.JavaScriptSourceFrame}
752 */
753 function update() {
754 var lineNumbers = new Set();
755 for (var decoration of this._scheduledBreakpointDecorationUpdates) {
756 var location = decoration.handle.resolve();
757 if (!location)
758 continue;
759 lineNumbers.add(location.lineNumber);
760 }
761 for (var lineNumber of lineNumbers) {
762 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', false);
763 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', fa lse);
764 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', false);
765 var decorations = this._lineBreakpointDecorations(lineNumber);
766 if (!decorations.length)
767 continue;
768 decorations.sort(Sources.JavaScriptSourceFrame.BreakpointDecoration.most SpecificFirst);
769 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint', true);
770 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-disabled', !d ecorations[0].enabled || this._muted);
771 this.textEditor.toggleLineClass(lineNumber, 'cm-breakpoint-conditional', !!decorations[0].condition);
772 }
773 delete this._scheduledBreakpointDecorationUpdates;
774 this._breakpointDecorationsUpdatedForTest();
775 }
776 }
777
778 _breakpointDecorationsUpdatedForTest() {
779 }
780
781 /**
782 * @param {!Common.Event} event
764 * @return {boolean} 783 * @return {boolean}
765 */ 784 */
766 _shouldIgnoreExternalBreakpointEvents() { 785 _shouldIgnoreExternalBreakpointEvents(event) {
786 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
787 if (uiLocation.uiSourceCode !== this.uiSourceCode() || !this.loaded)
788 return true;
767 if (this._supportsEnabledBreakpointsWhileEditing()) 789 if (this._supportsEnabledBreakpointsWhileEditing())
768 return false; 790 return false;
769 if (this._muted) 791 if (this._muted)
770 return true; 792 return true;
771 var scriptFiles = this._scriptFileForTarget.valuesArray(); 793 var scriptFiles = this._scriptFileForTarget.valuesArray();
772 for (var i = 0; i < scriptFiles.length; ++i) { 794 for (var i = 0; i < scriptFiles.length; ++i) {
773 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM()) 795 if (scriptFiles[i].isDivergingFromVM() || scriptFiles[i].isMergingToVM())
774 return true; 796 return true;
775 } 797 }
776 return false; 798 return false;
777 } 799 }
778 800
801 /**
802 * @param {!Common.Event} event
803 */
779 _breakpointAdded(event) { 804 _breakpointAdded(event) {
805 if (this._shouldIgnoreExternalBreakpointEvents(event))
806 return;
780 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation ); 807 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
781 if (uiLocation.uiSourceCode !== this.uiSourceCode()) 808 var handle = this._textEditor.textEditorPositionHandle(uiLocation.lineNumber , uiLocation.columnNumber);
782 return;
783 if (this._shouldIgnoreExternalBreakpointEvents())
784 return;
785
786 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint); 809 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
787 if (this.loaded) { 810 var decoration = new Sources.JavaScriptSourceFrame.BreakpointDecoration(hand le, breakpoint);
788 this._addBreakpointDecoration( 811 this._breakpointDecorations.add(decoration);
789 uiLocation.lineNumber, uiLocation.columnNumber, breakpoint.condition() , breakpoint.enabled(), false); 812 breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSym bol] = decoration;
790 } 813 this._updateBreakpointDecoration(decoration);
791 }
792
793 _breakpointRemoved(event) {
794 var uiLocation = /** @type {!Workspace.UILocation} */ (event.data.uiLocation );
795 if (uiLocation.uiSourceCode !== this.uiSourceCode())
796 return;
797 if (this._shouldIgnoreExternalBreakpointEvents())
798 return;
799
800 var remainingBreakpoints = this._breakpointManager.findBreakpoints(this.uiSo urceCode(), uiLocation.lineNumber);
801 if (!remainingBreakpoints.length && this.loaded)
802 this._removeBreakpointDecoration(uiLocation.lineNumber);
803 } 814 }
804 815
805 /** 816 /**
817 * @param {!Common.Event} event
818 */
819 _breakpointRemoved(event) {
820 if (this._shouldIgnoreExternalBreakpointEvents(event))
821 return;
822 var breakpoint = /** @type {!Bindings.BreakpointManager.Breakpoint} */ (even t.data.breakpoint);
823 var decoration = breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecorati on._decorationSymbol];
824 if (!decoration)
825 return;
826 this._breakpointDecorations.delete(decoration);
827 delete breakpoint[Sources.JavaScriptSourceFrame.BreakpointDecoration._decora tionSymbol];
828 this._updateBreakpointDecoration(decoration);
829 }
830
831 /**
806 * @param {!Common.Event} event 832 * @param {!Common.Event} event
807 */ 833 */
808 _onSourceMappingChanged(event) { 834 _onSourceMappingChanged(event) {
809 var data = /** @type {{target: !SDK.Target}} */ (event.data); 835 var data = /** @type {{target: !SDK.Target}} */ (event.data);
810 this._updateScriptFile(data.target); 836 this._updateScriptFile(data.target);
811 this._updateLinesWithoutMappingHighlight(); 837 this._updateLinesWithoutMappingHighlight();
812 } 838 }
813 839
814 _updateLinesWithoutMappingHighlight() { 840 _updateLinesWithoutMappingHighlight() {
815 var linesCount = this.textEditor.linesCount; 841 var linesCount = this.textEditor.linesCount;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 /** 889 /**
864 * @override 890 * @override
865 */ 891 */
866 onTextEditorContentSet() { 892 onTextEditorContentSet() {
867 super.onTextEditorContentSet(); 893 super.onTextEditorContentSet();
868 if (this._executionLocation) 894 if (this._executionLocation)
869 this.setExecutionLocation(this._executionLocation); 895 this.setExecutionLocation(this._executionLocation);
870 896
871 var breakpointLocations = this._breakpointManager.breakpointLocationsForUISo urceCode(this.uiSourceCode()); 897 var breakpointLocations = this._breakpointManager.breakpointLocationsForUISo urceCode(this.uiSourceCode());
872 for (var i = 0; i < breakpointLocations.length; ++i) 898 for (var i = 0; i < breakpointLocations.length; ++i)
873 this._breakpointAdded({data: breakpointLocations[i]}); 899 this._breakpointAdded(/** @type {!Common.Event} */ ({data: breakpointLocat ions[i]}));
874 900
875 var scriptFiles = this._scriptFileForTarget.valuesArray(); 901 var scriptFiles = this._scriptFileForTarget.valuesArray();
876 for (var i = 0; i < scriptFiles.length; ++i) 902 for (var i = 0; i < scriptFiles.length; ++i)
877 scriptFiles[i].checkMapping(); 903 scriptFiles[i].checkMapping();
878 904
879 this._updateLinesWithoutMappingHighlight(); 905 this._updateLinesWithoutMappingHighlight();
880 this._detectMinified(); 906 this._detectMinified();
881 } 907 }
882 908
883 _detectMinified() { 909 _detectMinified() {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 960
935 this._toggleBreakpoint(lineNumber, eventObject.shiftKey); 961 this._toggleBreakpoint(lineNumber, eventObject.shiftKey);
936 eventObject.consume(true); 962 eventObject.consume(true);
937 } 963 }
938 964
939 /** 965 /**
940 * @param {number} lineNumber 966 * @param {number} lineNumber
941 * @param {boolean} onlyDisable 967 * @param {boolean} onlyDisable
942 */ 968 */
943 _toggleBreakpoint(lineNumber, onlyDisable) { 969 _toggleBreakpoint(lineNumber, onlyDisable) {
944 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCode( ), lineNumber); 970 var decorations = this._lineBreakpointDecorations(lineNumber);
945 if (breakpoints.length) { 971 if (!decorations.length) {
972 this._createNewBreakpoint(lineNumber, '', true);
973 return;
974 }
975 var hasDisabled = this._textEditor.hasLineClass(lineNumber, 'cm-breakpoint-d isabled');
976 var breakpoints = decorations.map(decoration => decoration.breakpoint);
977 for (var breakpoint of breakpoints) {
946 if (onlyDisable) 978 if (onlyDisable)
947 breakpoints[0].setEnabled(!breakpoints[0].enabled()); 979 breakpoint.setEnabled(hasDisabled);
948 else 980 else
949 breakpoints[0].remove(); 981 breakpoint.remove();
950 } else {
951 this._createNewBreakpoint(lineNumber, '', true);
952 } 982 }
953 } 983 }
954 984
955 /** 985 /**
956 * @param {number} lineNumber 986 * @param {number} lineNumber
957 * @param {string} condition 987 * @param {string} condition
958 * @param {boolean} enabled 988 * @param {boolean} enabled
959 */ 989 */
960 _createNewBreakpoint(lineNumber, condition, enabled) { 990 _createNewBreakpoint(lineNumber, condition, enabled) {
961 findPossibleBreakpoints.call(this, lineNumber) 991 findPossibleBreakpoints.call(this, lineNumber)
962 .then(checkNextLineIfNeeded.bind(this, lineNumber, 4)) 992 .then(checkNextLineIfNeeded.bind(this, lineNumber, 4))
963 .then(setBreakpoint.bind(this)); 993 .then(setBreakpoint.bind(this, condition, enabled));
964 994
965 /** 995 /**
966 * @this {!Sources.JavaScriptSourceFrame} 996 * @this {!Sources.JavaScriptSourceFrame}
967 * @param {number} lineNumber 997 * @param {number} lineNumber
968 * @return {!Promise<?Array<!Workspace.UILocation>>} 998 * @return {!Promise<?Array<!Workspace.UILocation>>}
969 */ 999 */
970 function findPossibleBreakpoints(lineNumber) { 1000 function findPossibleBreakpoints(lineNumber) {
971 const maxLengthToCheck = 1024; 1001 const maxLengthToCheck = 1024;
972 if (lineNumber >= this._textEditor.linesCount) 1002 if (lineNumber >= this._textEditor.linesCount)
973 return Promise.resolve(/** @type {?Array<!Workspace.UILocation>} */ ([]) ); 1003 return Promise.resolve(/** @type {?Array<!Workspace.UILocation>} */ ([]) );
(...skipping 13 matching lines...) Expand all
987 */ 1017 */
988 function checkNextLineIfNeeded(currentLineNumber, linesToCheck, locations) { 1018 function checkNextLineIfNeeded(currentLineNumber, linesToCheck, locations) {
989 if (locations || linesToCheck <= 0) 1019 if (locations || linesToCheck <= 0)
990 return Promise.resolve(locations); 1020 return Promise.resolve(locations);
991 return findPossibleBreakpoints.call(this, currentLineNumber + 1) 1021 return findPossibleBreakpoints.call(this, currentLineNumber + 1)
992 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1)); 1022 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1));
993 } 1023 }
994 1024
995 /** 1025 /**
996 * @this {!Sources.JavaScriptSourceFrame} 1026 * @this {!Sources.JavaScriptSourceFrame}
1027 * @param {string} condition
1028 * @param {boolean} enabled
997 * @param {?Array<!Workspace.UILocation>} locations 1029 * @param {?Array<!Workspace.UILocation>} locations
998 */ 1030 */
999 function setBreakpoint(locations) { 1031 function setBreakpoint(condition, enabled, locations) {
1000 if (!locations || !locations.length) 1032 if (!locations || !locations.length)
1001 this._setBreakpoint(lineNumber, 0, condition, enabled); 1033 this._setBreakpoint(lineNumber, 0, condition, enabled);
1002 else 1034 else
1003 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled); 1035 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled);
1004 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet) ; 1036 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ScriptsBreakpointSet) ;
1005 } 1037 }
1006 } 1038 }
1007 1039
1008 toggleBreakpointOnCurrentLine() { 1040 toggleBreakpointOnCurrentLine() {
1009 if (this._muted) 1041 if (this._muted)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this); 1084 Workspace.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChang ed, this);
1053 this.uiSourceCode().removeEventListener( 1085 this.uiSourceCode().removeEventListener(
1054 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this); 1086 Workspace.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCom mitted, this);
1055 this.uiSourceCode().removeEventListener( 1087 this.uiSourceCode().removeEventListener(
1056 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this); 1088 Workspace.UISourceCode.Events.TitleChanged, this._showBlackboxInfobarIfN eeded, this);
1057 Common.moduleSetting('skipStackFramesPattern').removeChangeListener(this._sh owBlackboxInfobarIfNeeded, this); 1089 Common.moduleSetting('skipStackFramesPattern').removeChangeListener(this._sh owBlackboxInfobarIfNeeded, this);
1058 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this); 1090 Common.moduleSetting('skipContentScripts').removeChangeListener(this._showBl ackboxInfobarIfNeeded, this);
1059 super.dispose(); 1091 super.dispose();
1060 } 1092 }
1061 }; 1093 };
1094
1095 /**
1096 * @unrestricted
1097 */
1098 Sources.JavaScriptSourceFrame.BreakpointDecoration = class {
1099 /**
1100 * @param {!TextEditor.TextEditorPositionHandle} handle
1101 * @param {!Bindings.BreakpointManager.Breakpoint} breakpoint
1102 */
1103 constructor(handle, breakpoint) {
1104 this.handle = handle;
1105 this.condition = breakpoint.condition();
1106 this.enabled = breakpoint.enabled();
1107 this.breakpoint = breakpoint;
1108 }
1109
1110 /**
1111 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration1
1112 * @param {!Sources.JavaScriptSourceFrame.BreakpointDecoration} decoration2
1113 * @return {number}
1114 */
1115 static mostSpecificFirst(decoration1, decoration2) {
1116 if (!!decoration1.condition !== !!decoration2.condition)
1117 return !!decoration1.condition ? -1 : 1;
1118 if (decoration1.enabled !== decoration2.enabled)
1119 return decoration1.enabled ? -1 : 1;
1120 return 0;
1121 }
1122 };
1123
1124 Sources.JavaScriptSourceFrame.BreakpointDecoration._decorationSymbol = Symbol('d ecoration');
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698