PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)
{
    Vector<ScriptCallFrame> frames;
    ASSERT(exec);
    CallFrame* frame = exec->vm().topCallFrame;
    StackIterator iter = frame->begin();
    if (iter.numberOfFrames() > 1)
        ++iter;
    for (; iter != frame->end() && maxStackSize--; ++iter) {
        // This early exit is necessary to maintain our old behaviour
        // but the stack trace we produce now is complete and handles all
        // ways in which code may be running
        if (!iter->callee() && frames.size())
            break;
        unsigned line;
        unsigned column;
        iter->computeLineAndColumn(line, column);
        frames.append(ScriptCallFrame(iter->functionName(), iter->sourceURL(), line, column));
    }
    return ScriptCallStack::create(frames);
}