diff --git a/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.cpp b/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.cpp index 5d31b891bee31..a62299a52057b 100644 --- a/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.cpp +++ b/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.cpp @@ -354,7 +354,7 @@ unsigned BunV8HeapSnapshotBuilder::getNodeTypeIndex(JSCell* cell) return static_cast(V8NodeType::Native); } -String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell) +String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell, bool recurse) { if (!cell) return "(root)"_s; @@ -420,7 +420,21 @@ String BunV8HeapSnapshotBuilder::getDetailedNodeType(JSCell* cell) } if (JSPromise* promise = jsDynamicCast(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(); diff --git a/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.h b/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.h index 6f5e4095ee6b1..bfba6c92bd671 100644 --- a/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.h +++ b/Source/JavaScriptCore/heap/BunV8HeapSnapshotBuilder.h @@ -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 getTraceLocation(JSCell*); };