diff --git a/Libraries/WebPerformance/NativePerformanceObserver.cpp b/Libraries/WebPerformance/NativePerformanceObserver.cpp index 506cbbe5834..471c373f3f9 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.cpp +++ b/Libraries/WebPerformance/NativePerformanceObserver.cpp @@ -39,11 +39,16 @@ void NativePerformanceObserver::stopReporting( reporter_->stopReporting(stringToPerformanceEntryType(entryType)); } -std::vector NativePerformanceObserver::getPendingEntries( +std::vector NativePerformanceObserver::popPendingEntries( jsi::Runtime &rt) { return reporter_->popPendingEntries(); } +std::vector NativePerformanceObserver::getPendingEntries( + jsi::Runtime &rt) { + return reporter_->getPendingEntries(); +} + void NativePerformanceObserver::setOnPerformanceEntryCallback( jsi::Runtime &rt, std::optional> callback) { diff --git a/Libraries/WebPerformance/NativePerformanceObserver.h b/Libraries/WebPerformance/NativePerformanceObserver.h index 4c47fe2d1be..7ef2ed61437 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.h +++ b/Libraries/WebPerformance/NativePerformanceObserver.h @@ -53,6 +53,7 @@ class NativePerformanceObserver void stopReporting(jsi::Runtime &rt, std::string entryType); + std::vector popPendingEntries(jsi::Runtime &rt); std::vector getPendingEntries(jsi::Runtime &rt); void setOnPerformanceEntryCallback( diff --git a/Libraries/WebPerformance/NativePerformanceObserver.js b/Libraries/WebPerformance/NativePerformanceObserver.js index c74502eb80a..a5595f4035b 100644 --- a/Libraries/WebPerformance/NativePerformanceObserver.js +++ b/Libraries/WebPerformance/NativePerformanceObserver.js @@ -34,6 +34,7 @@ export interface Spec extends TurboModule { +startReporting: (entryType: string) => void; +stopReporting: (entryType: string) => void; +getPendingEntries: () => $ReadOnlyArray; + +popPendingEntries?: () => $ReadOnlyArray; +setOnPerformanceEntryCallback: (callback?: () => void) => void; // NOTE: this is for dev-only purposes (potentially is going to be moved elsewhere) diff --git a/Libraries/WebPerformance/PerformanceEntryReporter.cpp b/Libraries/WebPerformance/PerformanceEntryReporter.cpp index ee1eb490057..27968593ffe 100644 --- a/Libraries/WebPerformance/PerformanceEntryReporter.cpp +++ b/Libraries/WebPerformance/PerformanceEntryReporter.cpp @@ -23,8 +23,8 @@ void PerformanceEntryReporter::stopReporting(PerformanceEntryType entryType) { reportingType_[static_cast(entryType)] = false; } -std::vector PerformanceEntryReporter::getPendingEntries() - const { +const std::vector + &PerformanceEntryReporter::getPendingEntries() const { return entries_; } diff --git a/Libraries/WebPerformance/PerformanceEntryReporter.h b/Libraries/WebPerformance/PerformanceEntryReporter.h index a54362c56d8..05cf8363727 100644 --- a/Libraries/WebPerformance/PerformanceEntryReporter.h +++ b/Libraries/WebPerformance/PerformanceEntryReporter.h @@ -26,7 +26,7 @@ class PerformanceEntryReporter { void startReporting(PerformanceEntryType entryType); void stopReporting(PerformanceEntryType entryType); - std::vector getPendingEntries() const; + const std::vector &getPendingEntries() const; std::vector popPendingEntries(); void clearPendingEntries(); void logEntry(const RawPerformanceEntry &entry); diff --git a/Libraries/WebPerformance/PerformanceObserver.js b/Libraries/WebPerformance/PerformanceObserver.js index 6c6566173db..71db2cee119 100644 --- a/Libraries/WebPerformance/PerformanceObserver.js +++ b/Libraries/WebPerformance/PerformanceObserver.js @@ -124,7 +124,7 @@ const onPerformanceEntry = () => { if (!NativePerformanceObserver) { return; } - const rawEntries = NativePerformanceObserver.getPendingEntries(); + const rawEntries = NativePerformanceObserver.popPendingEntries?.() ?? []; if (rawEntries.length === 0) { return; }