Changeset 63805 in webkit


Ignore:
Timestamp:
Jul 20, 2010 11:53:12 PM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-07-20 Yury Semikhatsky <yurys@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@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.
Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r63799 r63805  
     12010-07-20  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        console.assert should include stack trace with line numbers.
     6        https://bugs.webkit.org/show_bug.cgi?id=22556
     7
     8        * inspector/console-assert-expected.txt: Added.
     9        * inspector/console-assert.html: Added.
     10
    1112010-07-20  Adam Barth  <abarth@webkit.org>
    212
  • trunk/WebCore/ChangeLog

    r63804 r63805  
     12010-07-20  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        console.assert should include stack trace with line numbers.
     6        https://bugs.webkit.org/show_bug.cgi?id=22556
     7
     8        Test: inspector/console-assert.html
     9
     10        * bindings/v8/ScriptCallStack.cpp:
     11        (WebCore::getTopFrameLocation):
     12        (WebCore::toScriptCallFramesVector):
     13        (WebCore::ScriptCallStack::create):
     14        (WebCore::ScriptCallStack::ScriptCallStack):
     15        * bindings/v8/ScriptCallStack.h:
     16        * bindings/v8/ScriptController.cpp:
     17        (WebCore::ScriptController::setCaptureCallStackForUncaughtExceptions):
     18        * bindings/v8/custom/V8ConsoleCustom.cpp:
     19        (WebCore::V8Console::traceCallback):
     20        (WebCore::V8Console::assertCallback):
     21        * inspector/ConsoleMessage.cpp:
     22        (WebCore::ConsoleMessage::ConsoleMessage):
     23        * inspector/InspectorController.cpp:
     24        (WebCore::InspectorController::addMessageToConsole):
     25        * inspector/front-end/ConsoleView.js:
     26        (WebInspector.ConsoleMessage.prototype._formatMessage):
     27        (WebInspector.ConsoleMessage.prototype.toMessageElement):
     28        * page/Console.cpp:
     29        (WebCore::Console::lastWMLErrorMessage):
     30        * page/Console.idl:
     31
    1322010-07-20  Rafael Antognolli  <antognolli@profusion.mobi>
    233
  • trunk/WebCore/bindings/v8/ScriptCallStack.cpp

    r63753 r63805  
    5252}
    5353
     54static void getTopFrameLocation(v8::Handle<v8::StackTrace> stackTrace, String* sourceName, int* sourceLineNumber, String* functionName)
     55{
     56    if (stackTrace->GetFrameCount() <= 0) {
     57        // Successfully grabbed stack trace, but there are no frames. It may happen in case of a syntax error for example.
     58        // Fallback to setting lineNumber to 0, and source and function name to "undefined".
     59        *sourceName = "undefined";
     60        *sourceLineNumber = 0;
     61        *functionName = "undefined";
     62    } else {
     63        v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0);
     64        getFrameLocation(frame, sourceName, sourceLineNumber, functionName);
     65    }
     66}
     67
    5468static PassOwnPtr<ScriptCallFrame> toScriptCallFrame(v8::Handle<v8::StackFrame> frame)
    5569{
     
    6175}
    6276
    63 PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount)
     77static void toScriptCallFramesVector(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames)
     78{
     79    v8::Context::Scope contextScope(context);
     80    int frameCount = stackTrace->GetFrameCount();
     81    for (int i = 0; i < frameCount; i++) {
     82        v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
     83        scriptCallFrames.append(toScriptCallFrame(stackFrame));
     84    }
     85}
     86
     87const int ScriptCallStack::maxCallStackSizeToCapture = 200;
     88
     89PassOwnPtr<ScriptCallStack> ScriptCallStack::create(const v8::Arguments& arguments, unsigned skipArgumentCount, int framCountLimit)
    6490{
    6591    v8::HandleScope scope;
    66     v8::Context::Scope contextScope(v8::Context::GetCurrent());
    67     v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(1));
     92    v8::Local<v8::Context> context = v8::Context::GetCurrent();
     93    v8::Context::Scope contextScope(context);
     94    v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(framCountLimit));
    6895
    6996    if (stackTrace.IsEmpty())
     
    73100    int sourceLineNumber;
    74101    String functionName;
    75     if (stackTrace->GetFrameCount() <= 0) {
    76         // Successfully grabbed stack trace, but there are no frames.
    77         // Fallback to setting lineNumber to 0, and source and function name to "undefined".
    78         sourceName = toWebCoreString(v8::Undefined());
    79         sourceLineNumber = 0;
    80         functionName = toWebCoreString(v8::Undefined());
    81     } else {
    82         v8::Handle<v8::StackFrame> frame = stackTrace->GetFrame(0);
    83         getFrameLocation(frame, &sourceName, &sourceLineNumber, &functionName);
    84     }
    85     return new ScriptCallStack(arguments, skipArgumentCount, sourceName, sourceLineNumber, functionName);
     102    getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName);
     103
     104    Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames;
     105    if (framCountLimit > 1)
     106        toScriptCallFramesVector(context, stackTrace, scriptCallFrames);
     107
     108    return new ScriptCallStack(ScriptState::forContext(context), new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount), scriptCallFrames);
    86109}
    87110
    88111PassOwnPtr<ScriptCallStack> ScriptCallStack::create(ScriptState* state, v8::Handle<v8::StackTrace> stackTrace)
    89112{
    90     return new ScriptCallStack(state, stackTrace);
     113    v8::HandleScope scope;
     114    Vector<OwnPtr<ScriptCallFrame> > scriptCallFrames;
     115    toScriptCallFramesVector(state->context(), stackTrace, scriptCallFrames);
     116
     117    String sourceName;
     118    int sourceLineNumber;
     119    String functionName;
     120    getTopFrameLocation(stackTrace, &sourceName, &sourceLineNumber, &functionName);
     121
     122    return new ScriptCallStack(state, new ScriptCallFrame(functionName, sourceName, sourceLineNumber), scriptCallFrames);
    91123}
    92124
    93 ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String functionName)
    94     : m_topFrame(new ScriptCallFrame(functionName, sourceName, sourceLineNumber, arguments, skipArgumentCount))
    95     , m_scriptState(ScriptState::current())
     125ScriptCallStack::ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames)
     126    : m_topFrame(topFrame)
     127    , m_scriptState(scriptState)
    96128{
    97 }
    98 
    99 ScriptCallStack::ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace)
    100     : m_scriptState(scriptState)
    101 {
    102     v8::HandleScope handleScope;
    103     v8::Context::Scope contextScope(m_scriptState->context());
    104     int frameCount = stackTrace->GetFrameCount();
    105     for (int i = 0; i < frameCount; i++) {
    106         v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
    107         m_scriptCallFrames.append(toScriptCallFrame(stackFrame));
    108     }
     129    m_scriptCallFrames.swap(scriptCallFrames);
    109130}
    110131
  • trunk/WebCore/bindings/v8/ScriptCallStack.h

    r63548 r63805  
    4949class ScriptCallStack : public Noncopyable {
    5050public:
    51     static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0);
     51    static const int maxCallStackSizeToCapture;
     52
     53    static PassOwnPtr<ScriptCallStack> create(const v8::Arguments&, unsigned skipArgumentCount = 0, int framCountLimit = 1);
    5254    static PassOwnPtr<ScriptCallStack> create(ScriptState*, v8::Handle<v8::StackTrace>);
    5355    ~ScriptCallStack();
     
    7173
    7274private:
    73     ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber, String funcName);
     75    ScriptCallStack(ScriptState* scriptState, PassOwnPtr<ScriptCallFrame> topFrame, Vector<OwnPtr<ScriptCallFrame> >& scriptCallFrames);
    7476    ScriptCallStack(ScriptState* scriptState, v8::Handle<v8::StackTrace> stackTrace);
    7577
  • trunk/WebCore/bindings/v8/ScriptController.cpp

    r63662 r63805  
    3535#include "PlatformBridge.h"
    3636#include "Document.h"
     37#include "ScriptCallStack.h"
    3738#include "ScriptableDocumentParser.h"
    3839#include "DOMWindow.h"
     
    455456void ScriptController::setCaptureCallStackForUncaughtExceptions(bool)
    456457{
    457     v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, 200);
     458    v8::V8::SetCaptureStackTraceForUncaughtExceptions(true, ScriptCallStack::maxCallStackSizeToCapture);
    458459}
    459460#endif
  • trunk/WebCore/bindings/v8/custom/V8ConsoleCustom.cpp

    r63548 r63805  
    6565    v8::HandleScope handleScope;
    6666    ScriptState* scriptState = ScriptState::current();
    67     v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(200);
     67    v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(ScriptCallStack::maxCallStackSizeToCapture);
    6868    OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(scriptState, stackTrace));
    6969    imp->trace(callStack.get());
    7070    return v8::Handle<v8::Value>();
    7171}
     72
     73v8::Handle<v8::Value> V8Console::assertCallback(const v8::Arguments& args)
     74{
     75    INC_STATS("DOM.Console.assertCallback");
     76    Console* imp = V8Console::toNative(args.Holder());
     77    OwnPtr<ScriptCallStack> callStack(ScriptCallStack::create(args, 1, ScriptCallStack::maxCallStackSizeToCapture));
     78    bool condition = args[0]->BooleanValue();
     79    imp->assertCondition(condition, callStack.get());
     80    return v8::Handle<v8::Value>();
     81}
     82
    7283} // namespace WebCore
  • trunk/WebCore/inspector/ConsoleMessage.cpp

    r63662 r63805  
    9898    m_url = lastCaller.sourceURL().string();
    9999
    100     // FIXME: For now, just store function names as strings.
    101     // As ScriptCallStack start storing line number and source URL for all
    102     // frames, refactor to use that, as well.
    103100    if (storeTrace) {
    104101        for (unsigned i = 0; i < callStack->size(); ++i)
  • trunk/WebCore/inspector/InspectorController.cpp

    r63662 r63805  
    344344        return;
    345345
    346     addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, type == TraceMessageType || type == UncaughtExceptionMessageType));
     346    bool storeStackTrace = type == TraceMessageType || type == UncaughtExceptionMessageType || type == AssertMessageType;
     347    addConsoleMessage(callStack->state(), new ConsoleMessage(source, type, level, message, callStack, m_groupLevel, storeStackTrace));
    347348}
    348349
  • trunk/WebCore/inspector/front-end/ConsoleView.js

    r63732 r63805  
    673673    {
    674674        switch (this.type) {
     675            case WebInspector.ConsoleMessage.MessageType.Assert:
    675676            case WebInspector.ConsoleMessage.MessageType.Trace:
    676677            case WebInspector.ConsoleMessage.MessageType.UncaughtException:
     
    682683
    683684                var root = treeOutline;
    684                 if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException) {
    685                     var li = document.createElement("li");
    686                     this._addMessageHeader(li, document.createTextNode(this._messageText));
    687                     root = new TreeElement(li.innerHTML, null, true);
     685                if (this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException ||
     686                    this.type === WebInspector.ConsoleMessage.MessageType.Assert) {
     687                    var messageText;
     688                    if (this.type === WebInspector.ConsoleMessage.MessageType.Assert)
     689                        messageText = this._format(this._parameters);
     690                    else
     691                        messageText = document.createTextNode(this._messageText);
     692
     693                    var content = document.createElement("div");
     694                    this._addMessageHeader(content, messageText);
     695                    root = new TreeElement(content, null, true);
     696                    content.treeElementForTest = root;
    688697                    treeOutline.appendChild(root);
    689698                }
     
    842851
    843852        if (this.type === WebInspector.ConsoleMessage.MessageType.Trace ||
     853            this.type === WebInspector.ConsoleMessage.MessageType.Assert ||
    844854            this.type === WebInspector.ConsoleMessage.MessageType.UncaughtException)
    845855            element.appendChild(this.formattedMessage);
  • trunk/WebCore/page/Console.cpp

    r63662 r63805  
    301301        return String();
    302302
    303     const Vector<ConsoleMessage*>& consoleMessages = page->inspectorController()->consoleMessages();
     303    const Vector<OwnPtr<ConsoleMessage> >& consoleMessages = page->inspectorController()->consoleMessages();
    304304    if (consoleMessages.isEmpty())
    305305        return String();
    306306
    307     Vector<ConsoleMessage*>::const_iterator it = consoleMessages.begin();
    308     const Vector<ConsoleMessage*>::const_iterator end = consoleMessages.end();
     307    Vector<OwnPtr<ConsoleMessage> >::const_iterator it = consoleMessages.begin();
     308    const Vector<OwnPtr<ConsoleMessage> >::const_iterator end = consoleMessages.end();
    309309
    310310    for (; it != end; ++it) {
    311         ConsoleMessage* message = *it;
     311        ConsoleMessage* message = it->get();
    312312        if (message->source() != WMLMessageSource)
    313313            continue;
  • trunk/WebCore/page/Console.idl

    r63548 r63805  
    4343        [CustomArgumentHandling] void dirxml();
    4444        [V8Custom, CustomArgumentHandling] void trace();
    45         [CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition);
     45        [V8Custom, CustomArgumentHandling, ImplementationFunction=assertCondition] void assert(in boolean condition);
    4646        [CustomArgumentHandling] void count();
    4747        [CustomArgumentHandling] void markTimeline();
Note: See TracChangeset for help on using the changeset viewer.