Changeset 121359 in webkit


Ignore:
Timestamp:
Jun 27, 2012 12:54:48 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
https://bugs.webkit.org/show_bug.cgi?id=40118

Patch by Anthony Scian <ascian@rim.com> on 2012-06-27
Reviewed by Yong Li.

Source/JavaScriptCore:

Added member functions to expose function name, urlString, and line #.
Refactored toString to make use of these member functions to reduce
duplicated code for future maintenance.

Manually tested refactoring of toString by tracing thrown exceptions.

  • interpreter/Interpreter.h:

(StackFrame):
(JSC::StackFrame::toString):
(JSC::StackFrame::friendlySourceURL):
(JSC::StackFrame::friendlyFunctionName):
(JSC::StackFrame::friendlyLineNumber):

Source/WebCore:

Implemented stub for createScriptCallStack to call into
Interpreter and extract the current stack frames, iterate
through the frames and create the return result required.

No new tests, manually tested thrown exception and inspector
tracebacks.

  • bindings/js/ScriptCallStackFactory.cpp:

(WebCore::createScriptCallStack):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r121338 r121359  
     12012-06-27  Anthony Scian  <ascian@rim.com>
     2
     3        Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
     4        https://bugs.webkit.org/show_bug.cgi?id=40118
     5
     6        Reviewed by Yong Li.
     7
     8        Added member functions to expose function name, urlString, and line #.
     9        Refactored toString to make use of these member functions to reduce
     10        duplicated code for future maintenance.
     11
     12        Manually tested refactoring of toString by tracing thrown exceptions.
     13
     14        * interpreter/Interpreter.h:
     15        (StackFrame):
     16        (JSC::StackFrame::toString):
     17        (JSC::StackFrame::friendlySourceURL):
     18        (JSC::StackFrame::friendlyFunctionName):
     19        (JSC::StackFrame::friendlyLineNumber):
     20
    1212012-06-27  Oswald Buddenhagen  <oswald.buddenhagen@nokia.com>
    222
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.h

    r115861 r121359  
    11/*
    22 * Copyright (C) 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4041
    4142#include <wtf/HashMap.h>
     43#include <wtf/text/StringBuilder.h>
    4244
    4345namespace JSC {
     
    8183        UString toString(CallFrame* callFrame) const
    8284        {
    83             bool hasSourceURLInfo = !sourceURL.isNull() && !sourceURL.isEmpty();
    84             bool hasLineInfo = line > -1;
     85            StringBuilder traceBuild;
     86            String functionName = friendlyFunctionName(callFrame);
     87            String sourceURL = friendlySourceURL();
     88            traceBuild.append(functionName);
     89            if (!functionName.isEmpty() && !sourceURL.isEmpty())
     90                traceBuild.append('@');
     91            traceBuild.append(sourceURL);
     92            if (line > -1) {
     93                traceBuild.append(':');
     94                traceBuild.append(String::number(line));
     95            }
     96            return traceBuild.toString().impl();
     97        }
     98        String friendlySourceURL() const
     99        {
     100            String traceLine;
     101
     102            switch (codeType) {
     103            case StackFrameEvalCode:
     104            case StackFrameFunctionCode:
     105            case StackFrameGlobalCode:
     106                if (!sourceURL.isEmpty())
     107                    traceLine = sourceURL.impl();
     108                break;
     109            case StackFrameNativeCode:
     110                traceLine = "[native code]";
     111                break;
     112            }
     113            return traceLine.isNull() ? emptyString() : traceLine;
     114        }
     115        String friendlyFunctionName(CallFrame* callFrame) const
     116        {
    85117            String traceLine;
    86118            JSObject* stackFrameCallee = callee.get();
     
    88120            switch (codeType) {
    89121            case StackFrameEvalCode:
    90                 if (hasSourceURLInfo) {
    91                     traceLine = hasLineInfo ? String::format("eval code@%s:%d", sourceURL.ascii().data(), line)
    92                                             : String::format("eval code@%s", sourceURL.ascii().data());
    93                 } else
    94                     traceLine = String::format("eval code");
    95                 break;
    96             case StackFrameNativeCode: {
    97                 if (callee) {
    98                     UString functionName = getCalculatedDisplayName(callFrame, stackFrameCallee);
    99                     traceLine = String::format("%s@[native code]", functionName.ascii().data());
    100                 } else
    101                     traceLine = "[native code]";
     122                traceLine = "eval code";
     123                break;
     124            case StackFrameNativeCode:
     125                if (callee)
     126                    traceLine = getCalculatedDisplayName(callFrame, stackFrameCallee).impl();
     127                break;
     128            case StackFrameFunctionCode:
     129                traceLine = getCalculatedDisplayName(callFrame, stackFrameCallee).impl();
     130                break;
     131            case StackFrameGlobalCode:
     132                traceLine = "global code";
    102133                break;
    103134            }
    104             case StackFrameFunctionCode: {
    105                 UString functionName = getCalculatedDisplayName(callFrame, stackFrameCallee);
    106                 if (hasSourceURLInfo) {
    107                     traceLine = hasLineInfo ? String::format("%s@%s:%d", functionName.ascii().data(), sourceURL.ascii().data(), line)
    108                                             : String::format("%s@%s", functionName.ascii().data(), sourceURL.ascii().data());
    109                 } else
    110                     traceLine = String::format("%s\n", functionName.ascii().data());
    111                 break;
    112             }
    113             case StackFrameGlobalCode:
    114                 if (hasSourceURLInfo) {
    115                     traceLine = hasLineInfo ? String::format("global code@%s:%d", sourceURL.ascii().data(), line)
    116                                             : String::format("global code@%s", sourceURL.ascii().data());
    117                 } else
    118                     traceLine = String::format("global code");
    119                    
    120             }
    121             return traceLine.impl();
     135            return traceLine.isNull() ? emptyString() : traceLine;
     136        }
     137        unsigned friendlyLineNumber() const
     138        {
     139            return line > -1 ? line : 0;
    122140        }
    123141    };
  • trunk/Source/WebCore/ChangeLog

    r121358 r121359  
     12012-06-27  Anthony Scian  <ascian@rim.com>
     2
     3        Web Inspector [JSC]: Implement ScriptCallStack::stackTrace
     4        https://bugs.webkit.org/show_bug.cgi?id=40118
     5
     6        Reviewed by Yong Li.
     7
     8        Implemented stub for createScriptCallStack to call into
     9        Interpreter and extract the current stack frames, iterate
     10        through the frames and create the return result required.
     11
     12        No new tests, manually tested thrown exception and inspector
     13        tracebacks.
     14
     15        * bindings/js/ScriptCallStackFactory.cpp:
     16        (WebCore::createScriptCallStack):
     17
    1182012-06-27  Ryosuke Niwa  <rniwa@webkit.org>
    219
  • trunk/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp

    r113387 r121359  
    11/*
    22 * Copyright (c) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435#include "InspectorInstrumentation.h"
    3536#include "JSDOMBinding.h"
     37#include "JSMainThreadExecState.h"
    3638#include "ScriptArguments.h"
    3739#include "ScriptCallFrame.h"
     
    5254class ScriptExecutionContext;
    5355
    54 PassRefPtr<ScriptCallStack> createScriptCallStack(size_t, bool)
     56PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool emptyIsAllowed)
    5557{
    56     return 0;
     58    Vector<ScriptCallFrame> frames;
     59    if (JSC::ExecState* exec = JSMainThreadExecState::currentState()) {
     60        Vector<StackFrame> stackTrace;
     61        Interpreter::getStackTrace(&exec->globalData(), stackTrace);
     62        for (Vector<StackFrame>::const_iterator iter = stackTrace.begin(); iter < stackTrace.end(); iter++) {
     63            StackFrame level = *iter;
     64            frames.append(ScriptCallFrame(level.friendlyFunctionName(exec), level.friendlySourceURL(), level.friendlyLineNumber()));
     65            if (frames.size() >= maxStackSize)
     66                break;
     67        }
     68    }
     69    if (frames.isEmpty() && !emptyIsAllowed) {
     70        // No frames found. It may happen in the case where
     71        // a bound function is called from native code for example.
     72        // Fallback to setting lineNumber to 0, and source and function name to "undefined".
     73        frames.append(ScriptCallFrame("undefined", "undefined", 0));
     74    }
     75    return ScriptCallStack::create(frames);
    5776}
    5877
Note: See TracChangeset for help on using the changeset viewer.