Diff
Modified: trunk/LayoutTests/ChangeLog (98846 => 98847)
--- trunk/LayoutTests/ChangeLog 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/LayoutTests/ChangeLog 2011-10-31 11:55:59 UTC (rev 98847)
@@ -1,3 +1,14 @@
+2011-10-31 Pavel Feldman <[email protected]>
+
+ Web Inspector: do not map scripts generated with document.write to the document resources.
+ https://bugs.webkit.org/show_bug.cgi?id=71114
+
+ Reviewed by Yury Semikhatsky.
+
+ * inspector/debugger/bind-script-to-resource-expected.txt: Added.
+ * inspector/debugger/bind-script-to-resource.html: Added.
+ * inspector/debugger/linkifier.html:
+
2011-10-31 Andrey Kosyakov <[email protected]>
Unreviewed.
Added: trunk/LayoutTests/inspector/debugger/bind-script-to-resource-expected.txt (0 => 98847)
--- trunk/LayoutTests/inspector/debugger/bind-script-to-resource-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/debugger/bind-script-to-resource-expected.txt 2011-10-31 11:55:59 UTC (rev 98847)
@@ -0,0 +1,19 @@
+Tests that only inline scripts are bound to the resource, while the ones generated with document.write are not. Bug 71099
+
+Debugger was enabled.
+There should be 4 scripts:
+script1: bind-script-to-resource.html
+script2: bind-script-to-resource.html
+script3: debugger-test.js
+script4: inspector-test.js
+
+There should be 3 resources, each resource should have 1 script:
+url1 : debugger-test.js
+ script: debugger-test.js
+url2 : inspector-test.js
+ script: inspector-test.js
+url3 : bind-script-to-resource.html
+ script: bind-script-to-resource.html
+document url:bind-script-to-resource.html
+Debugger was disabled.
+
Property changes on: trunk/LayoutTests/inspector/debugger/bind-script-to-resource-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/debugger/bind-script-to-resource.html (0 => 98847)
--- trunk/LayoutTests/inspector/debugger/bind-script-to-resource.html (rev 0)
+++ trunk/LayoutTests/inspector/debugger/bind-script-to-resource.html 2011-10-31 11:55:59 UTC (rev 98847)
@@ -0,0 +1,66 @@
+<html>
+<head>
+<script src=""
+<script src=""
+
+<script>
+
+document.write("<scrip" + "t>function foo() { }</sc" + "ript>");
+
+var test = function()
+{
+ var scripts = [];
+ InspectorTest.startDebuggerTest(step1);
+
+ function step1()
+ {
+ var model = WebInspector.debuggerPresentationModel;
+
+ var scriptURLs = [];
+ for (var scriptId in model._rawSourceCodeForScriptId) {
+ var script = WebInspector.debuggerModel.scripts[scriptId];
+ scriptURLs.push(WebInspector.displayNameForURL(script.sourceURL));
+ }
+ scriptURLs.sort();
+ InspectorTest.assertEquals(4, scriptURLs.length);
+ InspectorTest.addResult("There should be 4 scripts:");
+ for (var i = 0; i < scriptURLs.length; ++i)
+ InspectorTest.addResult("script" + (i+1) + ": " + scriptURLs[i]);
+
+ var urls = Object.keys(model._rawSourceCodeForURL);
+ urls.sort();
+
+ InspectorTest.addResult("\nThere should be 3 resources, each resource should have 1 script:");
+ InspectorTest.assertEquals(3, urls.length);
+ for (var i = 0; i < urls.length; ++i) {
+ var url = ""
+ var displayName = WebInspector.displayNameForURL(url);
+ InspectorTest.addResult("url" + (i+1) + " : " + displayName);
+ var rawSourceCode = model._rawSourceCodeForURL[url];
+ InspectorTest.assertEquals(1, rawSourceCode._scripts.length);
+ for (var j = 0; j < rawSourceCode._scripts.length; ++j) {
+ var script = rawSourceCode._scripts[j];
+ InspectorTest.addResult(" script: " + WebInspector.displayNameForURL(script.sourceURL));
+ }
+ }
+
+ urls = Object.keys(model._rawSourceCodeForDocumentURL);
+ urls.sort();
+ for (var i = 0; i < urls.length; ++i)
+ InspectorTest.addResult("document url:" + WebInspector.displayNameForURL(urls[i]));
+
+ InspectorTest.completeDebuggerTest();
+ }
+}
+</script>
+</head>
+
+<body _onload_="runTest()">
+
+<p>
+Tests that only inline scripts are bound to the resource, while the ones generated with document.write are not. Bug 71099</a>
+</p>
+
+</body>
+
+</html>
Property changes on: trunk/LayoutTests/inspector/debugger/bind-script-to-resource.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/LayoutTests/inspector/debugger/linkifier-expected.txt (98846 => 98847)
--- trunk/LayoutTests/inspector/debugger/linkifier-expected.txt 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/LayoutTests/inspector/debugger/linkifier-expected.txt 2011-10-31 11:55:59 UTC (rev 98847)
@@ -3,26 +3,10 @@
Two addEventListener calls expected. The first for 'fakeUrl-1' the second for 'fakeUrl-2'.
Two removeEventListener calls expected. The first for 'fakeUrl-1' the second for 'fakeUrl-2'.
Debugger was enabled.
---- linkify fakeURL-1 first time ---
-DummyPresentationModel._rawSourceCodeForScriptWithURL was called with arguments = ['fakeUrl-1']
-DummyRawSourceCode.addEventListener was called for source with URL = '' with arguments = ['source-mapping-updated', function, object]
+listeners added on raw source code: 1
+original location: linkifier.html:21
+pretty printed location: linkifier.html:24
+reverted location: linkifier.html:21
+listeners removed from raw source code: 1
+Debugger was disabled.
---- linkify fakeURL-2 first time ---
-DummyPresentationModel._rawSourceCodeForScriptWithURL was called with arguments = ['fakeUrl-2']
-DummyRawSourceCode.addEventListener was called for source with URL = '' with arguments = ['source-mapping-updated', function, object]
-
---- linkify fakeURL-1 second time ---
-DummyPresentationModel._rawSourceCodeForScriptWithURL was called with arguments = ['fakeUrl-1']
-
---- linkify fakeURL-2 second time ---
-DummyPresentationModel._rawSourceCodeForScriptWithURL was called with arguments = ['fakeUrl-2']
-
---- reset ---
-DummyRawSourceCode.removeEventListener was called for source with id = 'fakeUrl-1' with arguments = ['source-mapping-updated', function, object]
-DummyRawSourceCode.removeEventListener was called for source with id = 'fakeUrl-2' with arguments = ['source-mapping-updated', function, object]
-
---- location update ---
-original location: linkifier.html:93
-pretty printed location: linkifier.html:98
-reverted location: linkifier.html:93
-
Modified: trunk/LayoutTests/inspector/debugger/linkifier.html (98846 => 98847)
--- trunk/LayoutTests/inspector/debugger/linkifier.html 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/LayoutTests/inspector/debugger/linkifier.html 2011-10-31 11:55:59 UTC (rev 98847)
@@ -8,99 +8,54 @@
{
InspectorTest.startDebuggerTest(debuggerTest);
+ var linkifier;
+ var link;
+ var rawSourceCode;
+
function debuggerTest()
{
- if (!WebInspector.debuggerPresentationModel._rawSourceCode[WebInspector.mainResource._documentURL]) {
- InspectorTest.addSniffer(WebInspector.debuggerPresentationModel, "_addScript", debuggerTest);
- return;
- }
+ linkifier = WebInspector.debuggerPresentationModel.createLinkifier();
+ rawSourceCode = WebInspector.debuggerPresentationModel._rawSourceCodeForURL[WebInspector.mainResource._documentURL];
- var fakeURL1 = "fakeUrl-1";
- var fakeURL2 = "fakeUrl-2";
+ var count1 = listenersCount(rawSourceCode);
+ link = linkifier.linkifyLocation(WebInspector.mainResource._documentURL, 20, 0, "dummy-class");
+ var count2 = listenersCount(rawSourceCode);
+ InspectorTest.addResult("listeners added on raw source code: " + (count2 - count1));
- DummyRawSourceCode = function(url)
- {
- this.url = ""
- this.id = url;
- }
+ InspectorTest.addResult("original location: " + link.textContent);
- DummyRawSourceCode.prototype = {
- addEventListener: function(eventName, callback, object)
- {
- InspectorTest.addResult("DummyRawSourceCode.addEventListener was called for source with URL = '' with arguments = ['" + eventName + "', " + (typeof callback) + ", " + (typeof object) + "]");
- },
+ InspectorTest.addSniffer(linkifier, "_updateAnchor", linkUpdated);
+ WebInspector.debuggerPresentationModel.setFormatSource(true);
+ }
- removeEventListener: function(eventName, callback, object)
- {
- InspectorTest.addResult("DummyRawSourceCode.removeEventListener was called for source with id = '" + this.url + "' with arguments = ['" + eventName + "', " + (typeof callback) + ", " + (typeof object) + "]");
- }
- }
+ function linkUpdated()
+ {
+ InspectorTest.addResult("pretty printed location: " + link.textContent);
+ InspectorTest.addSniffer(linkifier, "_updateAnchor", linkReverted);
+ WebInspector.debuggerPresentationModel.setFormatSource(false);
+ }
- DummyPresentationModel = function()
- {
- this._rawSourceCode = [];
- }
+ function linkReverted()
+ {
+ InspectorTest.addResult("reverted location: " + link.textContent);
- DummyPresentationModel.prototype = {
- _rawSourceCodeForScriptWithURL: function(sourceURL)
- {
- InspectorTest.addResult("DummyPresentationModel._rawSourceCodeForScriptWithURL was called with arguments = ['" + sourceURL + "']");
- var rawSourceCode = this._rawSourceCode[sourceURL];
- if (rawSourceCode)
- return rawSourceCode;
- rawSourceCode = new DummyRawSourceCode(sourceURL);
- this._rawSourceCode[sourceURL] = rawSourceCode;
- return rawSourceCode;
- }
- }
-
- var dummyPresentationModel = new DummyPresentationModel();
-
- var linkifier = new WebInspector.DebuggerPresentationModel.Linkifier(dummyPresentationModel);
-
- InspectorTest.addResult("--- linkify fakeURL-1 first time ---");
- linkifier.linkifyLocation(fakeURL1, 42, 26, "fake-class-name");
- InspectorTest.addResult("");
-
- InspectorTest.addResult("--- linkify fakeURL-2 first time ---");
- linkifier.linkifyLocation(fakeURL2, 42, 26, "fake-class-name");
- InspectorTest.addResult("");
-
- InspectorTest.addResult("--- linkify fakeURL-1 second time ---");
- linkifier.linkifyLocation(fakeURL1, 97, 23, "fake-class-name");
- InspectorTest.addResult("");
-
- InspectorTest.addResult("--- linkify fakeURL-2 second time ---");
- linkifier.linkifyLocation(fakeURL2, 4, 2, "fake-class-name");
- InspectorTest.addResult("");
-
- InspectorTest.addResult("--- reset ---");
+ var count1 = listenersCount(rawSourceCode);
linkifier.reset();
- InspectorTest.addResult("");
+ var count2 = listenersCount(rawSourceCode);
+ InspectorTest.addResult("listeners removed from raw source code: " + (count1 - count2));
- InspectorTest.addResult("--- location update ---");
+ InspectorTest.completeDebuggerTest();
+ }
- function dummyFunctionToBePrettyPrinted() { InspectorTest.addResult(""); console.error(""); }
-
- linkifier = WebInspector.debuggerPresentationModel.createLinkifier();
- var link = linkifier.linkifyLocation(WebInspector.mainResource._documentURL, 92, 0, "dummy-class");
- InspectorTest.addResult("original location: " + link.textContent);
-
- InspectorTest.addSniffer(linkifier, "_updateAnchor", linkUpdated);
- WebInspector.debuggerPresentationModel.setFormatSource(true);
-
- function linkUpdated()
- {
- InspectorTest.addResult("pretty printed location: " + link.textContent);
- InspectorTest.addSniffer(linkifier, "_updateAnchor", linkReverted);
- WebInspector.debuggerPresentationModel.setFormatSource(false);
+ function listenersCount(object)
+ {
+ var listeners = object._listeners;
+ var count = 0;
+ for (var eventTypes in listeners) {
+ var listenersArray = listeners[eventTypes];
+ count += listenersArray.length;
}
-
- function linkReverted()
- {
- InspectorTest.addResult("reverted location: " + link.textContent);
- InspectorTest.completeTest();
- }
+ return count;
}
}
Modified: trunk/Source/WebCore/ChangeLog (98846 => 98847)
--- trunk/Source/WebCore/ChangeLog 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/Source/WebCore/ChangeLog 2011-10-31 11:55:59 UTC (rev 98847)
@@ -1,3 +1,26 @@
+2011-10-31 Pavel Feldman <[email protected]>
+
+ Web Inspector: do not map scripts generated with document.write to the document resources.
+ https://bugs.webkit.org/show_bug.cgi?id=71114
+
+ Reviewed by Yury Semikhatsky.
+
+ Test: inspector/debugger/bind-script-to-resource.html
+
+ * inspector/front-end/DebuggerPresentationModel.js:
+ (WebInspector.DebuggerPresentationModel):
+ (WebInspector.DebuggerPresentationModel.prototype._addScript):
+ (WebInspector.DebuggerPresentationModel.prototype._bindScriptToRawSourceCode):
+ (WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScriptWithURL):
+ (WebInspector.DebuggerPresentationModel.prototype._rawSourceCodeForScript):
+ (WebInspector.DebuggerPresentationModel.prototype._scriptForRawSourceCode):
+ (WebInspector.DebuggerPresentationModel.prototype._debuggerReset):
+ * inspector/front-end/RawSourceCode.js:
+ (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent.didFormatContent):
+ (WebInspector.RawSourceCode.prototype._createSourceMapping.didRequestContent):
+ (WebInspector.RawSourceCode.prototype._createSourceMapping):
+ * inspector/front-end/Script.js:
+
2011-10-31 Antti Koivisto <[email protected]>
https://bugs.webkit.org/show_bug.cgi?id=71012
Modified: trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js (98846 => 98847)
--- trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/Source/WebCore/inspector/front-end/DebuggerPresentationModel.js 2011-10-31 11:55:59 UTC (rev 98847)
@@ -36,7 +36,9 @@
{
// FIXME: apply formatter from outside as a generic mapping.
this._formatter = new WebInspector.ScriptFormatter();
- this._rawSourceCode = {};
+ this._rawSourceCodeForScriptId = {};
+ this._rawSourceCodeForURL = {};
+ this._rawSourceCodeForDocumentURL = {};
this._presentationCallFrames = [];
this._breakpointManager = new WebInspector.BreakpointManager(WebInspector.settings.breakpoints, this._breakpointAdded.bind(this), this._breakpointRemoved.bind(this), WebInspector.debuggerModel);
@@ -109,24 +111,43 @@
*/
_addScript: function(script)
{
- var rawSourceCodeId = this._createRawSourceCodeId(script);
- var rawSourceCode = this._rawSourceCode[rawSourceCodeId];
- if (rawSourceCode) {
- rawSourceCode.addScript(script);
- return;
+ var resource;
+ var isInlineScript = false;
+ if (script.isInlineScript()) {
+ resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
+ if (resource && resource.type === WebInspector.Resource.Type.Document) {
+ isInlineScript = true;
+ var rawSourceCode = this._rawSourceCodeForDocumentURL[script.sourceURL];
+ if (rawSourceCode) {
+ rawSourceCode.addScript(script);
+ this._bindScriptToRawSourceCode(script, rawSourceCode);
+ return;
+ }
+ }
}
- var resource;
- if (script.sourceURL)
- resource = WebInspector.networkManager.inflightResourceForURL(script.sourceURL) || WebInspector.resourceForURL(script.sourceURL);
- rawSourceCode = new WebInspector.RawSourceCode(rawSourceCodeId, script, resource, this._formatter, this._formatSource);
- this._rawSourceCode[rawSourceCodeId] = rawSourceCode;
+ rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, this._formatter, this._formatSource);
+ this._bindScriptToRawSourceCode(script, rawSourceCode);
+
+ if (isInlineScript)
+ this._rawSourceCodeForDocumentURL[script.sourceURL] = rawSourceCode;
+
if (rawSourceCode.sourceMapping)
this._updateSourceMapping(rawSourceCode, null);
rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._sourceMappingUpdated, this);
},
/**
+ * @param {WebInspector.Script} script
+ * @param {WebInspector.RawSourceCode} rawSourceCode
+ */
+ _bindScriptToRawSourceCode: function(script, rawSourceCode)
+ {
+ this._rawSourceCodeForScriptId[script.scriptId] = rawSourceCode;
+ this._rawSourceCodeForURL[script.sourceURL] = rawSourceCode;
+ },
+
+ /**
* @param {WebInspector.Event} event
*/
_sourceMappingUpdated: function(event)
@@ -142,8 +163,8 @@
uiSourceCodes: function()
{
var result = [];
- for (var id in this._rawSourceCode) {
- var uiSourceCodeList = this._rawSourceCode[id].sourceMapping.uiSourceCodeList();
+ for (var id in this._rawSourceCodeForScriptId) {
+ var uiSourceCodeList = this._rawSourceCodeForScriptId[id].sourceMapping.uiSourceCodeList();
for (var i = 0; i < uiSourceCodeList.length; ++i)
result.push(uiSourceCodeList[i]);
}
@@ -297,8 +318,8 @@
this._formatSource = formatSource;
this._breakpointManager.reset();
- for (var id in this._rawSourceCode)
- this._rawSourceCode[id].setFormatted(this._formatSource);
+ for (var id in this._rawSourceCodeForScriptId)
+ this._rawSourceCodeForScriptId[id].setFormatted(this._formatSource);
},
/**
@@ -338,8 +359,8 @@
_consoleCleared: function()
{
- for (var id in this._rawSourceCode)
- this._rawSourceCode[id].messages = [];
+ for (var id in this._rawSourceCodeForScriptId)
+ this._rawSourceCodeForScriptId[id].messages = [];
this.dispatchEventToListeners(WebInspector.DebuggerPresentationModel.Events.ConsoleMessagesCleared);
},
@@ -580,7 +601,7 @@
*/
_rawSourceCodeForScriptWithURL: function(sourceURL)
{
- return this._rawSourceCode[sourceURL];
+ return this._rawSourceCodeForURL[sourceURL];
},
/**
@@ -588,7 +609,7 @@
*/
_rawSourceCodeForScript: function(script)
{
- return this._rawSourceCode[this._createRawSourceCodeId(script)];
+ return this._rawSourceCodeForScriptId[script.scriptId];
},
/**
@@ -603,23 +624,15 @@
*/
function filter(script)
{
- return this._createRawSourceCodeId(script) === rawSourceCode.id;
+ return script.scriptId === rawSourceCode.id;
}
return WebInspector.debuggerModel.queryScripts(filter.bind(this))[0];
},
- /**
- * @param {WebInspector.Script} script
- */
- _createRawSourceCodeId: function(script)
- {
- return script.sourceURL || script.scriptId;
- },
-
_debuggerReset: function()
{
- for (var id in this._rawSourceCode) {
- var rawSourceCode = this._rawSourceCode[id];
+ for (var id in this._rawSourceCodeForScriptId) {
+ var rawSourceCode = this._rawSourceCodeForScriptId[id];
if (rawSourceCode.sourceMapping) {
var uiSourceCodeList = rawSourceCode.sourceMapping.uiSourceCodeList();
for (var i = 0; i < uiSourceCodeList.length; ++i)
@@ -627,7 +640,9 @@
}
rawSourceCode.removeAllListeners();
}
- this._rawSourceCode = {};
+ this._rawSourceCodeForScriptId = {};
+ this._rawSourceCodeForURL = {};
+ this._rawSourceCodeForDocumentURL = {};
this._presentationCallFrames = [];
this._selectedCallFrame = null;
this._breakpointManager.debuggerReset();
@@ -960,8 +975,8 @@
reset: function()
{
for (var id in this._anchorsForRawSourceCode) {
- if (this._model._rawSourceCode[id]) // In case of navigation the list of rawSourceCodes is empty.
- this._model._rawSourceCode[id].removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._updateSourceAnchors, this);
+ if (this._model._rawSourceCodeForScriptId[id]) // In case of navigation the list of rawSourceCodes is empty.
+ this._model._rawSourceCodeForScriptId[id].removeEventListener(WebInspector.RawSourceCode.Events.SourceMappingUpdated, this._updateSourceAnchors, this);
}
this._anchorsForRawSourceCode = {};
},
Modified: trunk/Source/WebCore/inspector/front-end/RawSourceCode.js (98846 => 98847)
--- trunk/Source/WebCore/inspector/front-end/RawSourceCode.js 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/Source/WebCore/inspector/front-end/RawSourceCode.js 2011-10-31 11:55:59 UTC (rev 98847)
@@ -211,7 +211,7 @@
var originalContentProvider = this._createContentProvider();
if (!this._formatted) {
- var uiSourceCode = new WebInspector.UISourceCode(this.id, this.url, this.isContentScript, this, originalContentProvider);
+ var uiSourceCode = new WebInspector.UISourceCode(this.url, this.url, this.isContentScript, this, originalContentProvider);
var sourceMapping = new WebInspector.RawSourceCode.PlainSourceMapping(this, uiSourceCode);
callback(sourceMapping);
return;
@@ -232,7 +232,7 @@
function didFormatContent(formattedContent, mapping)
{
var contentProvider = new WebInspector.StaticContentProvider(mimeType, formattedContent)
- var uiSourceCode = new WebInspector.UISourceCode("deobfuscated:" + this.id, this.url, this.isContentScript, this, contentProvider);
+ var uiSourceCode = new WebInspector.UISourceCode("deobfuscated:" + this.url, this.url, this.isContentScript, this, contentProvider);
var sourceMapping = new WebInspector.RawSourceCode.FormattedSourceMapping(this, uiSourceCode, mapping);
callback(sourceMapping);
}
Modified: trunk/Source/WebCore/inspector/front-end/Script.js (98846 => 98847)
--- trunk/Source/WebCore/inspector/front-end/Script.js 2011-10-31 11:55:52 UTC (rev 98846)
+++ trunk/Source/WebCore/inspector/front-end/Script.js 2011-10-31 11:55:59 UTC (rev 98847)
@@ -126,5 +126,10 @@
DebuggerAgent.setScriptSource(this.scriptId, newSource, undefined, didEditScriptSource.bind(this));
} else
callback("Script failed to parse");
+ },
+
+ isInlineScript: function()
+ {
+ return this.sourceURL && this.lineOffset !== 0 && this.columnOffset !== 0;
}
}