[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

yurys at chromium.org yurys at chromium.org
Wed Dec 22 11:22:55 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ace939fee7504c1f2822a79194289bc16a805bad
Author: yurys at chromium.org <yurys at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Jul 21 06:53:12 2010 +0000

    2010-07-20  Yury Semikhatsky  <yurys at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            console.assert should include stack trace with line numbers.
            https://bugs.webkit.org/show_bug.cgi?id=22556
    
            Test: inspector/console-assert.html
    
            * bindings/v8/ScriptCallStack.cpp:
            (WebCore::getTopFrameLocation):
            (WebCore::toScriptCallFramesVector):
            (WebCore::ScriptCallStack::create):
            (WebCore::ScriptCallStack::ScriptCallStack):
            * bindings/v8/ScriptCallStack.h:
            * bindings/v8/ScriptController.cpp:
            (WebCore::ScriptController::setCaptureCallStackForUncaughtExceptions):
            * bindings/v8/custom/V8ConsoleCustom.cpp:
            (WebCore::V8Console::traceCallback):
            (WebCore::V8Console::assertCallback):
            * inspector/ConsoleMessage.cpp:
            (WebCore::ConsoleMessage::ConsoleMessage):
            * inspector/InspectorController.cpp:
            (WebCore::InspectorController::addMessageToConsole):
            * inspector/front-end/ConsoleView.js:
            (WebInspector.ConsoleMessage.prototype._formatMessage):
            (WebInspector.ConsoleMessage.prototype.toMessageElement):
            * page/Console.cpp:
            (WebCore::Console::lastWMLErrorMessage):
            * page/Console.idl:
    
    2010-07-20  Yury Semikhatsky  <yurys at chromium.org>
    
            Reviewed by Pavel Feldman.
    
            console.assert should include stack trace with line numbers.
            https://bugs.webkit.org/show_bug.cgi?id=22556
    
            * inspector/console-assert-expected.txt: Added.
            * inspector/console-assert.html: Added.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63805 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 99425aa..3c491b4 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,13 @@
+2010-07-20  Yury Semikhatsky  <yurys at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        console.assert should include stack trace with line numbers.
+        https://bugs.webkit.org/show_bug.cgi?id=22556
+
+        * inspector/console-assert-expected.txt: Added.
+        * inspector/console-assert.html: Added.
+
 2010-07-20  Adam Barth  <abarth at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/LayoutTests/inspector/console-assert-expected.txt b/LayoutTests/inspector/console-assert-expected.txt
new file mode 100644
index 0000000..c7b7357
--- /dev/null
+++ b/LayoutTests/inspector/console-assert-expected.txt
@@ -0,0 +1,7 @@
+CONSOLE MESSAGE: line 9: 1
+CONSOLE MESSAGE: line 10: a
+Tests that console.assert() will dump a message and stack trace with source URLs and line numbers.
+
+console-assert.html:9Assertion failed: 1bconsole-assert.html:9aconsole-assert.html:15
+console-assert.html:10Assertion failed: a bbconsole-assert.html:10aconsole-assert.html:15
+
diff --git a/LayoutTests/inspector/console-assert.html b/LayoutTests/inspector/console-assert.html
new file mode 100755
index 0000000..5d298a4
--- /dev/null
+++ b/LayoutTests/inspector/console-assert.html
@@ -0,0 +1,48 @@
+<html>
+<head>
+<script src="../http/tests/inspector/inspector-test.js"></script>
+<script src="../http/tests/inspector/console-tests.js"></script>
+<script>
+
+function b()
+{
+    console.assert(false, 1);
+    console.assert(false, "a", "b");
+}
+
+function a()
+{
+    b();
+    evaluateInWebInspector("frontend_expandConsoleMessages");
+    dumpConsoleMessages();
+}
+
+function doit()
+{
+    setTimeout(a, 0);
+}
+
+function frontend_expandConsoleMessages()
+{
+    var messages = WebInspector.console.messages;
+    for (var i = 0; i < messages.length; ++i) {
+        var element = messages[i].toMessageElement();
+        var node = element;
+        while (node) {
+            if (node.treeElementForTest)
+                node.treeElementForTest.expand();
+            node = node.traverseNextNode(element);
+        }
+    }
+}
+
+</script>
+</head>
+
+<body onload="onload()">
+<p>
+Tests that console.assert() will dump a message and stack trace with source URLs and line numbers.
+</p>
+
+</body>
+</html>
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index dac7cc6..4af7110 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,34 @@
+2010-07-20  Yury Semikhatsky  <yurys at chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        console.assert should include stack trace with line numbers.
+        https://bugs.webkit.org/show_bug.cgi?id=22556
+
+        Test: inspector/console-assert.html
+
+        * bindings/v8/ScriptCallStack.cpp:
+        (WebCore::getTopFrameLocation):
+        (WebCore::toScriptCallFramesVector):
+        (WebCore::ScriptCallStack::create):
+        (WebCore::ScriptCallStack::ScriptCallStack):
+        * bindings/v8/ScriptCallStack.h:
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::setCaptureCallStackForUncaughtExceptions):
+        * bindings/v8/custom/V8ConsoleCustom.cpp:
+        (WebCore::V8Console::traceCallback):
+        (WebCore::V8Console::assertCallback):
+        * inspector/ConsoleMessage.cpp:
+        (WebCore::ConsoleMessage::ConsoleMessage):
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::addMessageToConsole):
+        * inspector/front-end/ConsoleView.js:
+        (WebInspector.ConsoleMessage.prototype._formatMessage):
+        (WebInspector.ConsoleMessage.prototype.toMessageElement):
+        * page/Console.cpp:
+        (WebCore::Console::lastWMLErrorMessage):
+        * page/Console.idl:
+
 2010-07-20  Rafael Antognolli  <antognolli at profusion.mobi>
 
         Reviewed by Kent Tamura.
diff --git a/WebCore/bindings/v8/ScriptCallStack.cpp b/WebCore/bindings/v8/ScriptCallStack.cpp
index 48168ba..98ddb90 100644
--- a/WebCore/bindings/v8/ScriptCallStack.cpp
+++ b/WebCore/bindings/v8/ScriptCallStack.cpp
@@ -51,6 +51,20 @@ static void getFrameLocation(v8::Handle<v8::StackFrame> frame, String* sourceNam
     *sourceLineNumber = frame->GetLineNumber();
 }
 
+static void getTopFrameLocation(v8::Handle<v8::StackTrace> stackTrace, String* sourceName, int* sourceLineNumber, String* functionName)
+{
+    if (stackTrace->GetFrameCount() <= 0) {
+        // Successfully grabbed stack trace, but there are no frames. It may happen in case of a syntax error for example.
+        // Fallback to setting lineNumber to 0, and source and function name to "undefined".
+        *sourceName = "undefined";
+        *sourceLineNumber = 0;
+        *functionName = "undefined";
+    } else {
+        v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0);
+        getFrameLocation(frame, sourceName, sourceLineNumber, functionName);
+    }
+}
+
 static PassOwnPtr<ScriptCallFrame> toScriptCallFrame(v8::Handle<v8::StackFrame> frame)
 {
     String sourceName;
@@ -60,11 +74,24 @@ static PassOwnPtr<ScriptCallFrame> toScriptCallFrame(v8::Handle<v8::StackFrame>
     return new ScriptCallFrame(functionName, sourceName, sourceLineNumber);
 }
 
-PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount)
+static void toScriptCallFramesVector(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames)
+{
+    v8::Context::Scope contextScope(context);
+    int frameCount = stackTrace->GetFrameCount();
+    for (int i = 0; i < frameCount; i++) {
+        v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
+        scriptCallFrames.append(toScriptCallFrame(stackFrame));
+    }
+}
+
+const int ScriptCallStack::maxCallStackSizeToCapture = 200;
+
+PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount, int framCountLimit)
 {
     v8::HandleScope scope;
-    v8::Context::Scope contextScope(v8::Context::GetCurrent());
-    v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(1));
+    v8::Local<v8::Context> context = v8::Context::GetCurrent();
+    v8::Context::Scope contextScope(context);
+    v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(framCountLimit));
 
     if (stackTrace.IsEmpty())
         return 0;
@@ -72,40 +99,34 @@ PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& argumen
     String sourceName;
     int sourceLineNumber;
     String functionName;
-    if (stackTrace->GetFrameCount() <= 0) {
-        // Successfully grabbed stack trace, but there are no frames.
-        // Fallback to setting lineNumber to 0, and source and function name to "undefined".
-        sourceName = toWebCoreString(v8::Undefined());
-        sourceLineNumber = 0;
-        functionName = toWebCoreString(v8::Undefined());
-    } else {
-        v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0);
-        getFrameLocation(frame, &sourceName, &sourceLineNumber, &functionName);
-    }
-    return new ScriptCallStack(arguments, skipArgumentCount, sourceName, sourceLineNumber, functionName);
+    getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName);
+
+    Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames;
+    if (framCountLimit > 1)
+        toScriptCallFramesVector(context, stackTrace, scriptCallFrames);
+
+    return new ScriptCallStack(ScriptState::forContext(context), new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount), scriptCallFrames);
 }
 
 PassOwnPtr<ScriptCallStack> ScriptCallStack::create(ScriptState* state, v8::Handle<v8::StackTrace> stackTrace)
 {
-    return new ScriptCallStack(state, stackTrace);
-}
+    v8::HandleScope scope;
+    Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames;
+    toScriptCallFramesVector(state->context(), stackTrace, scriptCallFrames);
 
-ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String functionName)
-    : m_topFrame(new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount))
-    , m_scriptState(ScriptState::current())
-{
+    String sourceName;
+    int sourceLineNumber;
+    String functionName;
+    getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName);
+
+    return new ScriptCallStack(state, new ScriptCallFrame(functionName, sourceName, sourceLineNumber), scriptCallFrames);
 }
 
-ScriptCallStack::ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace)
-    : m_scriptState(scriptState)
+ScriptCallStack::ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames)
+    : m_topFrame(topFrame)
+    , m_scriptState(scriptState)
 {
-    v8::HandleScope handleScope;
-    v8::Context::Scope contextScope(m_scriptState->context());
-    int frameCount = stackTrace->GetFrameCount();
-    for (int i = 0; i < frameCount; i++) {
-        v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
-        m_scriptCallFrames.append(toScriptCallFrame(stackFrame));
-    }
+    m_scriptCallFrames.swap(scriptCallFrames);
 }
 
 ScriptCallStack::~ScriptCallStack()
diff --git a/WebCore/bindings/v8/ScriptCallStack.h b/WebCore/bindings/v8/ScriptCallStack.h
index d21b9f9..b608563 100644
--- a/WebCore/bindings/v8/ScriptCallStack.h
+++ b/WebCore/bindings/v8/ScriptCallStack.h
@@ -48,7 +48,9 @@ class InspectorArray;
 
 class ScriptCallStack : public Noncopyable {
 public:
-    static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0);
+    static const int maxCallStackSizeToCapture;
+
+    static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0, int framCountLimit = 1);
     static PassOwnPtr<ScriptCallStack> create(ScriptState*, v8::Handle<v8::StackTrace>);
     ~ScriptCallStack();
 
@@ -70,7 +72,7 @@ public:
     ScriptState* globalState() const { return m_scriptState; }
 
 private:
-    ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String funcName);
+    ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames);
     ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace);
 
     OwnPtr<ScriptCallFrame> m_topFrame;
diff --git a/WebCore/bindings/v8/ScriptController.cpp b/WebCore/bindings/v8/ScriptController.cpp
index c8010f1..d76746e 100644
--- a/WebCore/bindings/v8/ScriptController.cpp
+++ b/WebCore/bindings/v8/ScriptController.cpp
@@ -34,6 +34,7 @@
 
 #include "PlatformBridge.h"
 #include "Document.h"
+#include "ScriptCallStack.h"
 #include "ScriptableDocumentParser.h"
 #include "DOMWindow.h"
 #include "Event.h"
@@ -454,7 +455,7 @@ void ScriptController::clearWindowShell(bool)
 #if ENABLE(INSPECTOR)
 void ScriptController::setCaptureCallStackForUncaughtExceptions(bool)
 {
-    v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 200);
+    v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, ScriptCallStack::maxCallStackSizeToCapture);
 }
 #endif
 
diff --git a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp
index a09e1b3..baffbd4 100644
--- a/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp
+++ b/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp
@@ -64,9 +64,20 @@ v8::Handle<v8::Value> V8Console::traceCallback(const v8::Arguments& args)
     Console* imp = V8Console::toNative(args.Holder());
     v8::HandleScope handleScope;
     ScriptState* scriptState = ScriptState::current();
-    v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(200);
+    v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(ScriptCallStack::maxCallStackSizeToCapture);
     OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(scriptState, stackTrace));
     imp->trace(callStack.get());
     return v8::Handle<v8::Value>();
 }
+
+v8::Handle<v8::Value> V8Console::assertCallback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.Console.assertCallback");
+    Console* imp = V8Console::toNative(args.Holder());
+    OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1, ScriptCallStack::maxCallStackSizeToCapture));
+    bool condition = args[0]->BooleanValue();
+    imp->assertCondition(condition, callStack.get());
+    return v8::Handle<v8::Value>();
+}
+
 } // namespace WebCore
diff --git a/WebCore/inspector/ConsoleMessage.cpp b/WebCore/inspector/ConsoleMessage.cpp
index 260ec69..79b5115 100644
--- a/WebCore/inspector/ConsoleMessage.cpp
+++ b/WebCore/inspector/ConsoleMessage.cpp
@@ -97,9 +97,6 @@ ConsoleMessage::ConsoleMessage(MessageSource s, MessageType t, MessageLevel l, c
     m_line = lastCaller.lineNumber();
     m_url = lastCaller.sourceURL().string();
 
-    // FIXME: For now, just store function names as strings.
-    // As ScriptCallStack start storing line number and source URL for all
-    // frames, refactor to use that, as well.
     if (storeTrace) {
         for (unsigned i = 0; i < callStack->size(); ++i)
             m_frames[i] = ConsoleMessage::CallFrame(callStack->at(i));
diff --git a/WebCore/inspector/InspectorController.cpp b/WebCore/inspector/InspectorController.cpp
index 841ae5c..8879b8e 100644
--- a/WebCore/inspector/InspectorController.cpp
+++ b/WebCore/inspector/InspectorController.cpp
@@ -343,7 +343,8 @@ void InspectorController::addMessageToConsole(MessageSource source, MessageType
     if (!enabled())
         return;
 
-    addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, type == TraceMessageType || type == UncaughtExceptionMessageType));
+    bool storeStackTrace = type == TraceMessageType || type == UncaughtExceptionMessageType || type == AssertMessageType;
+    addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, storeStackTrace));
 }
 
 void InspectorController::addMessageToConsole(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID)
diff --git a/WebCore/inspector/front-end/ConsoleView.js b/WebCore/inspector/front-end/ConsoleView.js
index b2da77e..d4119a1 100644
--- a/WebCore/inspector/front-end/ConsoleView.js
+++ b/WebCore/inspector/front-end/ConsoleView.js
@@ -672,6 +672,7 @@ WebInspector.ConsoleMessage.prototype = {
     _formatMessage: function()
     {
         switch (this.type) {
+            case WebInspector.ConsoleMessage.MessageType.Assert:
             case WebInspector.ConsoleMessage.MessageType.Trace:
             case WebInspector.ConsoleMessage.MessageType.UncaughtException:
                 var ol = document.createElement("ol");
@@ -681,10 +682,18 @@ WebInspector.ConsoleMessage.prototype = {
                 var treeOutline = new TreeOutline(ol);
 
                 var root = treeOutline;
-                if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException) {
-                    var li = document.createElement("li");
-                    this._addMessageHeader(li, document.createTextNode(this._messageText));
-                    root = new TreeElement(li.innerHTML, null, true);
+                if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException ||
+                    this.type === WebInspector.ConsoleMessage.MessageType.Assert) {
+                    var messageText;
+                    if (this.type === WebInspector.ConsoleMessage.MessageType.Assert)
+                        messageText = this._format(this._parameters);
+                    else
+                        messageText = document.createTextNode(this._messageText);
+
+                    var content = document.createElement("div");
+                    this._addMessageHeader(content, messageText);
+                    root = new TreeElement(content, null, true);
+                    content.treeElementForTest = root;
                     treeOutline.appendChild(root);
                 }
 
@@ -841,6 +850,7 @@ WebInspector.ConsoleMessage.prototype = {
         }
 
         if (this.type === WebInspector.ConsoleMessage.MessageType.Trace ||
+            this.type === WebInspector.ConsoleMessage.MessageType.Assert ||
             this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException)
             element.appendChild(this.formattedMessage);
         else
diff --git a/WebCore/page/Console.cpp b/WebCore/page/Console.cpp
index 67f9bee..3d8a7de 100644
--- a/WebCore/page/Console.cpp
+++ b/WebCore/page/Console.cpp
@@ -300,15 +300,15 @@ String Console::lastWMLErrorMessage() const
     if (!page)
         return String();
 
-    const Vector<ConsoleMessage*>& consoleMessages = page->inspectorController()->consoleMessages();
+    const Vector<OwnPtr<ConsoleMessage> >& consoleMessages = page->inspectorController()->consoleMessages();
     if (consoleMessages.isEmpty())
         return String();
 
-    Vector<ConsoleMessage*>::const_iterator it = consoleMessages.begin();
-    const Vector<ConsoleMessage*>::const_iterator end = consoleMessages.end();
+    Vector<OwnPtr<ConsoleMessage> >::const_iterator it = consoleMessages.begin();
+    const Vector<OwnPtr<ConsoleMessage> >::const_iterator end = consoleMessages.end();
 
     for (; it != end; ++it) {
-        ConsoleMessage* message = *it;
+        ConsoleMessage* message = it->get();
         if (message->source() != WMLMessageSource)
             continue;
 
diff --git a/WebCore/page/Console.idl b/WebCore/page/Console.idl
index addf635..52528f1 100644
--- a/WebCore/page/Console.idl
+++ b/WebCore/page/Console.idl
@@ -42,7 +42,7 @@ module window {
         [CustomArgumentHandling] void dir();
         [CustomArgumentHandling] void dirxml();
         [V8Custom, CustomArgumentHandling] void trace();
-        [CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition);
+        [V8Custom, CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition);
         [CustomArgumentHandling] void count();
         [CustomArgumentHandling] void markTimeline();
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list