Title: [139405] trunk
Revision
139405
Author
[email protected]
Date
2013-01-10 22:17:07 -0800 (Thu, 10 Jan 2013)

Log Message

Web Inspector: Pass the script url to the script-preprocessor script
https://bugs.webkit.org/show_bug.cgi?id=104384

Patch by John J. Barton <[email protected]> on 2013-01-10
Reviewed by Pavel Feldman.

Source/WebCore:

Add url argument to the script-preprocessor script in PageAgent.reload()

Test: inspector/debugger/debugger-script-preprocessor.html

* bindings/v8/DebuggerScript.js:
* bindings/v8/ScriptDebugServer.cpp:
(WebCore::ScriptDebugServer::ScriptPreprocessor::ScriptPreprocessor):
(WebCore::ScriptDebugServer::ScriptPreprocessor::preprocessSourceCode):
(WebCore::ScriptDebugServer::handleV8DebugEvent):
* bindings/v8/custom/V8InjectedScriptManager.cpp:
(WebCore::InjectedScriptManager::createInjectedScript):

LayoutTests:

Tests for Bug 80922 by Pavel Feldman <[email protected]> that did not land somehow,
with additional test for Bug 104384

* inspector/debugger/debugger-script-preprocessor-expected.txt: Added.
* inspector/debugger/debugger-script-preprocessor.html: Added.
* platform/chromium/inspector/debugger/debugger-script-preprocessor-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (139404 => 139405)


--- trunk/LayoutTests/ChangeLog	2013-01-11 05:49:24 UTC (rev 139404)
+++ trunk/LayoutTests/ChangeLog	2013-01-11 06:17:07 UTC (rev 139405)
@@ -1,3 +1,17 @@
+2013-01-10  John J. Barton  <[email protected]>
+
+        Web Inspector: Pass the script url to the script-preprocessor script
+        https://bugs.webkit.org/show_bug.cgi?id=104384
+
+        Reviewed by Pavel Feldman.
+
+        Tests for Bug 80922 by Pavel Feldman <[email protected]> that did not land somehow, 
+        with additional test for Bug 104384 
+
+        * inspector/debugger/debugger-script-preprocessor-expected.txt: Added.
+        * inspector/debugger/debugger-script-preprocessor.html: Added.
+        * platform/chromium/inspector/debugger/debugger-script-preprocessor-expected.txt: Added.
+
 2013-01-10  Eugene Klyuchnikov  <[email protected]>
 
         Web Inspector: DataGrid refactoring: make cell editing more generic.

Added: trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor-expected.txt (0 => 139405)


--- trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor-expected.txt	2013-01-11 06:17:07 UTC (rev 139405)
@@ -0,0 +1,12 @@
+Tests script preprocessor (ability to preprocess all scripts upon reload).
+
+Debugger was enabled.
+Page reloaded.
+inspector-test.js
+debugger-test.js
+debugger-script-preprocessor.html
+
+
+Page reloaded.
+Debugger was disabled.
+

Added: trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor.html (0 => 139405)


--- trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor.html	                        (rev 0)
+++ trunk/LayoutTests/inspector/debugger/debugger-script-preprocessor.html	2013-01-11 06:17:07 UTC (rev 139405)
@@ -0,0 +1,63 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<script>
+
+function load()
+{
+    eval("function dynamic" + "Script1() {}"); 
+    eval("function dynamic" + "Script2() {}"); 
+    runTest();
+}
+
+function test()
+{
+    function preprocessor(script, name)
+    {
+        if (script.indexOf("dynamic" + "Script1") !== -1)
+            return script + "//@ sourceURL=dynamicScript1";
+        if (script.indexOf("dynamic" + "Script2") !== -1) {
+            try {
+                var w = eval("window");
+                return script + "//@ sourceURL=FAIL_window_should_not_be_there";
+            } catch (e) {
+                return script + "//@ sourceURL=dynamicScript2";
+            }
+        }
+        // Verify that the |name| argument is correct. Note: if name is not passed in
+        // the results will be a script with a sourceURL equal to the original file name.
+        return script + "//@ sourceURL=" + name + ".js"; 
+    }
+
+    InspectorTest.startDebuggerTest(step1);
+
+    function step1()
+    {         
+        InspectorTest.reloadPage(step2, undefined, "(" + preprocessor + ")");
+    }
+
+    function step2()
+    {
+        function accept(script)
+        {
+            return true;
+        }
+        var scripts = InspectorTest.queryScripts(accept);
+        for (var i = 0; i < scripts.length; ++i)
+            InspectorTest.addResult(WebInspector.displayNameForURL(scripts[i].sourceURL));
+
+        InspectorTest.reloadPage(InspectorTest.completeDebuggerTest.bind(InspectorTest));
+    }
+}
+
+</script>
+</head>
+
+<body _onload_="load()">
+<p>
+Tests script preprocessor (ability to preprocess all scripts upon reload).
+</p>
+
+</body>
+</html>

Added: trunk/LayoutTests/platform/chromium/inspector/debugger/debugger-script-preprocessor-expected.txt (0 => 139405)


--- trunk/LayoutTests/platform/chromium/inspector/debugger/debugger-script-preprocessor-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/chromium/inspector/debugger/debugger-script-preprocessor-expected.txt	2013-01-11 06:17:07 UTC (rev 139405)
@@ -0,0 +1,13 @@
+Tests script preprocessor (ability to preprocess all scripts upon reload).
+
+Debugger was enabled.
+Page reloaded.
+inspector-test.js.js
+debugger-test.js.js
+debugger-script-preprocessor.html
+debugger-script-preprocessor.html
+dynamicScript1
+dynamicScript2
+Page reloaded.
+Debugger was disabled.
+

Modified: trunk/Source/WebCore/ChangeLog (139404 => 139405)


--- trunk/Source/WebCore/ChangeLog	2013-01-11 05:49:24 UTC (rev 139404)
+++ trunk/Source/WebCore/ChangeLog	2013-01-11 06:17:07 UTC (rev 139405)
@@ -1,3 +1,22 @@
+2013-01-10  John J. Barton  <[email protected]>
+
+        Web Inspector: Pass the script url to the script-preprocessor script
+        https://bugs.webkit.org/show_bug.cgi?id=104384
+
+        Reviewed by Pavel Feldman.
+
+        Add url argument to the script-preprocessor script in PageAgent.reload()
+
+        Test: inspector/debugger/debugger-script-preprocessor.html
+
+        * bindings/v8/DebuggerScript.js:
+        * bindings/v8/ScriptDebugServer.cpp:
+        (WebCore::ScriptDebugServer::ScriptPreprocessor::ScriptPreprocessor):
+        (WebCore::ScriptDebugServer::ScriptPreprocessor::preprocessSourceCode):
+        (WebCore::ScriptDebugServer::handleV8DebugEvent):
+        * bindings/v8/custom/V8InjectedScriptManager.cpp:
+        (WebCore::InjectedScriptManager::createInjectedScript):
+
 2013-01-10  Eugene Klyuchnikov  <[email protected]>
 
         Web Inspector: DataGrid refactoring: make cell editing more generic.

Modified: trunk/Source/WebCore/bindings/v8/DebuggerScript.js (139404 => 139405)


--- trunk/Source/WebCore/bindings/v8/DebuggerScript.js	2013-01-11 05:49:24 UTC (rev 139404)
+++ trunk/Source/WebCore/bindings/v8/DebuggerScript.js	2013-01-11 06:17:07 UTC (rev 139405)
@@ -249,6 +249,11 @@
     eventData.script().setSource(source);
 }
 
+DebuggerScript.getScriptName = function(eventData)
+{
+    return eventData.script().script_.nameOrSourceURL();
+}
+
 DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror, callerFrame)
 {
     // Get function name.

Modified: trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp (139404 => 139405)


--- trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp	2013-01-11 05:49:24 UTC (rev 139404)
+++ trunk/Source/WebCore/bindings/v8/ScriptDebugServer.cpp	2013-01-11 06:17:07 UTC (rev 139405)
@@ -100,6 +100,7 @@
 
         String wrappedScript = makeString("(", preprocessorScript, ")");
         v8::Handle<v8::String> preprocessor = v8::String::New(wrappedScript.utf8().data(), wrappedScript.utf8().length());
+
         v8::Handle<v8::Script> script = v8::Script::Compile(preprocessor);
 
         if (tryCatch.HasCaught())
@@ -113,7 +114,7 @@
         m_preprocessorFunction.set(v8::Handle<v8::Function>::Cast(preprocessorFunction));
     }
 
-    String preprocessSourceCode(const String& sourceCode)
+    String preprocessSourceCode(const String& sourceCode, const String& sourceName)
     {
         v8::HandleScope scope;
 
@@ -124,11 +125,14 @@
         v8::Context::Scope contextScope(context);
 
         v8::Handle<v8::String> sourceCodeString = v8::String::New(sourceCode.utf8().data(), sourceCode.utf8().length());
-        v8::Handle<v8::Value> argv[] = { sourceCodeString };
 
+        v8::Handle<v8::String> sourceNameString = v8::String::New(sourceName.utf8().data(), sourceName.utf8().length());
+        v8::Handle<v8::Value> argv[] = { sourceCodeString, sourceNameString };
+
         v8::TryCatch tryCatch;
         RecursionScopeSuppression suppressionScope;
-        v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context->Global(), 1, argv);
+        v8::Handle<v8::Value> resultValue = m_preprocessorFunction->Call(context->Global(), 2, argv);
+
         if (tryCatch.HasCaught())
             return sourceCode;
 
@@ -455,6 +459,7 @@
     if (listener) {
         v8::HandleScope scope;
         if (event == v8::BeforeCompile) {
+
             if (!m_scriptPreprocessor)
                 return;
 
@@ -464,8 +469,13 @@
             v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
             v8::Handle<v8::Value> script = getScriptSourceFunction->Call(m_debuggerScript.get(), 1, argv);
 
+            v8::Handle<v8::Function> getScriptNameFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getScriptName")));
+            v8::Handle<v8::Value> argv1[] = { eventDetails.GetEventData() };
+            v8::Handle<v8::Value> scriptName = getScriptNameFunction->Call(m_debuggerScript.get(), 1, argv1);
+
             v8::Handle<v8::Function> setScriptSourceFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("setScriptSource")));
-            String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script));
+            String patchedScript = preprocessor->preprocessSourceCode(toWebCoreStringWithUndefinedOrNullCheck(script), toWebCoreStringWithUndefinedOrNullCheck(scriptName));
+
             v8::Handle<v8::Value> argv2[] = { eventDetails.GetEventData(), v8String(patchedScript) };
             setScriptSourceFunction->Call(m_debuggerScript.get(), 2, argv2);
             m_scriptPreprocessor = preprocessor.release();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to