Changeset 73351 in webkit


Ignore:
Timestamp:
Dec 6, 2010 2:13:38 AM (13 years ago)
Author:
yurys@chromium.org
Message:

2010-12-03 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Pavel Feldman.

[v8] Web Inspector: remove duplicate code for capturing stack trace
https://bugs.webkit.org/show_bug.cgi?id=50461

No new tests. Covered with existing inspector tests.

  • bindings/js/ScriptCallStackFactory.cpp: (WebCore::createScriptCallStack):
  • bindings/js/ScriptCallStackFactory.h:
  • bindings/v8/ScriptCallStackFactory.cpp: (WebCore::toScriptCallFrame): (WebCore::toScriptCallFramesVector): (WebCore::createScriptCallStack):
  • bindings/v8/ScriptCallStackFactory.h:
  • bindings/v8/V8ConsoleMessage.cpp: (WebCore::V8ConsoleMessage::handler):
  • inspector/ScriptCallFrame.cpp: (WebCore::ScriptCallFrame::ScriptCallFrame): (WebCore::ScriptCallFrame::isEqual): (WebCore::ScriptCallFrame::buildInspectorObject):
  • inspector/ScriptCallFrame.h: (WebCore::ScriptCallFrame::sourceURL):
  • inspector/ScriptCallStack.h:
  • inspector/TimelineRecordFactory.cpp: (WebCore::TimelineRecordFactory::createGenericRecord):
  • inspector/front-end/ConsoleView.js: (WebInspector.ConsoleMessage.prototype._populateStackTraceTreeElement):
Location:
trunk/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73350 r73351  
     12010-12-03  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        [v8] Web Inspector: remove duplicate code for capturing stack trace
     6        https://bugs.webkit.org/show_bug.cgi?id=50461
     7
     8        No new tests. Covered with existing inspector tests.
     9
     10        * bindings/js/ScriptCallStackFactory.cpp:
     11        (WebCore::createScriptCallStack):
     12        * bindings/js/ScriptCallStackFactory.h:
     13        * bindings/v8/ScriptCallStackFactory.cpp:
     14        (WebCore::toScriptCallFrame):
     15        (WebCore::toScriptCallFramesVector):
     16        (WebCore::createScriptCallStack):
     17        * bindings/v8/ScriptCallStackFactory.h:
     18        * bindings/v8/V8ConsoleMessage.cpp:
     19        (WebCore::V8ConsoleMessage::handler):
     20        * inspector/ScriptCallFrame.cpp:
     21        (WebCore::ScriptCallFrame::ScriptCallFrame):
     22        (WebCore::ScriptCallFrame::isEqual):
     23        (WebCore::ScriptCallFrame::buildInspectorObject):
     24        * inspector/ScriptCallFrame.h:
     25        (WebCore::ScriptCallFrame::sourceURL):
     26        * inspector/ScriptCallStack.h:
     27        * inspector/TimelineRecordFactory.cpp:
     28        (WebCore::TimelineRecordFactory::createGenericRecord):
     29        * inspector/front-end/ConsoleView.js:
     30        (WebInspector.ConsoleMessage.prototype._populateStackTraceTreeElement):
     31
    1322010-12-06  Sergio Villar Senin  <svillar@igalia.com>
    233
  • trunk/WebCore/bindings/js/ScriptCallStackFactory.cpp

    r72895 r73351  
    4949namespace WebCore {
    5050
     51PassRefPtr<ScriptCallStack> createScriptCallStack(size_t)
     52{
     53    return 0;
     54}
     55
    5156PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)
    5257{
     
    8893}
    8994
    90 bool ScriptCallStack::stackTrace(int, const RefPtr<InspectorArray>&)
    91 {
    92     return false;
    93 }
    94 
    9595} // namespace WebCore
  • trunk/WebCore/bindings/js/ScriptCallStackFactory.h

    r72895 r73351  
    4343class ScriptCallStack;
    4444
     45PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize);
    4546PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState*, size_t maxStackSize);
    4647PassRefPtr<ScriptArguments> createScriptArguments(JSC::ExecState*, unsigned skipArgumentCount);
  • trunk/WebCore/bindings/v8/ScriptCallStackFactory.cpp

    r72895 r73351  
    5757
    5858    int sourceLineNumber = frame->GetLineNumber();
    59     return ScriptCallFrame(functionName, sourceName, sourceLineNumber);
     59    int sourceColumn = frame->GetColumn();
     60    return ScriptCallFrame(functionName, sourceName, sourceLineNumber, sourceColumn);
    6061}
    6162
    62 static void toScriptCallFramesVector(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, Vector<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize)
     63static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vector<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize)
    6364{
    64     // TODO(yurys): remove this???
    65     v8::Context::Scope contextScope(context);
     65    ASSERT(v8::Context::InContext());
    6666    int frameCount = stackTrace->GetFrameCount();
    6767    if (frameCount > static_cast<int>(maxStackSize))
     
    7171        scriptCallFrames.append(toScriptCallFrame(stackFrame));
    7272    }
    73    
    74     if (!frameCount) {
    75         // Successfully grabbed stack trace, but there are no frames. It may happen in case of a syntax error for example.
    76         // Fallback to setting lineNumber to 0, and source and function name to "undefined".
    77         scriptCallFrames.append(ScriptCallFrame("undefined", "undefined", 0));
    78     }
    7973}
    8074
    81 PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context> context, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize)
     75PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize)
    8276{
     77    ASSERT(v8::Context::InContext());
    8378    v8::HandleScope scope;
    84     v8::Context::Scope contextScope(context);
    85 
    8679    Vector<ScriptCallFrame> scriptCallFrames;
    87     toScriptCallFramesVector(context, stackTrace, scriptCallFrames, maxStackSize);
     80    toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize);
    8881    return ScriptCallStack::create(scriptCallFrames);
    8982}
     
    9184PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize)
    9285{
    93     v8::HandleScope scope;
    94     v8::Local<v8::Context> context = v8::Context::GetCurrent();
    95     // TODO(yurys): remove?
    96     v8::Context::Scope contextScope(context);
     86    if (!v8::Context::InContext())
     87        return 0;
     88    v8::HandleScope handleScope;
    9789    v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(maxStackSize, stackTraceOptions));
    98     return createScriptCallStack(context, stackTrace, maxStackSize);
     90    return createScriptCallStack(stackTrace, maxStackSize);
    9991}
    10092
     
    112104}
    113105
    114 bool ScriptCallStack::stackTrace(int frameLimit, const RefPtr<InspectorArray>& stackTrace)
    115 {
    116 #if ENABLE(INSPECTOR)
    117     if (!v8::Context::InContext())
    118         return false;
    119     v8::Handle<v8::Context> context = v8::Context::GetCurrent();
    120     if (context.IsEmpty())
    121         return false;
    122     v8::HandleScope scope;
    123     v8::Context::Scope contextScope(context);
    124     v8::Handle<v8::StackTrace> trace(v8::StackTrace::CurrentStackTrace(frameLimit));
    125     int frameCount = trace->GetFrameCount();
    126     if (trace.IsEmpty() || !frameCount)
    127         return false;
    128     for (int i = 0; i < frameCount; ++i) {
    129         v8::Handle<v8::StackFrame> frame = trace->GetFrame(i);
    130         RefPtr<InspectorObject> frameObject = InspectorObject::create();
    131         v8::Local<v8::String> scriptName = frame->GetScriptName();
    132         frameObject->setString("scriptName", scriptName.IsEmpty() ? "" : toWebCoreString(scriptName));
    133         v8::Local<v8::String> functionName = frame->GetFunctionName();
    134         frameObject->setString("functionName", functionName.IsEmpty() ? "" : toWebCoreString(functionName));
    135         frameObject->setNumber("lineNumber", frame->GetLineNumber());
    136         frameObject->setNumber("column", frame->GetColumn());
    137         stackTrace->pushObject(frameObject);
    138     }
    139     return true;
    140 #else
    141     return false;
    142 #endif
    143 }
    144 
    145106} // namespace WebCore
  • trunk/WebCore/bindings/v8/ScriptCallStackFactory.h

    r72895 r73351  
    4747    | v8::StackTrace::kFunctionName);
    4848
    49 PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Local<v8::Context>, v8::Handle<v8::StackTrace>, size_t maxStackSize);
     49PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace>, size_t maxStackSize);
    5050PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize);
    5151PassRefPtr<ScriptArguments> createScriptArguments(const v8::Arguments& v8arguments, unsigned skipArgumentCount);
  • trunk/WebCore/bindings/v8/V8ConsoleMessage.cpp

    r72895 r73351  
    118118    // Currently stack trace is only collected when inspector is open.
    119119    if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) {
    120         v8::Local<v8::Context> context = v8::Context::GetEntered();
    121         callStack = createScriptCallStack(context, stackTrace, ScriptCallStack::maxCallStackSizeToCapture);
     120        callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture);
    122121    }
    123122
  • trunk/WebCore/inspector/ScriptCallFrame.cpp

    r71981 r73351  
    3737namespace WebCore {
    3838
    39 ScriptCallFrame::ScriptCallFrame(const String& functionName, const String& urlString, unsigned lineNumber)
     39ScriptCallFrame::ScriptCallFrame(const String& functionName, const String& scriptName, unsigned lineNumber, unsigned column)
    4040    : m_functionName(functionName)
    41     , m_sourceURL(urlString)
     41    , m_scriptName(scriptName)
    4242    , m_lineNumber(lineNumber)
     43    , m_column(column)
    4344{
    4445}
     
    5152{
    5253    return m_functionName == o.m_functionName
    53         && m_sourceURL == o.m_sourceURL
     54        && m_scriptName == o.m_scriptName
    5455        && m_lineNumber == o.m_lineNumber;
    5556}
     
    6061    RefPtr<InspectorObject> frame = InspectorObject::create();
    6162    frame->setString("functionName", m_functionName);
    62     frame->setString("sourceURL", m_sourceURL);
     63    frame->setString("scriptName", m_scriptName);
    6364    frame->setNumber("lineNumber", m_lineNumber);
     65    frame->setNumber("column", m_column);
    6466    return frame;
    6567}
  • trunk/WebCore/inspector/ScriptCallFrame.h

    r72895 r73351  
    4141class ScriptCallFrame  {
    4242public:
    43     ScriptCallFrame(const String& functionName, const String& urlString, unsigned lineNumber);
     43    ScriptCallFrame(const String& functionName, const String& scriptName, unsigned lineNumber, unsigned column = 0);
    4444    ~ScriptCallFrame();
    4545
    4646    const String& functionName() const { return m_functionName; }
    47     const String& sourceURL() const { return m_sourceURL; }
     47    const String& sourceURL() const { return m_scriptName; }
    4848    unsigned lineNumber() const { return m_lineNumber; }
    4949
     
    5353private:
    5454    String m_functionName;
    55     String m_sourceURL;
     55    String m_scriptName;
    5656    unsigned m_lineNumber;
     57    unsigned m_column;
    5758};
    5859
  • trunk/WebCore/inspector/ScriptCallStack.h

    r72895 r73351  
    5151    const ScriptCallFrame &at(size_t) const;
    5252    size_t size() const;
    53     static bool stackTrace(int, const RefPtr<InspectorArray>&);
    5453
    5554    bool isEqual(ScriptCallStack*) const;
  • trunk/WebCore/inspector/TimelineRecordFactory.cpp

    r66098 r73351  
    4040#include "ResourceResponse.h"
    4141#include "ScriptCallStack.h"
     42#include "ScriptCallStackFactory.h"
    4243
    4344namespace WebCore {
     
    4849    record->setNumber("startTime", startTime);
    4950
    50     RefPtr<InspectorArray> stackTrace = InspectorArray::create();
    51     if (ScriptCallStack::stackTrace(5, stackTrace))
    52         record->setArray("stackTrace", stackTrace);
     51    RefPtr<ScriptCallStack> stackTrace = createScriptCallStack(5);
     52    if (stackTrace && stackTrace->size())
     53        record->setArray("stackTrace", stackTrace->buildInspectorObject());
    5354    return record.release();
    5455}
  • trunk/WebCore/inspector/front-end/ConsoleView.js

    r71413 r73351  
    864864            content.appendChild(messageTextElement);
    865865
    866             var urlElement = WebInspector.linkifyResourceAsNode(frame.sourceURL, "scripts", frame.lineNumber, "console-message-url");
     866            var urlElement = WebInspector.linkifyResourceAsNode(frame.scriptName, "scripts", frame.lineNumber, "console-message-url");
    867867            content.appendChild(urlElement);
    868868
Note: See TracChangeset for help on using the changeset viewer.