Skip to content

Commit

Permalink
Include promise status in heap snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
190n committed Jan 3, 2025
1 parent 248e65e commit 78cdd9b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ unsigned BunV8HeapSnapshotBuilder::getNodeTypeIndex(JSCell* cell)
return static_cast<unsigned>(V8NodeType::Native);
}

String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell)
String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell, bool recurse)
{
if (!cell)
return "(root)"_s;
Expand Down Expand Up @@ -420,7 +420,21 @@ String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell)
}

if (JSPromise* promise = jsDynamicCast<JSPromise*>(cell)) {
return "Promise"_s;
auto& vm = promise->globalObject()->vm();
switch (promise->status(vm)) {
case JSPromise::Status::Pending:
return "Promise (pending)"_s;
case JSPromise::Status::Fulfilled: {
JSValue result = promise->result(vm);
if (result.isCell() && recurse) {
// set recurse to false to make sure we don't infinitely expand promises
return makeString("Promise (fulfilled: "_s, getDetailedNodeType(result.asCell(), false), ")"_s);
}
return "Promise (fulfilled)"_s;
}
case JSPromise::Status::Rejected:
return "Promise (rejected)"_s;
}
}

auto* object = cell->getObject();
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class JS_EXPORT_PRIVATE BunV8HeapSnapshotBuilder final : public HeapAnalyzer {
unsigned getEdgeTypeIndex(const String& type);
unsigned addString(const String&);
void initializeTypeNames();
String getDetailedNodeType(JSCell*);
String getDetailedNodeType(JSCell*, bool recurse = true);
std::optional<TraceLocation> getTraceLocation(JSCell*);
};

Expand Down

0 comments on commit 78cdd9b

Please sign in to comment.