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

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

Issue 2613643002: DevTools: migrate from external Maps to symbols in the bindings objects. (Closed)
Patch Set: Created 3 years, 11 months 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
(...skipping 25 matching lines...) Expand all
36 * @param {!SDK.DebuggerModel} debuggerModel 36 * @param {!SDK.DebuggerModel} debuggerModel
37 * @param {!Workspace.Workspace} workspace 37 * @param {!Workspace.Workspace} workspace
38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding 38 * @param {!Bindings.DebuggerWorkspaceBinding} debuggerWorkspaceBinding
39 */ 39 */
40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) { 40 constructor(debuggerModel, workspace, debuggerWorkspaceBinding) {
41 this._debuggerModel = debuggerModel; 41 this._debuggerModel = debuggerModel;
42 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding; 42 this._debuggerWorkspaceBinding = debuggerWorkspaceBinding;
43 var projectId = Bindings.DefaultScriptMapping.projectIdForTarget(debuggerMod el.target()); 43 var projectId = Bindings.DefaultScriptMapping.projectIdForTarget(debuggerMod el.target());
44 this._project = new Bindings.ContentProviderBasedProject( 44 this._project = new Bindings.ContentProviderBasedProject(
45 workspace, projectId, Workspace.projectTypes.Debugger, '', true /* isSer viceProject */); 45 workspace, projectId, Workspace.projectTypes.Debugger, '', true /* isSer viceProject */);
46 /** @type {!Map.<string, !Workspace.UISourceCode>} */
47 this._uiSourceCodeForScriptId = new Map();
48 /** @type {!Map.<!Workspace.UISourceCode, string>} */
49 this._scriptIdForUISourceCode = new Map();
50 this._eventListeners = 46 this._eventListeners =
51 [debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCle ared, this._debuggerReset, this)]; 47 [debuggerModel.addEventListener(SDK.DebuggerModel.Events.GlobalObjectCle ared, this._debuggerReset, this)];
52 } 48 }
53 49
54 /** 50 /**
55 * @param {!Workspace.UISourceCode} uiSourceCode 51 * @param {!Workspace.UISourceCode} uiSourceCode
56 * @return {?SDK.Script} 52 * @return {?SDK.Script}
57 */ 53 */
58 static scriptForUISourceCode(uiSourceCode) { 54 static scriptForUISourceCode(uiSourceCode) {
59 return uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] || null; 55 return uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] || null;
60 } 56 }
61 57
62 /** 58 /**
63 * @param {!SDK.Target} target 59 * @param {!SDK.Target} target
64 * @return {string} 60 * @return {string}
65 */ 61 */
66 static projectIdForTarget(target) { 62 static projectIdForTarget(target) {
67 return 'debugger:' + target.id(); 63 return 'debugger:' + target.id();
68 } 64 }
69 65
70 /** 66 /**
71 * @override 67 * @override
72 * @param {!SDK.DebuggerModel.Location} rawLocation 68 * @param {!SDK.DebuggerModel.Location} rawLocation
73 * @return {!Workspace.UILocation} 69 * @return {!Workspace.UILocation}
74 */ 70 */
75 rawLocationToUILocation(rawLocation) { 71 rawLocationToUILocation(rawLocation) {
76 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL ocation); 72 var debuggerModelLocation = /** @type {!SDK.DebuggerModel.Location} */ (rawL ocation);
77 var script = debuggerModelLocation.script(); 73 var script = debuggerModelLocation.script();
78 var uiSourceCode = this._uiSourceCodeForScriptId.get(script.scriptId); 74 var uiSourceCode = script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol] ;
79 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi thSourceURL() ? script.lineOffset : 0); 75 var lineNumber = debuggerModelLocation.lineNumber - (script.isInlineScriptWi thSourceURL() ? script.lineOffset : 0);
80 var columnNumber = debuggerModelLocation.columnNumber || 0; 76 var columnNumber = debuggerModelLocation.columnNumber || 0;
81 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber) 77 if (script.isInlineScriptWithSourceURL() && !lineNumber && columnNumber)
82 columnNumber -= script.columnOffset; 78 columnNumber -= script.columnOffset;
83 return uiSourceCode.uiLocation(lineNumber, columnNumber); 79 return uiSourceCode.uiLocation(lineNumber, columnNumber);
84 } 80 }
85 81
86 /** 82 /**
87 * @override 83 * @override
88 * @param {!Workspace.UISourceCode} uiSourceCode 84 * @param {!Workspace.UISourceCode} uiSourceCode
89 * @param {number} lineNumber 85 * @param {number} lineNumber
90 * @param {number} columnNumber 86 * @param {number} columnNumber
91 * @return {?SDK.DebuggerModel.Location} 87 * @return {?SDK.DebuggerModel.Location}
92 */ 88 */
93 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) { 89 uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber) {
94 var scriptId = this._scriptIdForUISourceCode.get(uiSourceCode); 90 var script = uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol];
95 var script = this._debuggerModel.scriptForId(scriptId);
96 if (script.isInlineScriptWithSourceURL()) { 91 if (script.isInlineScriptWithSourceURL()) {
97 return this._debuggerModel.createRawLocation( 92 return this._debuggerModel.createRawLocation(
98 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co lumnNumber + script.columnOffset); 93 script, lineNumber + script.lineOffset, lineNumber ? columnNumber : co lumnNumber + script.columnOffset);
99 } 94 }
100 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe r); 95 return this._debuggerModel.createRawLocation(script, lineNumber, columnNumbe r);
101 } 96 }
102 97
103 /** 98 /**
104 * @param {!SDK.Script} script 99 * @param {!SDK.Script} script
105 */ 100 */
106 addScript(script) { 101 addScript(script) {
107 var name = Common.ParsedURL.extractName(script.sourceURL); 102 var name = Common.ParsedURL.extractName(script.sourceURL);
108 var url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : ''); 103 var url = 'debugger:///VM' + script.scriptId + (name ? ' ' + name : '');
109 104
110 var uiSourceCode = this._project.createUISourceCode(url, Common.resourceType s.Script); 105 var uiSourceCode = this._project.createUISourceCode(url, Common.resourceType s.Script);
111 uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] = script; 106 uiSourceCode[Bindings.DefaultScriptMapping._scriptSymbol] = script;
112 this._uiSourceCodeForScriptId.set(script.scriptId, uiSourceCode); 107 script[Bindings.DefaultScriptMapping._uiSourceCodeSymbol] = uiSourceCode;
113 this._scriptIdForUISourceCode.set(uiSourceCode, script.scriptId);
114 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null); 108 this._project.addUISourceCodeWithProvider(uiSourceCode, script, null);
115 109
116 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel.target() , uiSourceCode, this); 110 this._debuggerWorkspaceBinding.setSourceMapping(this._debuggerModel.target() , uiSourceCode, this);
117 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); 111 this._debuggerWorkspaceBinding.pushSourceMapping(script, this);
118 } 112 }
119 113
120 /** 114 /**
121 * @override 115 * @override
122 * @return {boolean} 116 * @return {boolean}
123 */ 117 */
124 isIdentity() { 118 isIdentity() {
125 return true; 119 return true;
126 } 120 }
127 121
128 /** 122 /**
129 * @override 123 * @override
130 * @param {!Workspace.UISourceCode} uiSourceCode 124 * @param {!Workspace.UISourceCode} uiSourceCode
131 * @param {number} lineNumber 125 * @param {number} lineNumber
132 * @return {boolean} 126 * @return {boolean}
133 */ 127 */
134 uiLineHasMapping(uiSourceCode, lineNumber) { 128 uiLineHasMapping(uiSourceCode, lineNumber) {
135 return true; 129 return true;
136 } 130 }
137 131
138 _debuggerReset() { 132 _debuggerReset() {
139 this._uiSourceCodeForScriptId.clear();
140 this._scriptIdForUISourceCode.clear();
141 this._project.reset(); 133 this._project.reset();
142 } 134 }
143 135
144 dispose() { 136 dispose() {
145 Common.EventTarget.removeEventListeners(this._eventListeners); 137 Common.EventTarget.removeEventListeners(this._eventListeners);
146 this._debuggerReset(); 138 this._debuggerReset();
147 this._project.dispose(); 139 this._project.dispose();
148 } 140 }
149 }; 141 };
150 142
151 Bindings.DefaultScriptMapping._scriptSymbol = Symbol('symbol'); 143 Bindings.DefaultScriptMapping._scriptSymbol = Symbol('symbol');
144 Bindings.DefaultScriptMapping._uiSourceCodeSymbol = Symbol('uiSourceCodeSymbol') ;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698