Title: [111694] trunk/Source/WebCore
Revision
111694
Author
vse...@chromium.org
Date
2012-03-22 07:48:01 -0700 (Thu, 22 Mar 2012)

Log Message

Web Inspector: Introduce ScriptBound/ScriptUnbound events in ScriptMapping.
https://bugs.webkit.org/show_bug.cgi?id=81904

Reviewed by Pavel Feldman.

This is another step on the way to cleaner BreakpointManager logic.
Here we extract ScriptBound/ScriptUnbound events from UISourceCodeListChanged event.
This allows us to handle script-uiSourceCode binding separately from
uiSourceCode creation/deletion and to handle unbinding that was not
possible at all before.

* inspector/front-end/CompilerScriptMapping.js:
(WebInspector.CompilerScriptMapping.prototype._uiSourceCodesForSourceMap):
(WebInspector.CompilerScriptMapping.prototype.addScript.get this):
(WebInspector.CompilerScriptMapping.prototype.addScript):
(WebInspector.CompilerScriptMapping.prototype.reset):
* inspector/front-end/ResourceScriptMapping.js:
(WebInspector.ResourceScriptMapping.prototype._uiSourceCodeChanged):
* inspector/front-end/ScriptMapping.js:
(WebInspector.MainScriptMapping):
(WebInspector.MainScriptMapping.prototype._updateLiveLocation):
(WebInspector.MainScriptMapping.prototype._handleUISourceCodeListChanged):
(WebInspector.MainScriptMapping.prototype._handleScriptBound):
(WebInspector.MainScriptMapping.prototype._handleScriptUnbound):
* inspector/front-end/SnippetsModel.js:
(WebInspector.SnippetsScriptMapping.prototype.addScript.get this):
(WebInspector.SnippetsScriptMapping.prototype._snippetAdded):
(WebInspector.SnippetsScriptMapping.prototype._createUISourceCodeForScript):
(WebInspector.SnippetsScriptMapping.prototype._snippetRemoved.get this):
(WebInspector.SnippetsScriptMapping.prototype._snippetRemoved):
(WebInspector.SnippetsScriptMapping.prototype.reset):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (111693 => 111694)


--- trunk/Source/WebCore/ChangeLog	2012-03-22 14:39:22 UTC (rev 111693)
+++ trunk/Source/WebCore/ChangeLog	2012-03-22 14:48:01 UTC (rev 111694)
@@ -1,3 +1,37 @@
+2012-03-22  Vsevolod Vlasov  <vse...@chromium.org>
+
+        Web Inspector: Introduce ScriptBound/ScriptUnbound events in ScriptMapping.
+        https://bugs.webkit.org/show_bug.cgi?id=81904
+
+        Reviewed by Pavel Feldman.
+
+        This is another step on the way to cleaner BreakpointManager logic.
+        Here we extract ScriptBound/ScriptUnbound events from UISourceCodeListChanged event.
+        This allows us to handle script-uiSourceCode binding separately from
+        uiSourceCode creation/deletion and to handle unbinding that was not
+        possible at all before.
+
+        * inspector/front-end/CompilerScriptMapping.js:
+        (WebInspector.CompilerScriptMapping.prototype._uiSourceCodesForSourceMap):
+        (WebInspector.CompilerScriptMapping.prototype.addScript.get this):
+        (WebInspector.CompilerScriptMapping.prototype.addScript):
+        (WebInspector.CompilerScriptMapping.prototype.reset):
+        * inspector/front-end/ResourceScriptMapping.js:
+        (WebInspector.ResourceScriptMapping.prototype._uiSourceCodeChanged):
+        * inspector/front-end/ScriptMapping.js:
+        (WebInspector.MainScriptMapping):
+        (WebInspector.MainScriptMapping.prototype._updateLiveLocation):
+        (WebInspector.MainScriptMapping.prototype._handleUISourceCodeListChanged):
+        (WebInspector.MainScriptMapping.prototype._handleScriptBound):
+        (WebInspector.MainScriptMapping.prototype._handleScriptUnbound):
+        * inspector/front-end/SnippetsModel.js:
+        (WebInspector.SnippetsScriptMapping.prototype.addScript.get this):
+        (WebInspector.SnippetsScriptMapping.prototype._snippetAdded):
+        (WebInspector.SnippetsScriptMapping.prototype._createUISourceCodeForScript):
+        (WebInspector.SnippetsScriptMapping.prototype._snippetRemoved.get this):
+        (WebInspector.SnippetsScriptMapping.prototype._snippetRemoved):
+        (WebInspector.SnippetsScriptMapping.prototype.reset):
+
 2012-03-22  Vineet Chaudhary  <rgf...@motorola.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=81893

Modified: trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js (111693 => 111694)


--- trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2012-03-22 14:39:22 UTC (rev 111693)
+++ trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js	2012-03-22 14:48:01 UTC (rev 111694)
@@ -79,6 +79,19 @@
     },
 
     /**
+     * @param {WebInspector.SourceMapParser} sourceMap
+     * @return {Array.<WebInspector.UISourceCode>}
+     */
+    _uiSourceCodesForSourceMap: function(sourceMap)
+    {
+        var result = []
+        var sourceURLs = sourceMap.sources();
+        for (var i = 0; i < sourceURLs.length; ++i)
+            result.push(this._uiSourceCodeByURL[sourceURLs[i]]);
+        return result;
+    },
+
+    /**
      * @param {WebInspector.Script} script
      */
     addScript: function(script)
@@ -87,8 +100,9 @@
 
         if (this._scriptForSourceMap.get(sourceMap)) {
             this._sourceMapForScriptId[script.scriptId] = sourceMap;
-            var data = { removedItems: [], addedItems: [], scriptIds: [script.scriptId] };
-            this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+            var uiSourceCodes = this._uiSourceCodesForSourceMap(sourceMap);
+            var data = { scriptId: script.scriptId, uiSourceCodes: uiSourceCodes };
+            this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);
             return;
         }
 
@@ -109,8 +123,10 @@
 
         this._sourceMapForScriptId[script.scriptId] = sourceMap;
         this._scriptForSourceMap.put(sourceMap, script);
-        var data = { removedItems: [], addedItems: uiSourceCodeList, scriptIds: [script.scriptId] };
+        var data = { removedItems: [], addedItems: uiSourceCodeList };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+        var data = { scriptId: script.scriptId, uiSourceCodes: uiSourceCodeList };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);
     },
 
     /**
@@ -134,7 +150,7 @@
 
     reset: function()
     {
-        var data = { removedItems: this.uiSourceCodeList(), addedItems: [], scriptIds: [] };
+        var data = { removedItems: this.uiSourceCodeList(), addedItems: [] };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
 
         this._sourceMapByURL = {};

Modified: trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js (111693 => 111694)


--- trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js	2012-03-22 14:39:22 UTC (rev 111693)
+++ trunk/Source/WebCore/inspector/front-end/ResourceScriptMapping.js	2012-03-22 14:48:01 UTC (rev 111694)
@@ -139,8 +139,23 @@
             scriptIds.push(rawSourceCode._scripts[i].scriptId);
         var removedItems = removedItem ? [removedItem] : [];
         var addedItems = addedItem ? [addedItem] : [];
-        var data = { removedItems: removedItems, addedItems: addedItems, scriptIds: scriptIds };
+
+        if (removedItem) {
+            for (var i = 0; i < scriptIds.length; ++i) {
+                var data = { scriptId: scriptIds[i], uiSourceCodes: [removedItem] };
+                this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptUnbound, data);
+            }
+        }
+
+        var data = { removedItems: removedItems, addedItems: addedItems };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+
+        if (addedItem) {
+            for (var i = 0; i < scriptIds.length; ++i) {
+                var data = { scriptId: scriptIds[i], uiSourceCodes: [addedItem] };
+                this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);
+            }
+        }
     },
 
     /**

Modified: trunk/Source/WebCore/inspector/front-end/ScriptMapping.js (111693 => 111694)


--- trunk/Source/WebCore/inspector/front-end/ScriptMapping.js	2012-03-22 14:39:22 UTC (rev 111693)
+++ trunk/Source/WebCore/inspector/front-end/ScriptMapping.js	2012-03-22 14:48:01 UTC (rev 111694)
@@ -37,7 +37,9 @@
 }
 
 WebInspector.ScriptMapping.Events = {
-    UISourceCodeListChanged: "us-source-code-list-changed"
+    UISourceCodeListChanged: "ui-source-code-list-changed",
+    ScriptBound: "script-bound",
+    ScriptUnbound: "script-unbound",
 }
 
 WebInspector.ScriptMapping.prototype = {
@@ -78,8 +80,11 @@
     this._snippetsMapping = new WebInspector.SnippetsScriptMapping();
     this._mappings.push(this._snippetsMapping);
 
-    for (var i = 0; i < this._mappings.length; ++i)
+    for (var i = 0; i < this._mappings.length; ++i) {
         this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, this._handleUISourceCodeListChanged, this);
+        this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.ScriptBound, this._handleScriptBound, this);
+        this._mappings[i].addEventListener(WebInspector.ScriptMapping.Events.ScriptUnbound, this._handleScriptUnbound, this);
+    }
 
     this._mappingForScriptId = {};
     this._mappingForUISourceCode = new Map();
@@ -87,7 +92,7 @@
 }
 
 WebInspector.MainScriptMapping.Events = {
-    UISourceCodeListChanged: "us-source-code-list-changed"
+    UISourceCodeListChanged: "ui-source-code-list-changed"
 }
 
 WebInspector.MainScriptMapping.prototype = {
@@ -133,13 +138,11 @@
             this._liveLocationsForScriptId[scriptId].remove(liveLocation);
     },
 
-    _updateLiveLocations: function(scriptIds)
+    _updateLiveLocation: function(scriptId)
     {
-        for (var i = 0; i < scriptIds.length; ++i) {
-            var liveLocations = this._liveLocationsForScriptId[scriptIds[i]];
-            for (var j = 0; j < liveLocations.length; ++j)
-                liveLocations[j]._update();
-        }
+        var liveLocations = this._liveLocationsForScriptId[scriptId];
+        for (var j = 0; j < liveLocations.length; ++j)
+            liveLocations[j]._update();
     },
 
     /**
@@ -195,17 +198,34 @@
         var scriptMapping = /** @type {WebInspector.ScriptMapping} */ event.target;
         var removedItems = /** @type {Array.<WebInspector.UISourceCode>} */ event.data["removedItems"];
         var addedItems = /** @type {Array.<WebInspector.UISourceCode>} */ event.data["addedItems"];
-        var scriptIds = /** @type {Array.<number>} */ event.data["scriptIds"];
 
         for (var i = 0; i < removedItems.length; ++i)
             this._mappingForUISourceCode.remove(removedItems[i]);
         for (var i = 0; i < addedItems.length; ++i)
             this._mappingForUISourceCode.put(addedItems[i], scriptMapping);
-        this._updateLiveLocations(scriptIds);
         this.dispatchEventToListeners(WebInspector.MainScriptMapping.Events.UISourceCodeListChanged, event.data);
     },
 
     /**
+     * @param {WebInspector.Event} event
+     */
+    _handleScriptBound: function(event)
+    {
+        var scriptId = /** @type {number} */ event.data.scriptId;
+        this._updateLiveLocation(scriptId);
+    },
+
+    /**
+     * @param {WebInspector.Event} event
+     */
+    _handleScriptUnbound: function(event)
+    {
+        var scriptId = /** @type {number} */ event.data.scriptId;
+        this._updateLiveLocation(scriptId);
+    },
+
+
+    /**
      * @param {boolean} formatSource
      */
     setFormatSource: function(formatSource)

Modified: trunk/Source/WebCore/inspector/front-end/SnippetsModel.js (111693 => 111694)


--- trunk/Source/WebCore/inspector/front-end/SnippetsModel.js	2012-03-22 14:39:22 UTC (rev 111693)
+++ trunk/Source/WebCore/inspector/front-end/SnippetsModel.js	2012-03-22 14:48:01 UTC (rev 111694)
@@ -276,7 +276,7 @@
     this._uiSourceCodeForScriptId = {};
     this._scriptForUISourceCode = new Map();
     this._uiSourceCodeForSnippet = new Map();
-    
+
     WebInspector.snippetsModel.addEventListener(WebInspector.SnippetsModel.EventTypes.SnippetAdded, this._snippetAdded.bind(this));
     WebInspector.snippetsModel.addEventListener(WebInspector.SnippetsModel.EventTypes.SnippetWillBeEvaluated, this._snippetWillBeEvaluated.bind(this));
     WebInspector.snippetsModel.addEventListener(WebInspector.SnippetsModel.EventTypes.SnippetRemoved, this._snippetRemoved.bind(this));
@@ -363,8 +363,8 @@
         this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
         this._snippetForScriptId[script.scriptId] = snippet;
         this._scriptForUISourceCode.put(uiSourceCode, script);
-        var data = { removedItems: [], addedItems: [], scriptIds: [script.scriptId] };
-        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);        
+        var data = { scriptId: script.scriptId, uiSourceCodes: [uiSourceCode] };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);
     },
 
     /**
@@ -380,7 +380,7 @@
         uiSourceCode.isEditable = true;
         this._uiSourceCodeForSnippet.put(snippet, uiSourceCode);
         uiSourceCode.snippet = snippet;
-        var data = { removedItems: [], addedItems: [uiSourceCode], scriptIds: [] };
+        var data = { removedItems: [], addedItems: [uiSourceCode] };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
     },
 
@@ -400,10 +400,15 @@
     {
         var uiSourceCode = new WebInspector.UISourceCode(script.sourceURL, script.sourceURL, new WebInspector.ScriptContentProvider(script));
         uiSourceCode.isSnippetEvaluation = true;
+        var oldUISourceCode = this._uiSourceCodeForScriptId[script.scriptId];
         this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
         this._scriptForUISourceCode.put(uiSourceCode, script);
-        var data = { removedItems: [], addedItems: [uiSourceCode], scriptIds: [script.scriptId] };
+        var data = { scriptId: script.scriptId, uiSourceCodes: [oldUISourceCode] };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptUnbound, data);
+        var data = { removedItems: [], addedItems: [uiSourceCode] };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
+        var data = { scriptId: script.scriptId, uiSourceCodes: [uiSourceCode] };
+        this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.ScriptBound, data);
     },
 
     /**
@@ -432,7 +437,7 @@
         var uiSourceCode = this._uiSourceCodeForSnippet.get(snippet);
         this._releaseSnippetScript(snippet);
         this._uiSourceCodeForSnippet.remove(snippet);
-        var data = { removedItems: [uiSourceCode], addedItems: [], scriptIds: [] };
+        var data = { removedItems: [uiSourceCode], addedItems: [] };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
     },
 
@@ -442,7 +447,7 @@
         this._snippetForScriptId = {};
         this._uiSourceCodeForScriptId = {};
         this._scriptForUISourceCode = new Map();
-        var data = { removedItems: removedUISourceCodes, addedItems: [], scriptIds: [] };
+        var data = { removedItems: removedUISourceCodes, addedItems: [] };
         this.dispatchEventToListeners(WebInspector.ScriptMapping.Events.UISourceCodeListChanged, data);
     }
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to