Restoring use of StackIterator instead of Interpreter::getStacktrace().
https://bugs.webkit.org/show_bug.cgi?id=119575.
Reviewed by Oliver Hunt.
Source/JavaScriptCore:
* interpreter/Interpreter.h:
- Made getStackTrace() private.
* interpreter/StackIterator.cpp:
(JSC::StackIterator::StackIterator):
(JSC::StackIterator::numberOfFrames):
- Computes the number of frames by iterating through the whole stack
from the starting frame. The iterator will save its current frame
position before counting the frames, and then restoring it after
the counting.
(JSC::StackIterator::gotoFrameAtIndex):
(JSC::StackIterator::gotoNextFrame):
(JSC::StackIterator::resetIterator):
- Points the iterator to the starting frame.
* interpreter/StackIteratorPrivate.h:
Source/WebCore:
No new tests.
* bindings/js/ScriptCallStackFactory.cpp:
(WebCore::createScriptCallStack):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153825 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index ca18d85..01766f3 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,5 +1,27 @@
2013-08-08 Mark Lam <mark.lam@apple.com>
+ Restoring use of StackIterator instead of Interpreter::getStacktrace().
+ https://bugs.webkit.org/show_bug.cgi?id=119575.
+
+ Reviewed by Oliver Hunt.
+
+ * interpreter/Interpreter.h:
+ - Made getStackTrace() private.
+ * interpreter/StackIterator.cpp:
+ (JSC::StackIterator::StackIterator):
+ (JSC::StackIterator::numberOfFrames):
+ - Computes the number of frames by iterating through the whole stack
+ from the starting frame. The iterator will save its current frame
+ position before counting the frames, and then restoring it after
+ the counting.
+ (JSC::StackIterator::gotoFrameAtIndex):
+ (JSC::StackIterator::gotoNextFrame):
+ (JSC::StackIterator::resetIterator):
+ - Points the iterator to the starting frame.
+ * interpreter/StackIteratorPrivate.h:
+
+2013-08-08 Mark Lam <mark.lam@apple.com>
+
Moved ErrorConstructor and NativeErrorConstructor helper functions into
the Interpreter class.
https://bugs.webkit.org/show_bug.cgi?id=119576.
diff --git a/Source/JavaScriptCore/interpreter/Interpreter.h b/Source/JavaScriptCore/interpreter/Interpreter.h
index abdf4e6..83327ab 100644
--- a/Source/JavaScriptCore/interpreter/Interpreter.h
+++ b/Source/JavaScriptCore/interpreter/Interpreter.h
@@ -233,8 +233,6 @@
JS_EXPORT_PRIVATE void dumpCallFrame(CallFrame*);
- JS_EXPORT_PRIVATE void getStackTrace(Vector<StackFrame>& results, size_t maxStackSize = std::numeric_limits<size_t>::max());
-
private:
enum ExecutionFlag { Normal, InitializeAndReturn };
@@ -242,6 +240,7 @@
void endRepeatCall(CallFrameClosure&);
JSValue execute(CallFrameClosure&);
+ void getStackTrace(Vector<StackFrame>& results, size_t maxStackSize = std::numeric_limits<size_t>::max());
NEVER_INLINE bool unwindCallFrame(StackIterator&, JSValue);
void dumpRegisters(CallFrame*);
diff --git a/Source/JavaScriptCore/interpreter/StackIterator.cpp b/Source/JavaScriptCore/interpreter/StackIterator.cpp
index 72c5210..9d8490e 100644
--- a/Source/JavaScriptCore/interpreter/StackIterator.cpp
+++ b/Source/JavaScriptCore/interpreter/StackIterator.cpp
@@ -34,12 +34,32 @@
namespace JSC {
-StackIterator::StackIterator(CallFrame* frame, StackIterator::FrameFilter filter)
- : m_filter(filter)
+StackIterator::StackIterator(CallFrame* startFrame, StackIterator::FrameFilter filter)
+ : m_startFrame(startFrame)
+ , m_filter(filter)
{
- ASSERT(frame);
- m_frame = Frame::create(frame);
- m_frame = m_frame->logicalFrame();
+ ASSERT(startFrame);
+ resetIterator();
+}
+
+size_t StackIterator::numberOfFrames()
+{
+ int savedFrameIndex = m_frameIndex;
+ resetIterator();
+ while (m_frame)
+ gotoNextFrame();
+ size_t numberOfFrames = m_frameIndex;
+
+ resetIterator();
+ gotoFrameAtIndex(savedFrameIndex);
+
+ return numberOfFrames;
+}
+
+void StackIterator::gotoFrameAtIndex(size_t index)
+{
+ while (m_frame && (m_frameIndex != index))
+ gotoNextFrame();
}
void StackIterator::gotoNextFrame()
@@ -51,6 +71,14 @@
break;
}
m_frame = frame;
+ m_frameIndex++;
+}
+
+void StackIterator::resetIterator()
+{
+ m_frameIndex = 0;
+ m_frame = Frame::create(m_startFrame);
+ m_frame = m_frame->logicalFrame();
}
void StackIterator::find(JSFunction* functionObj)
diff --git a/Source/JavaScriptCore/interpreter/StackIteratorPrivate.h b/Source/JavaScriptCore/interpreter/StackIteratorPrivate.h
index 3f9f32f..401655a 100644
--- a/Source/JavaScriptCore/interpreter/StackIteratorPrivate.h
+++ b/Source/JavaScriptCore/interpreter/StackIteratorPrivate.h
@@ -39,6 +39,8 @@
class Frame;
typedef bool (*FrameFilter)(Frame*);
+ JS_EXPORT_PRIVATE size_t numberOfFrames();
+
Frame& operator*() { return *m_frame; }
ALWAYS_INLINE Frame* operator->() { return m_frame; }
@@ -51,8 +53,12 @@
JS_EXPORT_PRIVATE StackIterator(CallFrame* startFrame, FrameFilter = 0);
static Frame* end() { return 0; }
+ void gotoFrameAtIndex(size_t frameIndex);
JS_EXPORT_PRIVATE void gotoNextFrame();
+ void resetIterator();
+ CallFrame* m_startFrame;
+ size_t m_frameIndex;
Frame* m_frame;
FrameFilter m_filter;
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 9a66aba..def0daa 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,15 @@
+2013-08-08 Mark Lam <mark.lam@apple.com>
+
+ Restoring use of StackIterator instead of Interpreter::getStacktrace().
+ https://bugs.webkit.org/show_bug.cgi?id=119575.
+
+ Reviewed by Oliver Hunt.
+
+ No new tests.
+
+ * bindings/js/ScriptCallStackFactory.cpp:
+ (WebCore::createScriptCallStack):
+
2013-08-08 Zalan Bujtas <zalan@apple.com>
REGRESSION (r121551) Incorrect handling of invalid media query list.
diff --git a/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp
index 8be3604..ae4741d 100644
--- a/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp
+++ b/Source/WebCore/bindings/js/ScriptCallStackFactory.cpp
@@ -78,22 +78,22 @@
PassRefPtr<ScriptCallStack> createScriptCallStack(JSC::ExecState* exec, size_t maxStackSize)
{
Vector<ScriptCallFrame> frames;
- Vector<StackFrame> stackTrace;
- exec->vm().interpreter->getStackTrace(stackTrace, maxStackSize + 1);
- for (size_t i = stackTrace.size() == 1 ? 0 : 1; i < stackTrace.size(); i++) {
+ 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 (!stackTrace[i].callee && frames.size())
+ if (!iter->callee() && frames.size())
break;
-
- String functionName = stackTrace[i].friendlyFunctionName(exec);
unsigned line;
unsigned column;
- stackTrace[i].computeLineAndColumn(line, column);
- frames.append(ScriptCallFrame(functionName, stackTrace[i].sourceURL, line, column));
+ iter->computeLineAndColumn(line, column);
+ frames.append(ScriptCallFrame(iter->functionName(), iter->sourceURL(), line, column));
}
-
return ScriptCallStack::create(frames);
}