summaryrefslogtreecommitdiffstats
path: root/xpcom/base
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /xpcom/base
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-upstream/125.0.1.tar.xz
firefox-upstream/125.0.1.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xpcom/base')
-rw-r--r--xpcom/base/AppShutdown.cpp18
-rw-r--r--xpcom/base/AvailableMemoryWatcherLinux.cpp2
-rw-r--r--xpcom/base/AvailableMemoryWatcherMac.cpp30
-rw-r--r--xpcom/base/AvailableMemoryWatcherWin.cpp9
-rw-r--r--xpcom/base/CFTypeRefPtr.h194
-rw-r--r--xpcom/base/CycleCollectedJSRuntime.cpp6
-rw-r--r--xpcom/base/EnumeratedArrayCycleCollection.h12
-rw-r--r--xpcom/base/MacHelpers.mm3
-rw-r--r--xpcom/base/MacStringHelpers.h6
-rw-r--r--xpcom/base/MacStringHelpers.mm36
-rw-r--r--xpcom/base/moz.build14
-rw-r--r--xpcom/base/nsCycleCollector.cpp4
-rw-r--r--xpcom/base/nsDebugImpl.cpp7
-rw-r--r--xpcom/base/nsISupportsImpl.cpp18
-rw-r--r--xpcom/base/nsISupportsImpl.h15
-rw-r--r--xpcom/base/nsrootidl.idl27
16 files changed, 327 insertions, 74 deletions
diff --git a/xpcom/base/AppShutdown.cpp b/xpcom/base/AppShutdown.cpp
index c68dedef31..53ae4e3ba9 100644
--- a/xpcom/base/AppShutdown.cpp
+++ b/xpcom/base/AppShutdown.cpp
@@ -309,32 +309,32 @@ bool AppShutdown::IsRestarting() {
void AppShutdown::AnnotateShutdownReason(AppShutdownReason aReason) {
auto key = CrashReporter::Annotation::ShutdownReason;
- nsCString reasonStr;
+ const char* reasonStr;
switch (aReason) {
case AppShutdownReason::AppClose:
- reasonStr = "AppClose"_ns;
+ reasonStr = "AppClose";
break;
case AppShutdownReason::AppRestart:
- reasonStr = "AppRestart"_ns;
+ reasonStr = "AppRestart";
break;
case AppShutdownReason::OSForceClose:
- reasonStr = "OSForceClose"_ns;
+ reasonStr = "OSForceClose";
break;
case AppShutdownReason::OSSessionEnd:
- reasonStr = "OSSessionEnd"_ns;
+ reasonStr = "OSSessionEnd";
break;
case AppShutdownReason::OSShutdown:
- reasonStr = "OSShutdown"_ns;
+ reasonStr = "OSShutdown";
break;
case AppShutdownReason::WinUnexpectedMozQuit:
- reasonStr = "WinUnexpectedMozQuit"_ns;
+ reasonStr = "WinUnexpectedMozQuit";
break;
default:
MOZ_ASSERT_UNREACHABLE("We should know the given reason for shutdown.");
- reasonStr = "Unknown"_ns;
+ reasonStr = "Unknown";
break;
}
- CrashReporter::AnnotateCrashReport(key, reasonStr);
+ CrashReporter::RecordAnnotationCString(key, reasonStr);
}
#ifdef DEBUG
diff --git a/xpcom/base/AvailableMemoryWatcherLinux.cpp b/xpcom/base/AvailableMemoryWatcherLinux.cpp
index 04927b7d46..de8a1d79fc 100644
--- a/xpcom/base/AvailableMemoryWatcherLinux.cpp
+++ b/xpcom/base/AvailableMemoryWatcherLinux.cpp
@@ -206,7 +206,7 @@ void nsAvailableMemoryWatcher::HandleLowMemory() {
void nsAvailableMemoryWatcher::UpdateCrashAnnotation(const MutexAutoLock&)
MOZ_REQUIRES(mMutex) {
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationBool(
CrashReporter::Annotation::LinuxUnderMemoryPressure,
mUnderMemoryPressure);
}
diff --git a/xpcom/base/AvailableMemoryWatcherMac.cpp b/xpcom/base/AvailableMemoryWatcherMac.cpp
index d6f2d16b30..de6901f8d5 100644
--- a/xpcom/base/AvailableMemoryWatcherMac.cpp
+++ b/xpcom/base/AvailableMemoryWatcherMac.cpp
@@ -95,11 +95,11 @@ class nsAvailableMemoryWatcher final : public nsITimerCallback,
void AddParentAnnotation(CrashReporter::Annotation aAnnotation,
nsAutoCString aString) {
- CrashReporter::AnnotateCrashReport(aAnnotation, aString);
+ CrashReporter::RecordAnnotationNSCString(aAnnotation, aString);
}
void AddParentAnnotation(CrashReporter::Annotation aAnnotation,
uint32_t aData) {
- CrashReporter::AnnotateCrashReport(aAnnotation, aData);
+ CrashReporter::RecordAnnotationU32(aAnnotation, aData);
}
void LowMemoryResponse();
@@ -251,18 +251,18 @@ nsresult nsAvailableMemoryWatcher::Init() {
// Set the initial state of all annotations for parent crash reports.
// Content process crash reports are set when a crash occurs and
// AddChildAnnotations() is called.
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressure, mLevelStr);
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureNormalTime, mNormalTimeStr);
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureWarningTime, mWarningTimeStr);
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureCriticalTime,
mCriticalTimeStr);
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationU32(
CrashReporter::Annotation::MacMemoryPressureSysctl, mLevelSysctl);
- CrashReporter::AnnotateCrashReport(
+ CrashReporter::RecordAnnotationU32(
CrashReporter::Annotation::MacAvailableMemorySysctl, mAvailMemSysctl);
// To support running experiments, handle pref
@@ -441,18 +441,18 @@ void nsAvailableMemoryWatcher::OnMemoryPressureChangedInternal(
// Add all annotations to the provided crash reporter instance.
void nsAvailableMemoryWatcher::AddChildAnnotations(
const UniquePtr<ipc::CrashReporterHost>& aCrashReporter) {
- aCrashReporter->AddAnnotation(CrashReporter::Annotation::MacMemoryPressure,
- mLevelStr);
- aCrashReporter->AddAnnotation(
+ aCrashReporter->AddAnnotationNSCString(
+ CrashReporter::Annotation::MacMemoryPressure, mLevelStr);
+ aCrashReporter->AddAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureNormalTime, mNormalTimeStr);
- aCrashReporter->AddAnnotation(
+ aCrashReporter->AddAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureWarningTime, mWarningTimeStr);
- aCrashReporter->AddAnnotation(
+ aCrashReporter->AddAnnotationNSCString(
CrashReporter::Annotation::MacMemoryPressureCriticalTime,
mCriticalTimeStr);
- aCrashReporter->AddAnnotation(
+ aCrashReporter->AddAnnotationU32(
CrashReporter::Annotation::MacMemoryPressureSysctl, mLevelSysctl);
- aCrashReporter->AddAnnotation(
+ aCrashReporter->AddAnnotationU32(
CrashReporter::Annotation::MacAvailableMemorySysctl, mAvailMemSysctl);
}
diff --git a/xpcom/base/AvailableMemoryWatcherWin.cpp b/xpcom/base/AvailableMemoryWatcherWin.cpp
index cd027366de..1effbe3226 100644
--- a/xpcom/base/AvailableMemoryWatcherWin.cpp
+++ b/xpcom/base/AvailableMemoryWatcherWin.cpp
@@ -121,6 +121,12 @@ nsresult nsAvailableMemoryWatcher::Init() {
return NS_ERROR_FAILURE;
}
+ static_assert(sizeof(sNumLowPhysicalMemEvents) == sizeof(uint32_t));
+
+ CrashReporter::RegisterAnnotationU32(
+ CrashReporter::Annotation::LowPhysicalMemoryEvents,
+ reinterpret_cast<uint32_t*>(&sNumLowPhysicalMemEvents));
+
return NS_OK;
}
@@ -172,9 +178,6 @@ VOID CALLBACK nsAvailableMemoryWatcher::LowMemoryCallback(PVOID aContext,
// static
void nsAvailableMemoryWatcher::RecordLowMemoryEvent() {
sNumLowPhysicalMemEvents++;
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::LowPhysicalMemoryEvents,
- sNumLowPhysicalMemEvents);
}
bool nsAvailableMemoryWatcher::RegisterMemoryResourceHandler(
diff --git a/xpcom/base/CFTypeRefPtr.h b/xpcom/base/CFTypeRefPtr.h
new file mode 100644
index 0000000000..185355777e
--- /dev/null
+++ b/xpcom/base/CFTypeRefPtr.h
@@ -0,0 +1,194 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef CFTypeRefPtr_h
+#define CFTypeRefPtr_h
+
+#include "mozilla/Assertions.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/DbgMacro.h"
+#include "mozilla/HashFunctions.h"
+
+// A smart pointer for CoreFoundation classes which does reference counting.
+//
+// Manual reference counting:
+//
+// UInt32 someNumber = 10;
+// CFNumberRef numberObject =
+// CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &someNumber);
+// // do something with numberObject
+// CFRelease(numberObject);
+//
+// Automatic reference counting using CFTypeRefPtr:
+//
+// UInt32 someNumber = 10;
+// auto numberObject =
+// CFTypeRefPtr<CFNumberRef>::WrapUnderCreateRule(
+// CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &someNumber));
+// // do something with numberObject
+// // no CFRelease
+
+template <class PtrT>
+class CFTypeRefPtr {
+ private:
+ void assign_with_CFRetain(PtrT aRawPtr) {
+ CFRetain(aRawPtr);
+ assign_assuming_CFRetain(aRawPtr);
+ }
+
+ void assign_assuming_CFRetain(PtrT aNewPtr) {
+ PtrT oldPtr = mRawPtr;
+ mRawPtr = aNewPtr;
+ if (oldPtr) {
+ CFRelease(oldPtr);
+ }
+ }
+
+ private:
+ PtrT mRawPtr;
+
+ public:
+ ~CFTypeRefPtr() {
+ if (mRawPtr) {
+ CFRelease(mRawPtr);
+ }
+ }
+
+ // Constructors
+
+ CFTypeRefPtr() : mRawPtr(nullptr) {}
+
+ CFTypeRefPtr(const CFTypeRefPtr<PtrT>& aSmartPtr)
+ : mRawPtr(aSmartPtr.mRawPtr) {
+ if (mRawPtr) {
+ CFRetain(mRawPtr);
+ }
+ }
+
+ CFTypeRefPtr(CFTypeRefPtr<PtrT>&& aRefPtr) : mRawPtr(aRefPtr.mRawPtr) {
+ aRefPtr.mRawPtr = nullptr;
+ }
+
+ MOZ_IMPLICIT CFTypeRefPtr(decltype(nullptr)) : mRawPtr(nullptr) {}
+
+ // There is no constructor from a raw pointer value.
+ // Use one of the static WrapUnder*Rule methods below instead.
+
+ static CFTypeRefPtr<PtrT> WrapUnderCreateRule(PtrT aRawPtr) {
+ CFTypeRefPtr<PtrT> ptr;
+ ptr.AssignUnderCreateRule(aRawPtr);
+ return ptr;
+ }
+
+ static CFTypeRefPtr<PtrT> WrapUnderGetRule(PtrT aRawPtr) {
+ CFTypeRefPtr<PtrT> ptr;
+ ptr.AssignUnderGetRule(aRawPtr);
+ return ptr;
+ }
+
+ // Assignment operators
+
+ CFTypeRefPtr<PtrT>& operator=(decltype(nullptr)) {
+ assign_assuming_CFRetain(nullptr);
+ return *this;
+ }
+
+ CFTypeRefPtr<PtrT>& operator=(const CFTypeRefPtr<PtrT>& aRhs) {
+ assign_with_CFRetain(aRhs.mRawPtr);
+ return *this;
+ }
+
+ CFTypeRefPtr<PtrT>& operator=(CFTypeRefPtr<PtrT>&& aRefPtr) {
+ assign_assuming_CFRetain(aRefPtr.mRawPtr);
+ aRefPtr.mRawPtr = nullptr;
+ return *this;
+ }
+
+ // There is no operator= for a raw pointer value.
+ // Use one of the AssignUnder*Rule methods below instead.
+
+ CFTypeRefPtr<PtrT>& AssignUnderCreateRule(PtrT aRawPtr) {
+ // Freshly-created objects come with a retain count of 1.
+ assign_assuming_CFRetain(aRawPtr);
+ return *this;
+ }
+
+ CFTypeRefPtr<PtrT>& AssignUnderGetRule(PtrT aRawPtr) {
+ assign_with_CFRetain(aRawPtr);
+ return *this;
+ }
+
+ // Other pointer operators
+
+ // This is the only way to get the raw pointer out of the smart pointer.
+ // There is no implicit conversion to a raw pointer.
+ PtrT get() const { return mRawPtr; }
+
+ // Don't allow implicit conversion of temporary CFTypeRefPtr to raw pointer,
+ // because the refcount might be one and the pointer will immediately become
+ // invalid.
+ operator PtrT() const&& = delete;
+ // Also don't allow implicit conversion of non-temporary CFTypeRefPtr.
+ operator PtrT() const& = delete;
+
+ // These let you null-check a pointer without calling get().
+ explicit operator bool() const { return !!mRawPtr; }
+};
+
+template <class PtrT>
+inline bool operator==(const CFTypeRefPtr<PtrT>& aLhs,
+ const CFTypeRefPtr<PtrT>& aRhs) {
+ return aLhs.get() == aRhs.get();
+}
+
+template <class PtrT>
+inline bool operator!=(const CFTypeRefPtr<PtrT>& aLhs,
+ const CFTypeRefPtr<PtrT>& aRhs) {
+ return !(aLhs == aRhs);
+}
+
+// Comparing an |CFTypeRefPtr| to |nullptr|
+
+template <class PtrT>
+inline bool operator==(const CFTypeRefPtr<PtrT>& aLhs, decltype(nullptr)) {
+ return aLhs.get() == nullptr;
+}
+
+template <class PtrT>
+inline bool operator==(decltype(nullptr), const CFTypeRefPtr<PtrT>& aRhs) {
+ return nullptr == aRhs.get();
+}
+
+template <class PtrT>
+inline bool operator!=(const CFTypeRefPtr<PtrT>& aLhs, decltype(nullptr)) {
+ return aLhs.get() != nullptr;
+}
+
+template <class PtrT>
+inline bool operator!=(decltype(nullptr), const CFTypeRefPtr<PtrT>& aRhs) {
+ return nullptr != aRhs.get();
+}
+
+// MOZ_DBG support
+
+template <class PtrT>
+std::ostream& operator<<(std::ostream& aOut, const CFTypeRefPtr<PtrT>& aObj) {
+ return mozilla::DebugValue(aOut, aObj.get());
+}
+
+// std::hash support (e.g. for unordered_map)
+namespace std {
+template <class PtrT>
+struct hash<CFTypeRefPtr<PtrT>> {
+ typedef CFTypeRefPtr<PtrT> argument_type;
+ typedef std::size_t result_type;
+ result_type operator()(argument_type const& aPtr) const {
+ return mozilla::HashGeneric(reinterpret_cast<uintptr_t>(aPtr.get()));
+ }
+};
+} // namespace std
+
+#endif /* CFTypeRefPtr_h */
diff --git a/xpcom/base/CycleCollectedJSRuntime.cpp b/xpcom/base/CycleCollectedJSRuntime.cpp
index 03af9e3074..c3f9d56857 100644
--- a/xpcom/base/CycleCollectedJSRuntime.cpp
+++ b/xpcom/base/CycleCollectedJSRuntime.cpp
@@ -1046,7 +1046,7 @@ struct GCMajorMarker : public BaseMarkerType<GCMajorMarker> {
using MS = MarkerSchema;
static constexpr MS::PayloadField PayloadFields[] = {
- {"timings", MS::InputType::String, "GC timings"}};
+ {"timings", MS::InputType::CString, "GC timings"}};
static constexpr MS::Location Locations[] = {MS::Location::MarkerChart,
MS::Location::MarkerTable,
@@ -1793,8 +1793,8 @@ void CycleCollectedJSRuntime::AnnotateAndSetOutOfMemory(OOMState* aStatePtr,
? CrashReporter::Annotation::JSOutOfMemory
: CrashReporter::Annotation::JSLargeAllocationFailure;
- CrashReporter::AnnotateCrashReport(
- annotation, nsDependentCString(OOMStateToString(aNewState)));
+ CrashReporter::RecordAnnotationCString(annotation,
+ OOMStateToString(aNewState));
}
void CycleCollectedJSRuntime::OnGC(JSContext* aContext, JSGCStatus aStatus,
diff --git a/xpcom/base/EnumeratedArrayCycleCollection.h b/xpcom/base/EnumeratedArrayCycleCollection.h
index 465d4cf38a..863b990de7 100644
--- a/xpcom/base/EnumeratedArrayCycleCollection.h
+++ b/xpcom/base/EnumeratedArrayCycleCollection.h
@@ -10,21 +10,21 @@
#include "mozilla/EnumeratedArray.h"
#include "nsCycleCollectionTraversalCallback.h"
-template <typename IndexType, IndexType SizeAsEnumValue, typename ValueType>
+template <typename IndexType, typename ValueType, size_t Size>
inline void ImplCycleCollectionUnlink(
- mozilla::EnumeratedArray<IndexType, SizeAsEnumValue, ValueType>& aField) {
- for (size_t i = 0; i < size_t(SizeAsEnumValue); ++i) {
+ mozilla::EnumeratedArray<IndexType, ValueType, Size>& aField) {
+ for (size_t i = 0; i < Size; ++i) {
aField[IndexType(i)] = nullptr;
}
}
-template <typename IndexType, IndexType SizeAsEnumValue, typename ValueType>
+template <typename IndexType, typename ValueType, size_t Size>
inline void ImplCycleCollectionTraverse(
nsCycleCollectionTraversalCallback& aCallback,
- mozilla::EnumeratedArray<IndexType, SizeAsEnumValue, ValueType>& aField,
+ mozilla::EnumeratedArray<IndexType, ValueType, Size>& aField,
const char* aName, uint32_t aFlags = 0) {
aFlags |= CycleCollectionEdgeNameArrayFlag;
- for (size_t i = 0; i < size_t(SizeAsEnumValue); ++i) {
+ for (size_t i = 0; i < Size; ++i) {
ImplCycleCollectionTraverse(aCallback, aField[IndexType(i)], aName, aFlags);
}
}
diff --git a/xpcom/base/MacHelpers.mm b/xpcom/base/MacHelpers.mm
index 26c04c49dd..9d53fd5b56 100644
--- a/xpcom/base/MacHelpers.mm
+++ b/xpcom/base/MacHelpers.mm
@@ -24,8 +24,7 @@ nsresult GetSelectedCityInfo(nsAString& aCountryCode) {
return NS_ERROR_FAILURE;
}
- return mozilla::CopyCocoaStringToXPCOMString((NSString*)countryCode,
- aCountryCode);
+ mozilla::CopyNSStringToXPCOMString((NSString*)countryCode, aCountryCode);
NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
}
diff --git a/xpcom/base/MacStringHelpers.h b/xpcom/base/MacStringHelpers.h
index c2f9ee82dc..f43046cfb6 100644
--- a/xpcom/base/MacStringHelpers.h
+++ b/xpcom/base/MacStringHelpers.h
@@ -13,7 +13,11 @@
namespace mozilla {
-nsresult CopyCocoaStringToXPCOMString(NSString* aFrom, nsAString& aTo);
+void CopyNSStringToXPCOMString(const NSString* aFrom, nsAString& aTo);
+
+NSString* XPCOMStringToNSString(const nsAString& aFrom);
+
+NSString* XPCOMStringToNSString(const nsACString& aFrom);
} // namespace mozilla
diff --git a/xpcom/base/MacStringHelpers.mm b/xpcom/base/MacStringHelpers.mm
index cf0b03665d..30b447548a 100644
--- a/xpcom/base/MacStringHelpers.mm
+++ b/xpcom/base/MacStringHelpers.mm
@@ -12,24 +12,42 @@
namespace mozilla {
-nsresult CopyCocoaStringToXPCOMString(NSString* aFrom, nsAString& aTo) {
- NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
+void CopyNSStringToXPCOMString(const NSString* aFrom, nsAString& aTo) {
+ NS_OBJC_BEGIN_TRY_IGNORE_BLOCK;
- NSUInteger len = [aFrom length];
- if (len > std::numeric_limits<nsAString::size_type>::max()) {
- return NS_ERROR_OUT_OF_MEMORY;
+ if (!aFrom) {
+ aTo.Truncate();
+ return;
}
- if (!aTo.SetLength(len, mozilla::fallible)) {
- return NS_ERROR_OUT_OF_MEMORY;
+ NSUInteger len = [aFrom length];
+ if (len > std::numeric_limits<nsAString::size_type>::max()) {
+ aTo.AllocFailed(std::numeric_limits<nsAString::size_type>::max());
}
+ aTo.SetLength(len);
[aFrom getCharacters:reinterpret_cast<unichar*>(aTo.BeginWriting())
range:NSMakeRange(0, len)];
- return NS_OK;
+ NS_OBJC_END_TRY_IGNORE_BLOCK;
+}
- NS_OBJC_END_TRY_BLOCK_RETURN(NS_ERROR_FAILURE);
+NSString* XPCOMStringToNSString(const nsAString& aFrom) {
+ if (aFrom.IsEmpty()) {
+ return [NSString string];
+ }
+ return [NSString stringWithCharacters:reinterpret_cast<const unichar*>(
+ aFrom.BeginReading())
+ length:aFrom.Length()];
+}
+
+NSString* XPCOMStringToNSString(const nsACString& aFrom) {
+ if (aFrom.IsEmpty()) {
+ return [NSString string];
+ }
+ return [[[NSString alloc] initWithBytes:aFrom.BeginReading()
+ length:aFrom.Length()
+ encoding:NSUTF8StringEncoding] autorelease];
}
} // namespace mozilla
diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build
index 1ac409ed04..16870a9dbc 100644
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -27,18 +27,24 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
XPIDL_SOURCES += [
"nsIMacPreferencesReader.idl",
]
+ EXPORTS.mozilla += [
+ "MacHelpers.h",
+ "nsMacPreferencesReader.h",
+ ]
+ UNIFIED_SOURCES += [
+ "MacHelpers.mm",
+ "nsMacPreferencesReader.mm",
+ ]
+if CONFIG["OS_ARCH"] == "Darwin":
EXPORTS += [
+ "CFTypeRefPtr.h",
"nsObjCExceptions.h",
]
EXPORTS.mozilla += [
- "MacHelpers.h",
"MacStringHelpers.h",
- "nsMacPreferencesReader.h",
]
UNIFIED_SOURCES += [
- "MacHelpers.mm",
"MacStringHelpers.mm",
- "nsMacPreferencesReader.mm",
"nsObjCExceptions.mm",
]
diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp
index 9c885b6ef1..9c39dee475 100644
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -628,8 +628,8 @@ void PtrInfo::AnnotatedReleaseAssert(bool aCondition, const char* aMessage) {
}
nsPrintfCString msg("%s, for class %s", aMessage, piName);
NS_WARNING(msg.get());
- CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::CycleCollector,
- msg);
+ CrashReporter::RecordAnnotationNSCString(
+ CrashReporter::Annotation::CycleCollector, msg);
MOZ_CRASH();
}
diff --git a/xpcom/base/nsDebugImpl.cpp b/xpcom/base/nsDebugImpl.cpp
index 4023efd0ec..81305ccdb9 100644
--- a/xpcom/base/nsDebugImpl.cpp
+++ b/xpcom/base/nsDebugImpl.cpp
@@ -452,13 +452,12 @@ NS_DebugBreak(uint32_t aSeverity, const char* aStr, const char* aExpr,
if (XRE_IsParentProcess()) {
// Don't include the PID in the crash report annotation to
// allow faceting on crash-stats.mozilla.org.
- nsCString note("xpcom_runtime_abort(");
+ nsAutoCString note("xpcom_runtime_abort(");
note += nonPIDBuf.buffer;
note += ")";
CrashReporter::AppendAppNotesToCrashReport(note);
- CrashReporter::AnnotateCrashReport(
- CrashReporter::Annotation::AbortMessage,
- nsDependentCString(nonPIDBuf.buffer));
+ CrashReporter::RecordAnnotationNSCString(
+ CrashReporter::Annotation::AbortMessage, note);
}
#if defined(DEBUG) && defined(_WIN32)
diff --git a/xpcom/base/nsISupportsImpl.cpp b/xpcom/base/nsISupportsImpl.cpp
index c282ec14db..5ae4b3914b 100644
--- a/xpcom/base/nsISupportsImpl.cpp
+++ b/xpcom/base/nsISupportsImpl.cpp
@@ -50,13 +50,25 @@ bool nsAutoOwningThread::IsCurrentThread() const {
nsAutoOwningEventTarget::nsAutoOwningEventTarget()
: mTarget(GetCurrentSerialEventTarget()) {
- mTarget->AddRef();
+ NS_ADDREF(mTarget);
}
-nsAutoOwningEventTarget::~nsAutoOwningEventTarget() {
- nsCOMPtr<nsISerialEventTarget> target = dont_AddRef(mTarget);
+nsAutoOwningEventTarget::nsAutoOwningEventTarget(
+ const nsAutoOwningEventTarget& aOther)
+ : mTarget(aOther.mTarget) {
+ NS_ADDREF(mTarget);
}
+nsAutoOwningEventTarget& nsAutoOwningEventTarget::operator=(
+ const nsAutoOwningEventTarget& aRhs) {
+ nsISerialEventTarget* previous = std::exchange(mTarget, aRhs.mTarget);
+ NS_ADDREF(mTarget);
+ NS_RELEASE(previous);
+ return *this;
+}
+
+nsAutoOwningEventTarget::~nsAutoOwningEventTarget() { NS_RELEASE(mTarget); }
+
void nsAutoOwningEventTarget ::AssertCurrentThreadOwnsMe(
const char* msg) const {
if (MOZ_UNLIKELY(!IsCurrentThread())) {
diff --git a/xpcom/base/nsISupportsImpl.h b/xpcom/base/nsISupportsImpl.h
index 27ff85b385..0485a98812 100644
--- a/xpcom/base/nsISupportsImpl.h
+++ b/xpcom/base/nsISupportsImpl.h
@@ -71,6 +71,20 @@ class nsISerialEventTarget;
class nsAutoOwningEventTarget {
public:
nsAutoOwningEventTarget();
+
+ nsAutoOwningEventTarget(const nsAutoOwningEventTarget& aOther);
+
+ // Per https://en.cppreference.com/w/cpp/language/move_constructor
+ // there's no implicitly-declared move constructor if there are user-declared
+ // copy constructors, and we have one, immediately above.
+
+ nsAutoOwningEventTarget& operator=(const nsAutoOwningEventTarget& aRhs);
+
+ // Per https://en.cppreference.com/w/cpp/language/move_assignment
+ // there's no implicitly-declared move assignment operator if there are
+ // user-declared copy assignment operators, and we have one, immediately
+ // above.
+
~nsAutoOwningEventTarget();
// We move the actual assertion checks out-of-line to minimize code bloat,
@@ -88,6 +102,7 @@ class nsAutoOwningEventTarget {
private:
void AssertCurrentThreadOwnsMe(const char* aMsg) const;
+ // A raw pointer to avoid nsCOMPtr.h dependency.
nsISerialEventTarget* mTarget;
};
diff --git a/xpcom/base/nsrootidl.idl b/xpcom/base/nsrootidl.idl
index 28e643e312..292ea54890 100644
--- a/xpcom/base/nsrootidl.idl
+++ b/xpcom/base/nsrootidl.idl
@@ -35,18 +35,21 @@ class Promise;
#if 0
%}
-typedef boolean bool ;
-typedef octet uint8_t ;
-typedef unsigned short uint16_t ;
-typedef unsigned short char16_t;
-typedef unsigned long uint32_t ;
-typedef unsigned long long uint64_t ;
-typedef long long PRTime ;
-typedef short int16_t ;
-typedef long int32_t ;
-typedef long long int64_t ;
-
-typedef unsigned long nsresult ;
+// [substitute] typedefs emit the underlying builtin type directly, and
+// avoid polluting bindings for other languages with C++ stdint types.
+
+[substitute] typedef boolean bool ;
+[substitute] typedef octet uint8_t ;
+[substitute] typedef unsigned short uint16_t ;
+[substitute] typedef unsigned long uint32_t ;
+[substitute] typedef unsigned long long uint64_t ;
+[substitute] typedef short int16_t ;
+[substitute] typedef long int32_t ;
+[substitute] typedef long long int64_t ;
+
+ typedef unsigned short char16_t ;
+ typedef unsigned long nsresult ;
+ typedef long long PRTime ;
// If we ever want to use `size_t` in scriptable interfaces, this will need to
// be built into the xpidl compiler, as the size varies based on platform.