Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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) | |
|
dgozman
2016/11/10 19:06:52
if (locations || !linesToCheck)
kozy
2016/11/10 19:49:53
Done.
| |
| 1062 return Promise.resolve(/** @type {?Array<!WebInspector.UILocation>} */(l ocations)); | |
|
dgozman
2016/11/10 19:06:52
No need to cast.
kozy
2016/11/10 19:49:53
Done.
| |
| 1063 if (linesToCheck <= 0) | |
| 1064 return Promise.resolve(/** @type {?Array<!WebInspector.UILocation>} */(l ocations)); | |
| 1065 return findPossibleBreakpoints.call(this, currentLineNumber + 1) | |
| 1066 .then(checkNextLineIfNeeded.bind(this, currentLineNumber + 1, linesToC heck - 1)); | |
| 1067 } | |
| 1068 | |
| 1069 /** | |
| 1070 * @this {!WebInspector.JavaScriptSourceFrame} | |
| 1071 * @param {?Array<!WebInspector.UILocation>} locations | |
| 1072 */ | |
| 1073 function setBreakpoint(locations) { | |
| 1074 if (!locations || !locations.length) | |
| 1075 this._setBreakpoint(lineNumber, 0, condition, enabled); | |
| 1076 else | |
| 1077 this._setBreakpoint(locations[0].lineNumber, locations[0].columnNumber, condition, enabled); | |
| 1078 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Scrip tsBreakpointSet); | |
| 1079 } | |
| 1037 } | 1080 } |
| 1038 | 1081 |
| 1039 toggleBreakpointOnCurrentLine() { | 1082 toggleBreakpointOnCurrentLine() { |
| 1040 if (this._muted) | 1083 if (this._muted) |
| 1041 return; | 1084 return; |
| 1042 | 1085 |
| 1043 var selection = this.textEditor.selection(); | 1086 var selection = this.textEditor.selection(); |
| 1044 if (!selection) | 1087 if (!selection) |
| 1045 return; | 1088 return; |
| 1046 this._toggleBreakpoint(selection.startLine, false); | 1089 this._toggleBreakpoint(selection.startLine, false); |
| 1047 } | 1090 } |
| 1048 | 1091 |
| 1049 /** | 1092 /** |
| 1050 * @param {number} lineNumber | 1093 * @param {number} lineNumber |
| 1051 * @param {number} columnNumber | 1094 * @param {number} columnNumber |
| 1052 * @param {string} condition | 1095 * @param {string} condition |
| 1053 * @param {boolean} enabled | 1096 * @param {boolean} enabled |
| 1054 */ | 1097 */ |
| 1055 _setBreakpoint(lineNumber, columnNumber, condition, enabled) { | 1098 _setBreakpoint(lineNumber, columnNumber, condition, enabled) { |
| 1056 if (!WebInspector.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCod e(), lineNumber)) | 1099 if (!WebInspector.debuggerWorkspaceBinding.uiLineHasMapping(this.uiSourceCod e(), lineNumber)) |
| 1057 return; | 1100 return; |
| 1058 | 1101 |
| 1059 this._breakpointManager.setBreakpoint(this.uiSourceCode(), lineNumber, colum nNumber, condition, enabled); | 1102 this._breakpointManager.setBreakpoint(this.uiSourceCode(), lineNumber, colum nNumber, condition, enabled); |
| 1103 this._breakpointWasSetForTest(lineNumber, columnNumber, condition, enabled); | |
| 1060 } | 1104 } |
| 1061 | 1105 |
| 1062 /** | 1106 /** |
| 1107 * @param {number} lineNumber | |
| 1108 * @param {number} columnNumber | |
| 1109 * @param {string} condition | |
| 1110 * @param {boolean} enabled | |
| 1111 */ | |
| 1112 _breakpointWasSetForTest(lineNumber, columnNumber, condition, enabled) { | |
| 1113 } | |
| 1114 | |
| 1115 /** | |
| 1063 * @override | 1116 * @override |
| 1064 */ | 1117 */ |
| 1065 dispose() { | 1118 dispose() { |
| 1066 this._breakpointManager.removeEventListener( | 1119 this._breakpointManager.removeEventListener( |
| 1067 WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointA dded, this); | 1120 WebInspector.BreakpointManager.Events.BreakpointAdded, this._breakpointA dded, this); |
| 1068 this._breakpointManager.removeEventListener( | 1121 this._breakpointManager.removeEventListener( |
| 1069 WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpoin tRemoved, this); | 1122 WebInspector.BreakpointManager.Events.BreakpointRemoved, this._breakpoin tRemoved, this); |
| 1070 this.uiSourceCode().removeEventListener( | 1123 this.uiSourceCode().removeEventListener( |
| 1071 WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMap pingChanged, this); | 1124 WebInspector.UISourceCode.Events.SourceMappingChanged, this._onSourceMap pingChanged, this); |
| 1072 this.uiSourceCode().removeEventListener( | 1125 this.uiSourceCode().removeEventListener( |
| 1073 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh anged, this); | 1126 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyCh anged, this); |
| 1074 this.uiSourceCode().removeEventListener( | 1127 this.uiSourceCode().removeEventListener( |
| 1075 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy Committed, this); | 1128 WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopy Committed, this); |
| 1076 this.uiSourceCode().removeEventListener( | 1129 this.uiSourceCode().removeEventListener( |
| 1077 WebInspector.UISourceCode.Events.TitleChanged, this._showBlackboxInfobar IfNeeded, this); | 1130 WebInspector.UISourceCode.Events.TitleChanged, this._showBlackboxInfobar IfNeeded, this); |
| 1078 WebInspector.moduleSetting('skipStackFramesPattern').removeChangeListener(th is._showBlackboxInfobarIfNeeded, this); | 1131 WebInspector.moduleSetting('skipStackFramesPattern').removeChangeListener(th is._showBlackboxInfobarIfNeeded, this); |
| 1079 WebInspector.moduleSetting('skipContentScripts').removeChangeListener(this._ showBlackboxInfobarIfNeeded, this); | 1132 WebInspector.moduleSetting('skipContentScripts').removeChangeListener(this._ showBlackboxInfobarIfNeeded, this); |
| 1080 super.dispose(); | 1133 super.dispose(); |
| 1081 } | 1134 } |
| 1082 }; | 1135 }; |
| OLD | NEW |