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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/bindings/DefaultScriptMapping.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor
33 * @implements {WebInspector.DebuggerSourceMapping} 31 * @implements {WebInspector.DebuggerSourceMapping}
34 * @param {!WebInspector.DebuggerModel} debuggerModel 32 * @unrestricted
35 * @param {!WebInspector.Workspace} workspace
36 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
37 */ 33 */
38 WebInspector.DefaultScriptMapping = function(debuggerModel, workspace, debuggerW orkspaceBinding) 34 WebInspector.DefaultScriptMapping = class {
39 { 35 /**
36 * @param {!WebInspector.DebuggerModel} debuggerModel
37 * @param {!WebInspector.Workspace} workspace
38 * @param {!WebInspector.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
39 */
40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
40 this._debuggerModel = debuggerModel; 41 this._debuggerModel = debuggerModel;
41 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; 42 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
42 var projectId = WebInspector.DefaultScriptMapping.projectIdForTarget(debugge rModel.target()); 43 var projectId = WebInspector.DefaultScriptMapping.projectIdForTarget(debugge rModel.target());
43 this._project = new WebInspector.ContentProviderBasedProject(workspace, proj ectId, WebInspector.projectTypes.Debugger, ""); 44 this._project =
45 new WebInspector.ContentProviderBasedProject(workspace, projectId, WebIn spector.projectTypes.Debugger, '');
44 /** @type {!Map.<string, !WebInspector.UISourceCode>} */ 46 /** @type {!Map.<string, !WebInspector.UISourceCode>} */
45 this._uiSourceCodeForScriptId = new Map(); 47 this._uiSourceCodeForScriptId = new Map();
46 /** @type {!Map.<!WebInspector.UISourceCode, string>} */ 48 /** @type {!Map.<!WebInspector.UISourceCode, string>} */
47 this._scriptIdForUISourceCode = new Map(); 49 this._scriptIdForUISourceCode = new Map();
48 this._eventListeners = [ 50 this._eventListeners = [debuggerModel.addEventListener(
49 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalO bjectCleared, this._debuggerReset, this) 51 WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerRes et, this)];
50 ]; 52 }
53
54 /**
55 * @param {!WebInspector.UISourceCode} uiSourceCode
56 * @return {?WebInspector.Script}
57 */
58 static scriptForUISourceCode(uiSourceCode) {
59 return uiSourceCode[WebInspector.DefaultScriptMapping._scriptSymbol] || null ;
60 }
61
62 /**
63 * @param {!WebInspector.Target} target
64 * @return {string}
65 */
66 static projectIdForTarget(target) {
67 return 'debugger:' + target.id();
68 }
69
70 /**
71 * @override
72 * @param {!WebInspector.DebuggerModel.Location} rawLocation
73 * @return {!WebInspector.UILocation}
74 */
75 rawLocationToUILocation(rawLocation) {
76 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Location} */ (rawLocation);
77 var script = debuggerModelLocation.script();
78 var uiSourceCode = this._uiSourceCodeForScriptId.get(script.scriptId);
79 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi thSourceURL() ? script.lineOffset : 0);
80 var columnNumber = debuggerModelLocation.columnNumber || 0;
81 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber)
82 columnNumber -= script.columnOffset;
83 return uiSourceCode.uiLocation(lineNumber, columnNumber);
84 }
85
86 /**
87 * @override
88 * @param {!WebInspector.UISourceCode} uiSourceCode
89 * @param {number} lineNumber
90 * @param {number} columnNumber
91 * @return {?WebInspector.DebuggerModel.Location}
92 */
93 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
94 var scriptId = this._scriptIdForUISourceCode.get(uiSourceCode);
95 var script = this._debuggerModel.scriptForId(scriptId);
96 if (script.isInlineScriptWithSourceURL())
97 return this._debuggerModel.createRawLocation(
98 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co lumnNumber + script.columnOffset);
99 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe r);
100 }
101
102 /**
103 * @param {!WebInspector.Script} script
104 */
105 addScript(script) {
106 var name = WebInspector.ParsedURL.extractName(script.sourceURL);
107 var url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : '');
108
109 var uiSourceCode = this._project.createUISourceCode(url, WebInspector.resour ceTypes.Script);
110 uiSourceCode[WebInspector.DefaultScriptMapping._scriptSymbol] = script;
111 this._uiSourceCodeForScriptId.set(script.scriptId, uiSourceCode);
112 this._scriptIdForUISourceCode.set(uiSourceCode, script.scriptId);
113 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null);
114
115 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel.target() , uiSourceCode, this);
116 this._debuggerWorkspaceBinding.pushSourceMapping(script, this);
117 }
118
119 /**
120 * @override
121 * @return {boolean}
122 */
123 isIdentity() {
124 return true;
125 }
126
127 /**
128 * @override
129 * @param {!WebInspector.UISourceCode} uiSourceCode
130 * @param {number} lineNumber
131 * @return {boolean}
132 */
133 uiLineHasMapping(uiSourceCode, lineNumber) {
134 return true;
135 }
136
137 _debuggerReset() {
138 this._uiSourceCodeForScriptId.clear();
139 this._scriptIdForUISourceCode.clear();
140 this._project.reset();
141 }
142
143 dispose() {
144 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
145 this._debuggerReset();
146 this._project.dispose();
147 }
51 }; 148 };
52 149
53 WebInspector.DefaultScriptMapping._scriptSymbol = Symbol("symbol"); 150 WebInspector.DefaultScriptMapping._scriptSymbol = Symbol('symbol');
54 151
55 /**
56 * @param {!WebInspector.UISourceCode} uiSourceCode
57 * @return {?WebInspector.Script}
58 */
59 WebInspector.DefaultScriptMapping.scriptForUISourceCode = function(uiSourceCode)
60 {
61 return uiSourceCode[WebInspector.DefaultScriptMapping._scriptSymbol] || null ;
62 };
63 152
64 WebInspector.DefaultScriptMapping.prototype = {
65 /**
66 * @override
67 * @param {!WebInspector.DebuggerModel.Location} rawLocation
68 * @return {!WebInspector.UILocation}
69 */
70 rawLocationToUILocation: function(rawLocation)
71 {
72 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation);
73 var script = debuggerModelLocation.script();
74 var uiSourceCode = this._uiSourceCodeForScriptId.get(script.scriptId);
75 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScri ptWithSourceURL() ? script.lineOffset : 0);
76 var columnNumber = debuggerModelLocation.columnNumber || 0;
77 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber)
78 columnNumber -= script.columnOffset;
79 return uiSourceCode.uiLocation(lineNumber, columnNumber);
80 },
81
82 /**
83 * @override
84 * @param {!WebInspector.UISourceCode} uiSourceCode
85 * @param {number} lineNumber
86 * @param {number} columnNumber
87 * @return {?WebInspector.DebuggerModel.Location}
88 */
89 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
90 {
91 var scriptId = this._scriptIdForUISourceCode.get(uiSourceCode);
92 var script = this._debuggerModel.scriptForId(scriptId);
93 if (script.isInlineScriptWithSourceURL())
94 return this._debuggerModel.createRawLocation(script, lineNumber + sc ript.lineOffset, lineNumber ? columnNumber : columnNumber + script.columnOffset) ;
95 return this._debuggerModel.createRawLocation(script, lineNumber, columnN umber);
96 },
97
98 /**
99 * @param {!WebInspector.Script} script
100 */
101 addScript: function(script)
102 {
103 var name = WebInspector.ParsedURL.extractName(script.sourceURL);
104 var url = "debugger:///VM" + script.scriptId + (name ? " " + name : "");
105
106 var uiSourceCode = this._project.createUISourceCode(url, WebInspector.re sourceTypes.Script);
107 uiSourceCode[WebInspector.DefaultScriptMapping._scriptSymbol] = script;
108 this._uiSourceCodeForScriptId.set(script.scriptId, uiSourceCode);
109 this._scriptIdForUISourceCode.set(uiSourceCode, script.scriptId);
110 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null);
111
112 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel.targ et(), uiSourceCode, this);
113 this._debuggerWorkspaceBinding.pushSourceMapping(script, this);
114 },
115
116 /**
117 * @override
118 * @return {boolean}
119 */
120 isIdentity: function()
121 {
122 return true;
123 },
124
125 /**
126 * @override
127 * @param {!WebInspector.UISourceCode} uiSourceCode
128 * @param {number} lineNumber
129 * @return {boolean}
130 */
131 uiLineHasMapping: function(uiSourceCode, lineNumber)
132 {
133 return true;
134 },
135
136 _debuggerReset: function()
137 {
138 this._uiSourceCodeForScriptId.clear();
139 this._scriptIdForUISourceCode.clear();
140 this._project.reset();
141 },
142
143 dispose: function()
144 {
145 WebInspector.EventTarget.removeEventListeners(this._eventListeners);
146 this._debuggerReset();
147 this._project.dispose();
148 }
149 };
150
151 /**
152 * @param {!WebInspector.Target} target
153 * @return {string}
154 */
155 WebInspector.DefaultScriptMapping.projectIdForTarget = function(target)
156 {
157 return "debugger:" + target.id();
158 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698