Changeset 155013 in webkit for trunk/Source/JavaScriptCore/API


Ignore:
Timestamp:
Sep 3, 2013, 5:26:57 PM (12 years ago)
Author:
[email protected]
Message:

Converting StackIterator to a callback interface.
https://bugs.webkit.org/show_bug.cgi?id=120564.

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

  • API/JSContextRef.cpp:

(BacktraceFunctor::BacktraceFunctor):
(BacktraceFunctor::operator()):
(JSContextCreateBacktrace):

  • interpreter/CallFrame.cpp:
  • interpreter/CallFrame.h:
  • interpreter/Interpreter.cpp:

(JSC::DumpRegisterFunctor::DumpRegisterFunctor):
(JSC::DumpRegisterFunctor::operator()):
(JSC::Interpreter::dumpRegisters):
(JSC::unwindCallFrame):
(JSC::GetStackTraceFunctor::GetStackTraceFunctor):
(JSC::GetStackTraceFunctor::operator()):
(JSC::Interpreter::getStackTrace):
(JSC::Interpreter::stackTraceAsString):
(JSC::UnwindFunctor::UnwindFunctor):
(JSC::UnwindFunctor::operator()):
(JSC::Interpreter::unwind):

  • interpreter/Interpreter.h:
  • interpreter/StackIterator.cpp:

(JSC::StackIterator::numberOfFrames):
(JSC::StackIterator::gotoFrameAtIndex):
(JSC::StackIterator::gotoNextFrameWithFilter):
(JSC::StackIterator::resetIterator):
(JSC::StackIterator::Frame::print):
(debugPrintCallFrame):
(DebugPrintStackFunctor::operator()):
(debugPrintStack): Added for debugging convenience.

  • interpreter/StackIterator.h:

(JSC::StackIterator::Frame::index):
(JSC::StackIterator::iterate):

  • jsc.cpp:

(FunctionJSCStackFunctor::FunctionJSCStackFunctor):
(FunctionJSCStackFunctor::operator()):
(functionJSCStack):

  • profiler/ProfileGenerator.cpp:

(JSC::AddParentForConsoleStartFunctor::AddParentForConsoleStartFunctor):
(JSC::AddParentForConsoleStartFunctor::foundParent):
(JSC::AddParentForConsoleStartFunctor::operator()):
(JSC::ProfileGenerator::addParentForConsoleStart):

  • runtime/JSFunction.cpp:

(JSC::RetrieveArgumentsFunctor::RetrieveArgumentsFunctor):
(JSC::RetrieveArgumentsFunctor::result):
(JSC::RetrieveArgumentsFunctor::operator()):
(JSC::retrieveArguments):
(JSC::RetrieveCallerFunctionFunctor::RetrieveCallerFunctionFunctor):
(JSC::RetrieveCallerFunctionFunctor::result):
(JSC::RetrieveCallerFunctionFunctor::operator()):
(JSC::retrieveCallerFunction):

  • runtime/JSGlobalObjectFunctions.cpp:

(JSC::GlobalFuncProtoGetterFunctor::GlobalFuncProtoGetterFunctor):
(JSC::GlobalFuncProtoGetterFunctor::result):
(JSC::GlobalFuncProtoGetterFunctor::operator()):
(JSC::globalFuncProtoGetter):
(JSC::GlobalFuncProtoSetterFunctor::GlobalFuncProtoSetterFunctor):
(JSC::GlobalFuncProtoSetterFunctor::allowsAccess):
(JSC::GlobalFuncProtoSetterFunctor::operator()):
(JSC::globalFuncProtoSetter):

  • runtime/ObjectConstructor.cpp:

(JSC::ObjectConstructorGetPrototypeOfFunctor::ObjectConstructorGetPrototypeOfFunctor):
(JSC::ObjectConstructorGetPrototypeOfFunctor::result):
(JSC::ObjectConstructorGetPrototypeOfFunctor::operator()):
(JSC::objectConstructorGetPrototypeOf):

Source/WebCore:

No new tests.

  • bindings/js/JSXMLHttpRequestCustom.cpp:

(WebCore::SendFunctor::SendFunctor):
(WebCore::SendFunctor::hasViableFrame):
(WebCore::SendFunctor::operator()):
(WebCore::JSXMLHttpRequest::send):

  • bindings/js/ScriptCallStackFactory.cpp:

(WebCore::CreateScriptCallStackFunctor::CreateScriptCallStackFunctor):
(WebCore::CreateScriptCallStackFunctor::operator()):
(WebCore::createScriptCallStack):
(WebCore::CreateScriptCallStackForConsoleFunctor::CreateScriptCallStackForConsoleFunctor):
(WebCore::CreateScriptCallStackForConsoleFunctor::operator()):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSContextRef.cpp

    r153218 r155013  
    213213    return toGlobalRef(exec->lexicalGlobalObject()->globalExec());
    214214}
    215    
     215
     216class BacktraceFunctor {
     217public:
     218    BacktraceFunctor(StringBuilder& builder, unsigned remainingCapacityForFrameCapture)
     219        : m_builder(builder)
     220        , m_remainingCapacityForFrameCapture(remainingCapacityForFrameCapture)
     221    {
     222    }
     223
     224    StackIterator::Status operator()(StackIterator& iter)
     225    {
     226        if (m_remainingCapacityForFrameCapture) {
     227            // If callee is unknown, but we've not added any frame yet, we should
     228            // still add the frame, because something called us, and gave us arguments.
     229            JSObject* callee = iter->callee();
     230            if (!callee && iter->index())
     231                return StackIterator::Done;
     232
     233            StringBuilder& builder = m_builder;
     234            if (!builder.isEmpty())
     235                builder.append('\n');
     236            builder.append('#');
     237            builder.appendNumber(iter->index());
     238            builder.append(' ');
     239            builder.append(iter->functionName());
     240            builder.appendLiteral("() at ");
     241            builder.append(iter->sourceURL());
     242            if (iter->isJSFrame()) {
     243                builder.append(':');
     244                unsigned lineNumber;
     245                unsigned unusedColumn;
     246                iter->computeLineAndColumn(lineNumber, unusedColumn);
     247                builder.appendNumber(lineNumber);
     248            }
     249
     250            if (!callee)
     251                return StackIterator::Done;
     252
     253            m_remainingCapacityForFrameCapture--;
     254            return StackIterator::Continue;
     255        }
     256        return StackIterator::Done;
     257    }
     258
     259private:
     260    StringBuilder& m_builder;
     261    unsigned m_remainingCapacityForFrameCapture;
     262};
     263
    216264JSStringRef JSContextCreateBacktrace(JSContextRef ctx, unsigned maxStackSize)
    217265{
     
    224272    StringBuilder builder;
    225273    CallFrame* frame = exec->vm().topCallFrame;
    226     size_t i = 0;
     274
    227275    ASSERT(maxStackSize);
    228     for (StackIterator iter = frame->begin(); iter != frame->end() && maxStackSize--; ++iter, ++i) {
    229         JSObject* callee = iter->callee();
    230         // If callee is unknown, but we've not added any frame yet, we should
    231         // still add the frame, because something called us, and gave us arguments.
    232         if (!callee && i)
    233             break;
    234 
    235         if (!builder.isEmpty())
    236             builder.append('\n');
    237         builder.append('#');
    238         builder.appendNumber(i);
    239         builder.append(' ');
    240         builder.append(iter->functionName());
    241         builder.appendLiteral("() at ");
    242         builder.append(iter->sourceURL());
    243         if (iter->isJSFrame()) {
    244             builder.append(':');
    245             unsigned lineNumber;
    246             unsigned unusedColumn;
    247             iter->computeLineAndColumn(lineNumber, unusedColumn);
    248             builder.appendNumber(lineNumber);
    249         }
    250 
    251         if (!callee)
    252             break;
    253     }
     276    BacktraceFunctor functor(builder, maxStackSize);
     277    StackIterator iter = frame->begin();
     278    iter.iterate(functor);
    254279
    255280    return OpaqueJSString::create(builder.toString()).leakRef();
Note: See TracChangeset for help on using the changeset viewer.