Skip to content

Commit

Permalink
Stop using Vector::unsafeAppendWithoutCapacityCheck() in GetStackTrac…
Browse files Browse the repository at this point in the history
…eFunctor

https://bugs.webkit.org/show_bug.cgi?id=265159

Reviewed by Darin Adler.

* Source/JavaScriptCore/interpreter/Interpreter.cpp:
(JSC::GetStackTraceFunctor::GetStackTraceFunctor):
(JSC::GetStackTraceFunctor::operator() const):
(JSC::GetStackTraceFunctor::frameCountInResults const):
(JSC::Interpreter::getStackTrace):
* Source/JavaScriptCore/runtime/StackFrame.h:

Canonical link: https://commits.webkit.org/271147@main
  • Loading branch information
cdumez committed Nov 27, 2023
1 parent c95abf8 commit 7ed7ab6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
22 changes: 11 additions & 11 deletions Source/JavaScriptCore/interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class GetStackTraceFunctor {
, m_results(results)
, m_framesToSkip(framesToSkip)
{
m_results.reserveInitialCapacity(capacity);
m_results.grow(capacity);
}

IterationStatus operator()(StackVisitor& visitor) const
Expand All @@ -418,34 +418,34 @@ class GetStackTraceFunctor {
if (visitor->isImplementationVisibilityPrivate())
return IterationStatus::Continue;

if (m_results.size() < m_results.capacity()) {
if (m_frameCountInResults < m_results.size()) {
if (visitor->isNativeCalleeFrame()) {
auto* nativeCallee = visitor->callee().asNativeCallee();
switch (nativeCallee->category()) {
case NativeCallee::Category::Wasm: {
m_results.unsafeAppendWithoutCapacityCheck(StackFrame(visitor->wasmFunctionIndexOrName()));
m_results[m_frameCountInResults++] = StackFrame(visitor->wasmFunctionIndexOrName());
break;
}
case NativeCallee::Category::InlineCache: {
break;
}
}
} else if (!!visitor->codeBlock() && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction()) {
m_results.unsafeAppendWithoutCapacityCheck(
StackFrame(m_vm, m_owner, visitor->callee().asCell(), visitor->codeBlock(), visitor->bytecodeIndex()));
} else {
m_results.unsafeAppendWithoutCapacityCheck(
StackFrame(m_vm, m_owner, visitor->callee().asCell()));
}
} else if (!!visitor->codeBlock() && !visitor->codeBlock()->unlinkedCodeBlock()->isBuiltinFunction())
m_results[m_frameCountInResults++] = StackFrame(m_vm, m_owner, visitor->callee().asCell(), visitor->codeBlock(), visitor->bytecodeIndex());
else
m_results[m_frameCountInResults++] = StackFrame(m_vm, m_owner, visitor->callee().asCell());
return IterationStatus::Continue;
}
return IterationStatus::Done;
}

size_t frameCountInResults() const { return m_frameCountInResults; }

private:
VM& m_vm;
JSCell* m_owner;
Vector<StackFrame>& m_results;
mutable size_t m_frameCountInResults { 0 };
mutable size_t m_framesToSkip;
};

Expand Down Expand Up @@ -486,7 +486,7 @@ void Interpreter::getStackTrace(JSCell* owner, Vector<StackFrame>& results, size

GetStackTraceFunctor functor(vm, owner, results, skippedFrames, visitedFrames);
StackVisitor::visit(callFrame, vm, functor);
ASSERT(results.size() == results.capacity());
ASSERT(functor.frameCountInResults() == results.size());
}

String Interpreter::stackTraceAsString(VM& vm, const Vector<StackFrame>& stackTrace)
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/StackFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class StackFrame {
StackFrame(VM&, JSCell* owner, JSCell* callee);
StackFrame(VM&, JSCell* owner, JSCell* callee, CodeBlock*, BytecodeIndex);
StackFrame(Wasm::IndexOrName);
StackFrame() = default;

bool hasLineAndColumnInfo() const { return !!m_codeBlock; }
CodeBlock* codeBlock() const { return m_codeBlock.get(); }
Expand Down

0 comments on commit 7ed7ab6

Please sign in to comment.