Title: [218603] trunk
Revision
218603
Author
drou...@apple.com
Date
2017-06-20 11:35:31 -0700 (Tue, 20 Jun 2017)

Log Message

Web Inspector: add console messages for WebGL shader compile and program link errors/warnings
https://bugs.webkit.org/show_bug.cgi?id=143236
<rdar://problem/20352149>

Reviewed by Dean Jackson.

Source/WebCore:

Test: fast/canvas/webgl/shader-compile-logging.html

* html/canvas/WebGLRenderingContextBase.h:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::checkFramebufferStatus):
(WebCore::WebGLRenderingContextBase::compileShader):
(WebCore::WebGLRenderingContextBase::recycleContext):
(WebCore::WebGLRenderingContextBase::checkTextureCompleteness):
(WebCore::WebGLRenderingContextBase::printToConsole):
(WebCore::WebGLRenderingContextBase::maybeRestoreContext):
(WebCore::WebGLRenderingContextBase::synthesizeGLError):
(WebCore::WebGLRenderingContextBase::printGLErrorToConsole): Deleted.
(WebCore::WebGLRenderingContextBase::printWarningToConsole): Deleted.
(WebCore::WebGLRenderingContextBase::printGLWarningToConsole): Deleted.
Unify console logging helper functions to all follow the same path. Additionally, errors
now generate stack traces. Shader compilation errors are now logged as well.

* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::addConsoleMessage):
* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):
* page/PageConsoleClient.h:
* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::addMessage):
* workers/WorkerGlobalScope.h:
Add new path for logging to the console that accepts a ConsoleMessage.

LayoutTests:

* fast/canvas/webgl/fragment-shader-assertion.html:
* fast/canvas/webgl/shader-compile-logging-expected.txt: Added.
* fast/canvas/webgl/shader-compile-logging.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (218602 => 218603)


--- trunk/LayoutTests/ChangeLog	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/LayoutTests/ChangeLog	2017-06-20 18:35:31 UTC (rev 218603)
@@ -1,3 +1,15 @@
+2017-06-20  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: add console messages for WebGL shader compile and program link errors/warnings
+        https://bugs.webkit.org/show_bug.cgi?id=143236
+        <rdar://problem/20352149>
+
+        Reviewed by Dean Jackson.
+
+        * fast/canvas/webgl/fragment-shader-assertion.html:
+        * fast/canvas/webgl/shader-compile-logging-expected.txt: Added.
+        * fast/canvas/webgl/shader-compile-logging.html: Added.
+
 2017-06-19  Antoine Quint  <grao...@apple.com>
 
         Media document experience with long-loading files is poor

Modified: trunk/LayoutTests/fast/canvas/webgl/fragment-shader-assertion.html (218602 => 218603)


--- trunk/LayoutTests/fast/canvas/webgl/fragment-shader-assertion.html	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/LayoutTests/fast/canvas/webgl/fragment-shader-assertion.html	2017-06-20 18:35:31 UTC (rev 218603)
@@ -4,6 +4,9 @@
 if (window.testRunner)
 	testRunner.dumpAsText();
 
+if (window.internals)
+    window.internals.settings.setWebGLErrorsToConsoleEnabled(false);
+
 function runTest() {
     var canvas = document.getElementById("myCanvas");
     var gl = canvas.getContext("webgl");

Added: trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging-expected.txt (0 => 218603)


--- trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging-expected.txt	2017-06-20 18:35:31 UTC (rev 218603)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:2: 'attribute' :  supported in vertex shaders only 
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:2: '' : No precision specified for (float)
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:4: 'gl_Position' : undeclared identifier
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:4: '=' : dimension mismatch
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:4: 'assign' : cannot convert from 'attribute 4-component vector of float' to 'float'
+CONSOLE MESSAGE: line 19: WebGL: ERROR: 0:7: 'FRAGMENT_SHADER' : syntax error
+CONSOLE MESSAGE: line 29: WebGL: ERROR: 0:3: 'gl_FragColor' : undeclared identifier
+CONSOLE MESSAGE: line 29: WebGL: ERROR: 0:3: '=' : dimension mismatch
+CONSOLE MESSAGE: line 29: WebGL: ERROR: 0:3: 'assign' : cannot convert from 'const 4-component vector of float' to 'float'
+CONSOLE MESSAGE: line 29: WebGL: ERROR: 0:6: 'VERTEX_SHADER' : syntax error
+Tests that WebGL shader compile errors/warnings are logged to the console.

Added: trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging.html (0 => 218603)


--- trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/webgl/shader-compile-logging.html	2017-06-20 18:35:31 UTC (rev 218603)
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<body>
+<p>Tests that WebGL shader compile errors/warnings are logged to the console.</p>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText()
+
+let gl = document.createElement("canvas").getContext("webgl");
+
+let fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
+gl.shaderSource(fragmentShader, `
+attribute vec4 position;
+void main() {
+    gl_Position = position;
+}
+
+FRAGMENT_SHADER
+`);
+gl.compileShader(fragmentShader);
+
+let vertexShader = gl.createShader(gl.VERTEX_SHADER);
+gl.shaderSource(vertexShader, `
+void main() {
+    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+}
+
+VERTEX_SHADER
+`);
+gl.compileShader(vertexShader);
+</script>
+</body>
+

Modified: trunk/Source/WebCore/ChangeLog (218602 => 218603)


--- trunk/Source/WebCore/ChangeLog	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/ChangeLog	2017-06-20 18:35:31 UTC (rev 218603)
@@ -1,3 +1,39 @@
+2017-06-20  Devin Rousso  <drou...@apple.com>
+
+        Web Inspector: add console messages for WebGL shader compile and program link errors/warnings
+        https://bugs.webkit.org/show_bug.cgi?id=143236
+        <rdar://problem/20352149>
+
+        Reviewed by Dean Jackson.
+
+        Test: fast/canvas/webgl/shader-compile-logging.html
+
+        * html/canvas/WebGLRenderingContextBase.h:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::checkFramebufferStatus):
+        (WebCore::WebGLRenderingContextBase::compileShader):
+        (WebCore::WebGLRenderingContextBase::recycleContext):
+        (WebCore::WebGLRenderingContextBase::checkTextureCompleteness):
+        (WebCore::WebGLRenderingContextBase::printToConsole):
+        (WebCore::WebGLRenderingContextBase::maybeRestoreContext):
+        (WebCore::WebGLRenderingContextBase::synthesizeGLError):
+        (WebCore::WebGLRenderingContextBase::printGLErrorToConsole): Deleted.
+        (WebCore::WebGLRenderingContextBase::printWarningToConsole): Deleted.
+        (WebCore::WebGLRenderingContextBase::printGLWarningToConsole): Deleted.
+        Unify console logging helper functions to all follow the same path. Additionally, errors
+        now generate stack traces. Shader compilation errors are now logged as well.
+
+        * dom/Document.h:
+        * dom/Document.cpp:
+        (WebCore::Document::addConsoleMessage):
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::AddConsoleMessageTask::AddConsoleMessageTask):
+        * page/PageConsoleClient.h:
+        * page/PageConsoleClient.cpp:
+        (WebCore::PageConsoleClient::addMessage):
+        * workers/WorkerGlobalScope.h:
+        Add new path for logging to the console that accepts a ConsoleMessage.
+
 2017-06-20  Saam Barati  <sbar...@apple.com>
 
         Unreviewed. Try to fix the build after r218594.

Modified: trunk/Source/WebCore/dom/Document.cpp (218602 => 218603)


--- trunk/Source/WebCore/dom/Document.cpp	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/dom/Document.cpp	2017-06-20 18:35:31 UTC (rev 218603)
@@ -197,6 +197,7 @@
 #include "XPathNSResolver.h"
 #include "XPathResult.h"
 #include <ctime>
+#include <inspector/ConsoleMessage.h>
 #include <inspector/ScriptCallStack.h>
 #include <wtf/CurrentTime.h>
 #include <wtf/NeverDestroyed.h>
@@ -5545,6 +5546,17 @@
     m_haveExplicitlyDisabledDNSPrefetch = true;
 }
 
+void Document::addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&& consoleMessage)
+{
+    if (!isContextThread()) {
+        postTask(AddConsoleMessageTask(WTFMove(consoleMessage)));
+        return;
+    }
+
+    if (Page* page = this->page())
+        page->console().addMessage(WTFMove(consoleMessage));
+}
+
 void Document::addConsoleMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier)
 {
     if (!isContextThread()) {

Modified: trunk/Source/WebCore/dom/Document.h (218602 => 218603)


--- trunk/Source/WebCore/dom/Document.h	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/dom/Document.h	2017-06-20 18:35:31 UTC (rev 218603)
@@ -1259,6 +1259,10 @@
     void addDisabledFieldsetElement() { m_disabledFieldsetElementsCount++; }
     void removeDisabledFieldsetElement() { ASSERT(m_disabledFieldsetElementsCount); m_disabledFieldsetElementsCount--; }
 
+    WEBCORE_EXPORT void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&) final;
+
+    // The following addConsoleMessage function is deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     WEBCORE_EXPORT void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) final;
 
     SecurityOrigin& securityOrigin() const { return *SecurityContext::securityOrigin(); }
@@ -1406,6 +1410,8 @@
     void refScriptExecutionContext() final { ref(); }
     void derefScriptExecutionContext() final { deref(); }
 
+    // The following addMessage function is deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0) final;
 
     Seconds minimumDOMTimerInterval() const final;

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (218602 => 218603)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2017-06-20 18:35:31 UTC (rev 218603)
@@ -45,6 +45,7 @@
 }
 
 namespace Inspector {
+class ConsoleMessage;
 class ScriptCallStack;
 }
 
@@ -97,6 +98,10 @@
     void reportException(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, RefPtr<Inspector::ScriptCallStack>&&, CachedScript* = nullptr);
     void reportUnhandledPromiseRejection(JSC::ExecState&, JSC::JSPromise&, RefPtr<Inspector::ScriptCallStack>&&);
 
+    virtual void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&) = 0;
+
+    // The following addConsoleMessage functions are deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     void addConsoleMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0);
     virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) = 0;
 
@@ -223,6 +228,13 @@
 protected:
     class AddConsoleMessageTask : public Task {
     public:
+        AddConsoleMessageTask(std::unique_ptr<Inspector::ConsoleMessage>&& consoleMessage)
+            : Task([&consoleMessage](ScriptExecutionContext& context) {
+                context.addConsoleMessage(WTFMove(consoleMessage));
+            })
+        {
+        }
+
         AddConsoleMessageTask(MessageSource source, MessageLevel level, const String& message)
             : Task([source, level, message = message.isolatedCopy()](ScriptExecutionContext& context) {
                 context.addConsoleMessage(source, level, message);
@@ -236,6 +248,8 @@
     bool hasPendingActivity() const;
 
 private:
+    // The following addMessage function is deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     virtual void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0) = 0;
     virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) = 0;
     bool dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception*, CachedScript*);

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (218602 => 218603)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2017-06-20 18:35:31 UTC (rev 218603)
@@ -52,7 +52,9 @@
 #include "HTMLVideoElement.h"
 #include "ImageBuffer.h"
 #include "ImageData.h"
+#include "InspectorInstrumentation.h"
 #include "IntSize.h"
+#include "JSMainThreadExecState.h"
 #include "Logging.h"
 #include "MainFrame.h"
 #include "NotImplemented.h"
@@ -89,7 +91,9 @@
 #include "WebGLShaderPrecisionFormat.h"
 #include "WebGLTexture.h"
 #include "WebGLUniformLocation.h"
-
+#include <inspector/ConsoleMessage.h>
+#include <inspector/ScriptCallStack.h>
+#include <inspector/ScriptCallStackFactory.h>
 #include <runtime/JSCInlines.h>
 #include <runtime/TypedArrayInlines.h>
 #include <runtime/Uint32Array.h>
@@ -344,7 +348,7 @@
     void onErrorMessage(const String& message, GC3Dint) override
     {
         if (m_context->m_synthesizedErrorsToConsole)
-            m_context->printGLErrorToConsole(message);
+            m_context->printToConsole(MessageLevel::Error, message);
     }
     virtual ~WebGLRenderingContextErrorMessageCallback() { }
 private:
@@ -1242,7 +1246,8 @@
     const char* reason = "framebuffer incomplete";
     GC3Denum result = m_framebufferBinding->checkStatus(&reason);
     if (result != GraphicsContext3D::FRAMEBUFFER_COMPLETE) {
-        printGLWarningToConsole("checkFramebufferStatus", reason);
+        String str = "WebGL: checkFramebufferStatus:" + String(reason);
+        printToConsole(MessageLevel::Warning, str);
         return result;
     }
     result = m_context->checkFramebufferStatus(target);
@@ -1303,6 +1308,15 @@
     GC3Dint value;
     m_context->getShaderiv(objectOrZero(shader), GraphicsContext3D::COMPILE_STATUS, &value);
     shader->setValid(value);
+
+    if (m_synthesizedErrorsToConsole && !value) {
+        Ref<Inspector::ScriptCallStack> stackTrace = Inspector::createScriptCallStack(JSMainThreadExecState::currentState(), Inspector::ScriptCallStack::maxCallStackSizeToCapture);
+
+        Vector<String> errors;
+        getShaderInfoLog(shader).split("\n", errors);
+        for (String& error : errors)
+            canvas().document().addConsoleMessage(std::make_unique<Inspector::ConsoleMessage>(MessageSource::Rendering, MessageType::Log, MessageLevel::Error, "WebGL: " + error, stackTrace.copyRef()));
+    }
 }
 
 void WebGLRenderingContextBase::compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, ArrayBufferView& data)
@@ -4572,7 +4586,7 @@
 
 void WebGLRenderingContextBase::recycleContext()
 {
-    printWarningToConsole("There are too many active WebGL contexts on this page, the oldest context will be lost.");
+    printToConsole(MessageLevel::Error, "There are too many active WebGL contexts on this page, the oldest context will be lost.");
     // Using SyntheticLostContext means the developer won't be able to force the restoration
     // of the context by calling preventDefault() in a "webglcontextlost" event handler.
     forceLostContext(SyntheticLostContext);
@@ -4829,7 +4843,7 @@
             String msg(String("texture bound to texture unit ") + String::number(badTexture)
                 + " is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete',"
                 + " or it is a float/half-float type with linear filtering and without the relevant float/half-float linear extension enabled.");
-            printGLWarningToConsole(functionName, msg.utf8().data());
+            printToConsole(MessageLevel::Error, "WebGL: " + String(functionName) + ": " + msg);
             tex2D = m_blackTexture2D.get();
             texCubeMap = m_blackTextureCubeMap.get();
         } else {
@@ -5200,23 +5214,27 @@
     }
 }
 
-void WebGLRenderingContextBase::printGLErrorToConsole(const String& message)
+void WebGLRenderingContextBase::printToConsole(MessageLevel level, const String& message)
 {
-    if (!m_numGLErrorsToConsoleAllowed)
+    if (!m_synthesizedErrorsToConsole || !m_numGLErrorsToConsoleAllowed)
         return;
 
+    std::unique_ptr<Inspector::ConsoleMessage> consoleMessage;
+
+    // Error messages can occur during function calls, so show stack traces for them.
+    if (level == MessageLevel::Error) {
+        Ref<Inspector::ScriptCallStack> stackTrace = Inspector::createScriptCallStack(JSMainThreadExecState::currentState(), Inspector::ScriptCallStack::maxCallStackSizeToCapture);
+        consoleMessage = std::make_unique<Inspector::ConsoleMessage>(MessageSource::Rendering, MessageType::Log, level, message, WTFMove(stackTrace));
+    } else
+        consoleMessage = std::make_unique<Inspector::ConsoleMessage>(MessageSource::Rendering, MessageType::Log, level, message);
+
+    canvas().document().addConsoleMessage(WTFMove(consoleMessage));
+
     --m_numGLErrorsToConsoleAllowed;
-    printWarningToConsole(message);
-
     if (!m_numGLErrorsToConsoleAllowed)
-        printWarningToConsole("WebGL: too many errors, no more errors will be reported to the console for this context.");
+        printToConsole(MessageLevel::Warning, "WebGL: too many errors, no more errors will be reported to the console for this context.");
 }
 
-void WebGLRenderingContextBase::printWarningToConsole(const String& message)
-{
-    canvas().document().addConsoleMessage(MessageSource::Rendering, MessageLevel::Warning, message);
-}
-
 bool WebGLRenderingContextBase::validateBlendFuncFactors(const char* functionName, GC3Denum src, GC3Denum dst)
 {
     if (((src == GraphicsContext3D::CONSTANT_COLOR || src == GraphicsContext3D::ONE_MINUS_CONSTANT_COLOR)
@@ -5595,7 +5613,7 @@
     case Extensions3D::GUILTY_CONTEXT_RESET_ARB:
         // The rendering context is not restored if this context was
         // guilty of causing the graphics reset.
-        printWarningToConsole("WARNING: WebGL content on the page caused the graphics card to reset; not restoring the context");
+        printToConsole(MessageLevel::Warning, "WARNING: WebGL content on the page caused the graphics card to reset; not restoring the context");
         return;
     case Extensions3D::INNOCENT_CONTEXT_RESET_ARB:
         // Always allow the context to be restored.
@@ -5606,7 +5624,7 @@
         // reset and ask them whether they want to continue running
         // the content. Only if they say "yes" should we start
         // attempting to restore the context.
-        printWarningToConsole("WARNING: WebGL content on the page might have caused the graphics card to reset");
+        printToConsole(MessageLevel::Warning, "WARNING: WebGL content on the page might have caused the graphics card to reset");
         break;
     }
 
@@ -5728,21 +5746,12 @@
 void WebGLRenderingContextBase::synthesizeGLError(GC3Denum error, const char* functionName, const char* description, ConsoleDisplayPreference display)
 {
     if (m_synthesizedErrorsToConsole && display == DisplayInConsole) {
-      String str = String("WebGL: ") + GetErrorString(error) +  ": " + String(functionName) + ": " + String(description);
-      printGLErrorToConsole(str);
+        String str = "WebGL: " + GetErrorString(error) +  ": " + String(functionName) + ": " + String(description);
+        printToConsole(MessageLevel::Error, str);
     }
     m_context->synthesizeGLError(error);
 }
 
-
-void WebGLRenderingContextBase::printGLWarningToConsole(const char* functionName, const char* description)
-{
-    if (m_synthesizedErrorsToConsole) {
-        String str = String("WebGL: ") + String(functionName) + ": " + String(description);
-        printGLErrorToConsole(str);
-    }
-}
-
 void WebGLRenderingContextBase::applyStencilTest()
 {
     bool haveStencilBuffer = false;

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h (218602 => 218603)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.h	2017-06-20 18:35:31 UTC (rev 218603)
@@ -743,14 +743,9 @@
     // Helper function for texParameterf and texParameteri.
     void texParameter(GC3Denum target, GC3Denum pname, GC3Dfloat parami, GC3Dint paramf, bool isFloat);
 
-    // Helper function to print GL errors to console.
-    void printGLErrorToConsole(const String&);
-    void printGLWarningToConsole(const char* function, const char* reason);
+    // Helper function to print errors and warnings to console.
+    void printToConsole(MessageLevel, const String&);
 
-    // Helper function to print warnings to console. Currently
-    // used only to warn about use of obsolete functions.
-    void printWarningToConsole(const String&);
-
     // Helper function to validate input parameters for framebuffer functions.
     // Generate GL error if parameters are illegal.
     virtual bool validateFramebufferFuncParameters(const char* functionName, GC3Denum target, GC3Denum attachment) = 0;

Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (218602 => 218603)


--- trunk/Source/WebCore/page/PageConsoleClient.cpp	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp	2017-06-20 18:35:31 UTC (rev 218603)
@@ -105,6 +105,18 @@
     column = position.m_column.oneBasedInt();
 }
 
+void PageConsoleClient::addMessage(std::unique_ptr<Inspector::ConsoleMessage>&& consoleMessage)
+{
+    if (consoleMessage->source() != MessageSource::CSS && !m_page.usesEphemeralSession()) {
+        m_page.chrome().client().addMessageToConsole(consoleMessage->source(), consoleMessage->level(), consoleMessage->message(), consoleMessage->line(), consoleMessage->column(), consoleMessage->url());
+
+        if (m_page.settings().logsPageMessagesToSystemConsoleEnabled() || shouldPrintExceptions())
+            ConsoleClient::printConsoleMessage(MessageSource::ConsoleAPI, MessageType::Log, consoleMessage->level(), consoleMessage->message(), consoleMessage->url(), consoleMessage->line(), consoleMessage->column());
+    }
+
+    InspectorInstrumentation::addMessageToConsole(m_page, WTFMove(consoleMessage));
+}
+
 void PageConsoleClient::addMessage(MessageSource source, MessageLevel level, const String& message, unsigned long requestIdentifier, Document* document)
 {
     String url;
@@ -132,24 +144,7 @@
     else
         message = std::make_unique<Inspector::ConsoleMessage>(source, MessageType::Log, level, messageText, suggestedURL, suggestedLineNumber, suggestedColumnNumber, state, requestIdentifier);
 
-    String url = ""
-    unsigned lineNumber = message->line();
-    unsigned columnNumber = message->column();
-
-    InspectorInstrumentation::addMessageToConsole(m_page, WTFMove(message));
-
-    if (source == MessageSource::CSS)
-        return;
-
-    if (m_page.usesEphemeralSession())
-        return;
-
-    m_page.chrome().client().addMessageToConsole(source, level, messageText, lineNumber, columnNumber, url);
-
-    if (!m_page.settings().logsPageMessagesToSystemConsoleEnabled() && !shouldPrintExceptions())
-        return;
-
-    ConsoleClient::printConsoleMessage(MessageSource::ConsoleAPI, MessageType::Log, level, messageText, url, lineNumber, columnNumber);
+    addMessage(WTFMove(message));
 }
 
 

Modified: trunk/Source/WebCore/page/PageConsoleClient.h (218602 => 218603)


--- trunk/Source/WebCore/page/PageConsoleClient.h	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/page/PageConsoleClient.h	2017-06-20 18:35:31 UTC (rev 218603)
@@ -32,6 +32,10 @@
 #include <runtime/ConsoleClient.h>
 #include <wtf/Forward.h>
 
+namespace Inspector {
+class ConsoleMessage;
+}
+
 namespace JSC {
 class ExecState;
 }
@@ -53,6 +57,10 @@
     static void mute();
     static void unmute();
 
+    void addMessage(std::unique_ptr<Inspector::ConsoleMessage>&&);
+
+    // The following addMessage function are deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&& = nullptr, JSC::ExecState* = nullptr, unsigned long requestIdentifier = 0);
     void addMessage(MessageSource, MessageLevel, const String& message, Ref<Inspector::ScriptCallStack>&&);
     void addMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0, Document* = nullptr);

Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.h (218602 => 218603)


--- trunk/Source/WebCore/workers/WorkerGlobalScope.h	2017-06-20 18:27:31 UTC (rev 218602)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.h	2017-06-20 18:35:31 UTC (rev 218603)
@@ -99,7 +99,7 @@
 
     bool isClosing() { return m_closing; }
 
-    void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&);
+    void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&) final;
 
     Crypto& crypto();
 
@@ -122,6 +122,9 @@
     void derefEventTarget() final { deref(); }
 
     void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) final;
+
+    // The following addMessage and addConsoleMessage functions are deprecated.
+    // Callers should try to create the ConsoleMessage themselves.
     void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState*, unsigned long requestIdentifier) final;
     void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier) final;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to