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

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

Issue 2484283004: [DevTools] added BreakpointManager.possibleBreakpoints method (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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 /** 252 /**
253 * @this {WebInspector.JavaScriptSourceFrame} 253 * @this {WebInspector.JavaScriptSourceFrame}
254 */ 254 */
255 function populate(resolve, reject) { 255 function populate(resolve, reject) {
256 var uiLocation = new WebInspector.UILocation(this.uiSourceCode(), lineNumb er, 0); 256 var uiLocation = new WebInspector.UILocation(this.uiSourceCode(), lineNumb er, 0);
257 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation); 257 this._scriptsPanel.appendUILocationItems(contextMenu, uiLocation);
258 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCod e(), lineNumber); 258 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCod e(), lineNumber);
259 if (!breakpoints.length) { 259 if (!breakpoints.length) {
260 // 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.
261 contextMenu.appendItem( 261 contextMenu.appendItem(
262 WebInspector.UIString('Add breakpoint'), this._createNewBreakpoint.b ind(this, lineNumber, 0, '', true)); 262 WebInspector.UIString('Add breakpoint'), this._createNewBreakpoint.b ind(this, lineNumber, '', true));
263 contextMenu.appendItem( 263 contextMenu.appendItem(
264 WebInspector.UIString('Add conditional breakpoint…'), this._editBrea kpointCondition.bind(this, lineNumber)); 264 WebInspector.UIString('Add conditional breakpoint…'), this._editBrea kpointCondition.bind(this, lineNumber));
265 contextMenu.appendItem( 265 contextMenu.appendItem(
266 WebInspector.UIString('Never pause here'), 266 WebInspector.UIString('Never pause here'),
267 this._createNewBreakpoint.bind(this, lineNumber, 0, 'false', true)); 267 this._createNewBreakpoint.bind(this, lineNumber, 'false', true));
268 } else { 268 } else {
269 var breakpoint = breakpoints[0]; 269 var breakpoint = breakpoints[0];
270 270
271 // This row has a breakpoint, we want to show edit and remove breakpoint , and either disable or enable. 271 // This row has a breakpoint, we want to show edit and remove breakpoint , and either disable or enable.
272 contextMenu.appendItem(WebInspector.UIString('Remove breakpoint'), break point.remove.bind(breakpoint)); 272 contextMenu.appendItem(WebInspector.UIString('Remove breakpoint'), break point.remove.bind(breakpoint));
273 contextMenu.appendItem( 273 contextMenu.appendItem(
274 WebInspector.UIString('Edit breakpoint…'), 274 WebInspector.UIString('Edit breakpoint…'),
275 this._editBreakpointCondition.bind(this, lineNumber, breakpoint)); 275 this._editBreakpointCondition.bind(this, lineNumber, breakpoint));
276 if (breakpoint.enabled()) 276 if (breakpoint.enabled())
277 contextMenu.appendItem( 277 contextMenu.appendItem(
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 function finishEditing(committed, element, newText) { 608 function finishEditing(committed, element, newText) {
609 this.textEditor.removeDecoration(this._conditionElement, lineNumber); 609 this.textEditor.removeDecoration(this._conditionElement, lineNumber);
610 delete this._conditionEditorElement; 610 delete this._conditionEditorElement;
611 delete this._conditionElement; 611 delete this._conditionElement;
612 if (!committed) 612 if (!committed)
613 return; 613 return;
614 614
615 if (breakpoint) 615 if (breakpoint)
616 breakpoint.setCondition(newText); 616 breakpoint.setCondition(newText);
617 else 617 else
618 this._createNewBreakpoint(lineNumber, 0, newText, true); 618 this._createNewBreakpoint(lineNumber, newText, true);
619 } 619 }
620 620
621 var config = new WebInspector.InplaceEditor.Config(finishEditing.bind(this, true), finishEditing.bind(this, false)); 621 var config = new WebInspector.InplaceEditor.Config(finishEditing.bind(this, true), finishEditing.bind(this, false));
622 WebInspector.InplaceEditor.startEditing(this._conditionEditorElement, config ); 622 WebInspector.InplaceEditor.startEditing(this._conditionEditorElement, config );
623 this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : ' '; 623 this._conditionEditorElement.value = breakpoint ? breakpoint.condition() : ' ';
624 this._conditionEditorElement.select(); 624 this._conditionEditorElement.select();
625 } 625 }
626 626
627 _createConditionElement(lineNumber) { 627 _createConditionElement(lineNumber) {
628 var conditionElement = createElementWithClass('div', 'source-frame-breakpoin t-condition'); 628 var conditionElement = createElementWithClass('div', 'source-frame-breakpoin t-condition');
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 * @param {boolean} onlyDisable 1015 * @param {boolean} onlyDisable
1016 */ 1016 */
1017 _toggleBreakpoint(lineNumber, onlyDisable) { 1017 _toggleBreakpoint(lineNumber, onlyDisable) {
1018 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCode( ), lineNumber); 1018 var breakpoints = this._breakpointManager.findBreakpoints(this.uiSourceCode( ), lineNumber);
1019 if (breakpoints.length) { 1019 if (breakpoints.length) {
1020 if (onlyDisable) 1020 if (onlyDisable)
1021 breakpoints[0].setEnabled(!breakpoints[0].enabled()); 1021 breakpoints[0].setEnabled(!breakpoints[0].enabled());
1022 else 1022 else
1023 breakpoints[0].remove(); 1023 breakpoints[0].remove();
1024 } else 1024 } else
1025 this._createNewBreakpoint(lineNumber, 0, '', true); 1025 this._createNewBreakpoint(lineNumber, '', true);
1026 } 1026 }
1027 1027
1028 /** 1028 /**
1029 * @param {number} lineNumber 1029 * @param {number} lineNumber
1030 * @param {number} columnNumber
1031 * @param {string} condition 1030 * @param {string} condition
1032 * @param {boolean} enabled 1031 * @param {boolean} enabled
1033 */ 1032 */
1034 _createNewBreakpoint(lineNumber, columnNumber, condition, enabled) { 1033 _createNewBreakpoint(lineNumber, condition, enabled) {
1035 this._setBreakpoint(lineNumber, columnNumber, condition, enabled); 1034 findPossibleBreakpoints.call(this, lineNumber)
1036 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Scripts BreakpointSet); 1035 .then(checkNextLineIfNeeded.bind(this, lineNumber, 4))
1036 .then(setBreakpoint.bind(this));
1037
1038 /**
1039 * @this {!WebInspector.JavaScriptSourceFrame}
1040 * @param {number} lineNumber
1041 * @return {!Promise<?Array<!WebInspector.UILocation>>}
1042 */
1043 function findPossibleBreakpoints(lineNumber) {
1044 const maxLengthToCheck = 1024;
1045 if (lineNumber >= this._textEditor.linesCount)
1046 return Promise.resolve(/** @type {?Array<!WebInspector.UILocation>} */([ ]));
1047 if (this._textEditor.line(lineNumber).length >= maxLengthToCheck)
1048 return Promise.resolve(/** @type {?Array<!WebInspector.UILocation>} */([ ]));
1049 return this._breakpointManager.possibleBreakpoints(this.uiSourceCode(), ne w WebInspector.TextRange(lineNumber, 0, lineNumber + 1, 0))
1050 .then(locations => locations.length ? locations : null);
1051 }
1052
1053 /**
1054 * @this {!WebInspector.JavaScriptSourceFrame}
1055 * @param {number} currentLineNumber
1056 * @param {number} linesToCheck
1057 * @param {?Array<!WebInspector.UILocation>} locations
1058 * @return {!Promise<?Array<!WebInspector.UILocation>>}
1059 */
1060 function checkNextLineIfNeeded(currentLineNumber, linesToCheck, locations) {
1061 if (locations || linesToCheck <= 0)
1062 return Promise.resolve(locations);
1063 return findPossibleBreakpoints.call(this, currentLineNumber + 1)
1064 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1));
1065 }
1066
1067 /**
1068 * @this {!WebInspector.JavaScriptSourceFrame}
1069 * @param {?Array<!WebInspector.UILocation>} locations
1070 */
1071 function setBreakpoint(locations) {
1072 if (!locations || !locations.length)
1073 this._setBreakpoint(lineNumber, 0, condition, enabled);
1074 else
1075 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled);
1076 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Scrip tsBreakpointSet);
1077 }
1037 } 1078 }
1038 1079
1039 toggleBreakpointOnCurrentLine() { 1080 toggleBreakpointOnCurrentLine() {
1040 if (this._muted) 1081 if (this._muted)
1041 return; 1082 return;
1042 1083
1043 var selection = this.textEditor.selection(); 1084 var selection = this.textEditor.selection();
1044 if (!selection) 1085 if (!selection)
1045 return; 1086 return;
1046 this._toggleBreakpoint(selection.startLine, false); 1087 this._toggleBreakpoint(selection.startLine, false);
1047 } 1088 }
1048 1089
1049 /** 1090 /**
1050 * @param {number} lineNumber 1091 * @param {number} lineNumber
1051 * @param {number} columnNumber 1092 * @param {number} columnNumber
1052 * @param {string} condition 1093 * @param {string} condition
1053 * @param {boolean} enabled 1094 * @param {boolean} enabled
1054 */ 1095 */
1055 _setBreakpoint(lineNumber, columnNumber, condition, enabled) { 1096 _setBreakpoint(lineNumber, columnNumber, condition, enabled) {
1056 if (!WebInspector.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCod e(), lineNumber)) 1097 if (!WebInspector.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCod e(), lineNumber))
1057 return; 1098 return;
1058 1099
1059 this._breakpointManager.setBreakpoint(this.uiSourceCode(), lineNumber, colum nNumber, condition, enabled); 1100 this._breakpointManager.setBreakpoint(this.uiSourceCode(), lineNumber, colum nNumber, condition, enabled);
1101 this._breakpointWasSetForTest(lineNumber, columnNumber, condition, enabled);
1060 } 1102 }
1061 1103
1062 /** 1104 /**
1105 * @param {number} lineNumber
1106 * @param {number} columnNumber
1107 * @param {string} condition
1108 * @param {boolean} enabled
1109 */
1110 _breakpointWasSetForTest(lineNumber, columnNumber, condition, enabled) {
1111 }
1112
1113 /**
1063 * @override 1114 * @override
1064 */ 1115 */
1065 dispose() { 1116 dispose() {
1066 this._breakpointManager.removeEventListener( 1117 this._breakpointManager.removeEventListener(
1067 WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointA dded, this); 1118 WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointA dded, this);
1068 this._breakpointManager.removeEventListener( 1119 this._breakpointManager.removeEventListener(
1069 WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpoin tRemoved, this); 1120 WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpoin tRemoved, this);
1070 this.uiSourceCode().removeEventListener( 1121 this.uiSourceCode().removeEventListener(
1071 WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMap pingChanged, this); 1122 WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMap pingChanged, this);
1072 this.uiSourceCode().removeEventListener( 1123 this.uiSourceCode().removeEventListener(
1073 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh anged, this); 1124 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh anged, this);
1074 this.uiSourceCode().removeEventListener( 1125 this.uiSourceCode().removeEventListener(
1075 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy Committed, this); 1126 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy Committed, this);
1076 this.uiSourceCode().removeEventListener( 1127 this.uiSourceCode().removeEventListener(
1077 WebInspector.UISourceCode.Events.TitleChanged, this._showBlackboxInfobar IfNeeded, this); 1128 WebInspector.UISourceCode.Events.TitleChanged, this._showBlackboxInfobar IfNeeded, this);
1078 WebInspector.moduleSetting('skipStackFramesPattern').removeChangeListener(th is._showBlackboxInfobarIfNeeded, this); 1129 WebInspector.moduleSetting('skipStackFramesPattern').removeChangeListener(th is._showBlackboxInfobarIfNeeded, this);
1079 WebInspector.moduleSetting('skipContentScripts').removeChangeListener(this._ showBlackboxInfobarIfNeeded, this); 1130 WebInspector.moduleSetting('skipContentScripts').removeChangeListener(this._ showBlackboxInfobarIfNeeded, this);
1080 super.dispose(); 1131 super.dispose();
1081 } 1132 }
1082 }; 1133 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698