From 583cee7bac3434e1452305142d922829bc33c65c Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Wed, 6 Jul 2022 14:53:06 +0000 Subject: [PATCH] Bug 1778211 - Reject xpidl CDATA containing 'virtual', r=xpcom-reviewers,necko-reviewers,mccr8,dragana We'll probably want to do something more accurate in the future with a custom clang static analysis pass which validates that XPIDL interfaces have the expected vtable and struct layout, however doing so would be more involved than the string matching done in this patch. In addition to checking for extra virtual methods, we'll likely also want to check for data members on interfaces, and reject them unless the class is marked as `[builtinclass]` in addition to some other attribute which we'll need to add to prevent them from being implemented in Rust (as c++ data members will not be reflected by the rust macro). There were 2 instances of a comment which contained the word 'virtual' within a CDATA block. These comments were moved out of the CDATA block to avoid triggering the error. Differential Revision: https://phabricator.services.mozilla.com/D151068 --- accessible/interfaces/nsIAccessible.idl | 9 +-- .../interfaces/nsIAccessibleMacInterface.idl | 6 +- accessible/xpcom/xpcAccessibleGeneric.cpp | 2 +- accessible/xpcom/xpcAccessibleGeneric.h | 4 +- accessible/xpcom/xpcAccessibleMacInterface.h | 5 +- accessible/xpcom/xpcAccessibleMacInterface.mm | 2 +- dom/base/nsINode.cpp | 2 +- dom/base/nsINode.h | 1 - .../webrtc/transport/ipc/WebrtcTCPSocket.cpp | 6 ++ .../webrtc/transport/ipc/WebrtcTCPSocket.h | 5 -- image/DynamicImage.cpp | 7 ++- image/DynamicImage.h | 2 - image/ImageWrapper.cpp | 7 ++- image/ImageWrapper.h | 2 - image/OrientedImage.cpp | 2 +- image/OrientedImage.h | 2 +- image/RasterImage.cpp | 8 ++- image/RasterImage.h | 2 - image/VectorImage.cpp | 4 +- image/VectorImage.h | 3 - image/imgIContainer.idl | 9 ++- image/imgTools.cpp | 8 --- intl/strres/nsIStringBundle.idl | 26 ++++---- intl/strres/nsStringBundle.cpp | 62 ++++++++++++++----- intl/strres/nsStringBundle.h | 6 +- intl/strres/nsStringBundleService.h | 10 --- .../protocol/http/ClassifierDummyChannel.cpp | 3 + netwerk/protocol/http/NullHttpChannel.cpp | 3 + netwerk/protocol/http/nsIHttpChannel.idl | 6 +- .../protocol/http/nsIHttpChannelInternal.idl | 10 ++- .../viewsource/nsViewSourceChannel.cpp | 10 +++ .../websocket/IPCTransportProvider.cpp | 7 +++ .../protocol/websocket/IPCTransportProvider.h | 6 +- .../protocol/websocket/WebSocketChannel.cpp | 3 +- netwerk/protocol/websocket/WebSocketChannel.h | 2 - .../websocket/WebSocketConnectionChild.cpp | 6 ++ .../websocket/WebSocketConnectionChild.h | 5 -- storage/mozIStorageStatement.idl | 2 +- storage/mozIStorageValueArray.idl | 2 +- tools/profiler/gecko/nsIProfiler.idl | 5 +- tools/profiler/gecko/nsProfiler.h | 3 - widget/nsIPrintSettings.idl | 5 +- widget/nsPrintSettingsImpl.h | 2 - xpcom/base/nsIWeakReference.idl | 7 ++- xpcom/base/nsWeakReference.cpp | 4 +- xpcom/base/nsrootidl.idl | 6 +- xpcom/ds/nsIPersistentProperties2.idl | 8 +-- xpcom/ds/nsPersistentProperties.cpp | 2 +- xpcom/ds/nsPersistentProperties.h | 3 - xpcom/idl-parser/xpidl/xpidl.py | 24 ++++++- xpcom/reflect/xptinfo/xptcodegen.py | 13 +++- xpcom/threads/nsITimer.idl | 5 +- xpcom/threads/nsTimerImpl.cpp | 2 +- xpcom/threads/nsTimerImpl.h | 3 - 54 files changed, 198 insertions(+), 161 deletions(-) diff --git a/accessible/interfaces/nsIAccessible.idl b/accessible/interfaces/nsIAccessible.idl index 60fdd0d2abfb..b2f1962f5ced 100644 --- a/accessible/interfaces/nsIAccessible.idl +++ b/accessible/interfaces/nsIAccessible.idl @@ -22,6 +22,9 @@ class LocalAccessible; } %} +[ptr] native InternalAccessible(mozilla::a11y::Accessible); +[ptr] native InternalLocalAccessible(mozilla::a11y::LocalAccessible); + /** * A cross-platform interface that supports platform-specific * accessibility APIs like MSAA and ATK. Contains the sum of what's needed @@ -342,10 +345,8 @@ interface nsIAccessible : nsISupports */ void announce(in AString announcement, in unsigned short priority); - %{C++ - virtual mozilla::a11y::LocalAccessible* ToInternalAccessible() const = 0; - virtual mozilla::a11y::Accessible* ToInternalGeneric() const = 0; - %} + [notxpcom, nostdcall] InternalLocalAccessible toInternalAccessible(); + [notxpcom, nostdcall] InternalAccessible toInternalGeneric(); }; diff --git a/accessible/interfaces/nsIAccessibleMacInterface.idl b/accessible/interfaces/nsIAccessibleMacInterface.idl index c4341f89c177..384d09d5f077 100644 --- a/accessible/interfaces/nsIAccessibleMacInterface.idl +++ b/accessible/interfaces/nsIAccessibleMacInterface.idl @@ -11,15 +11,15 @@ #define NS_ACCESSIBLE_MAC_EVENT_TOPIC "accessible-mac-event" %} +native NativeObjectId(id); + /** * A generic NSISupports wrapper for native NSObjects. */ [scriptable, builtinclass, uuid(4582bb77-de03-4ed1-a9b4-d482d97c0129)] interface nsIAccessibleMacNSObjectWrapper : nsISupports { - %{C++ - virtual id GetNativeObject() const = 0; - %} + [noscript, notxpcom, nostdcall] NativeObjectId GetNativeObject(); }; [scriptable, builtinclass, uuid(9d27cf21-66fc-47dc-8a07-98edb18707b1)] diff --git a/accessible/xpcom/xpcAccessibleGeneric.cpp b/accessible/xpcom/xpcAccessibleGeneric.cpp index 6ce122a07904..aaef5ac14c3a 100644 --- a/accessible/xpcom/xpcAccessibleGeneric.cpp +++ b/accessible/xpcom/xpcAccessibleGeneric.cpp @@ -51,7 +51,7 @@ xpcAccessibleGeneric::~xpcAccessibleGeneric() { //////////////////////////////////////////////////////////////////////////////// // nsIAccessible -LocalAccessible* xpcAccessibleGeneric::ToInternalAccessible() const { +LocalAccessible* xpcAccessibleGeneric::ToInternalAccessible() { return mIntl->AsLocal(); } diff --git a/accessible/xpcom/xpcAccessibleGeneric.h b/accessible/xpcom/xpcAccessibleGeneric.h index a990b83b42ff..65df7e6ec730 100644 --- a/accessible/xpcom/xpcAccessibleGeneric.h +++ b/accessible/xpcom/xpcAccessibleGeneric.h @@ -37,8 +37,8 @@ class xpcAccessibleGeneric : public xpcAccessible, NS_DECL_ISUPPORTS // nsIAccessible - LocalAccessible* ToInternalAccessible() const final; - Accessible* ToInternalGeneric() const final { return mIntl; } + LocalAccessible* ToInternalAccessible() final; + Accessible* ToInternalGeneric() final { return mIntl; } // xpcAccessibleGeneric virtual void Shutdown(); diff --git a/accessible/xpcom/xpcAccessibleMacInterface.h b/accessible/xpcom/xpcAccessibleMacInterface.h index 7fdc54e16b07..18b5955087b0 100644 --- a/accessible/xpcom/xpcAccessibleMacInterface.h +++ b/accessible/xpcom/xpcAccessibleMacInterface.h @@ -20,10 +20,7 @@ class xpcAccessibleMacNSObjectWrapper : public nsIAccessibleMacNSObjectWrapper { explicit xpcAccessibleMacNSObjectWrapper(id aTextMarker); NS_DECL_ISUPPORTS - NS_DECL_NSIACCESSIBLEMACNSOBJECTWRAPPER; - - // Get the wrapped NSObject for this interface. - id GetNativeObject() const final; + NS_DECL_NSIACCESSIBLEMACNSOBJECTWRAPPER protected: virtual ~xpcAccessibleMacNSObjectWrapper(); diff --git a/accessible/xpcom/xpcAccessibleMacInterface.mm b/accessible/xpcom/xpcAccessibleMacInterface.mm index 6347f1619db1..a266791579b8 100644 --- a/accessible/xpcom/xpcAccessibleMacInterface.mm +++ b/accessible/xpcom/xpcAccessibleMacInterface.mm @@ -33,7 +33,7 @@ xpcAccessibleMacNSObjectWrapper::xpcAccessibleMacNSObjectWrapper(id aNativeObj) xpcAccessibleMacNSObjectWrapper::~xpcAccessibleMacNSObjectWrapper() { [mNativeObject release]; } -id xpcAccessibleMacNSObjectWrapper::GetNativeObject() const { return mNativeObject; } +id xpcAccessibleMacNSObjectWrapper::GetNativeObject() { return mNativeObject; } // xpcAccessibleMacInterface diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index 88e24213ce8f..1088bfc489a0 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -3546,6 +3546,6 @@ nsNodeWeakReference::QueryReferentFromScript(const nsIID& aIID, } size_t nsNodeWeakReference::SizeOfOnlyThis( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { return aMallocSizeOf(this); } diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 56adeeb339ec..0c7c5867c4a1 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -252,7 +252,6 @@ class nsNodeWeakReference final : public nsIWeakReference { // nsIWeakReference NS_DECL_NSIWEAKREFERENCE - size_t SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) const override; void NoticeNodeDestruction() { mObject = nullptr; } diff --git a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp index d33c9a1dd865..510ac3515a93 100644 --- a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp +++ b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.cpp @@ -618,6 +618,12 @@ WebrtcTCPSocket::OnUpgradeFailed(nsresult aErrorCode) { return NS_OK; } +NS_IMETHODIMP +WebrtcTCPSocket::OnWebSocketConnectionAvailable( + WebSocketConnectionBase* aConnection) { + return NS_ERROR_NOT_IMPLEMENTED; +} + // nsIRequestObserver (from nsIStreamListener) NS_IMETHODIMP WebrtcTCPSocket::OnStartRequest(nsIRequest* aRequest) { diff --git a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h index 26267f011d75..e2f435a67e0c 100644 --- a/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h +++ b/dom/media/webrtc/transport/ipc/WebrtcTCPSocket.h @@ -58,11 +58,6 @@ class WebrtcTCPSocket : public nsIHttpUpgradeListener, size_t CountUnwrittenBytes() const; - nsresult OnWebSocketConnectionAvailable( - WebSocketConnectionBase* aConnection) override { - return NS_ERROR_NOT_IMPLEMENTED; - } - protected: virtual ~WebrtcTCPSocket(); diff --git a/image/DynamicImage.cpp b/image/DynamicImage.cpp index acb914a0bf6f..a7dbe6234370 100644 --- a/image/DynamicImage.cpp +++ b/image/DynamicImage.cpp @@ -90,11 +90,14 @@ DynamicImage::GetHeight(int32_t* aHeight) { return NS_OK; } -nsresult DynamicImage::GetNativeSizes(nsTArray& aNativeSizes) const { +void DynamicImage::MediaFeatureValuesChangedAllDocuments( + const mozilla::MediaFeatureChange& aChange) {} + +nsresult DynamicImage::GetNativeSizes(nsTArray&) { return NS_ERROR_NOT_IMPLEMENTED; } -size_t DynamicImage::GetNativeSizesLength() const { return 0; } +size_t DynamicImage::GetNativeSizesLength() { return 0; } NS_IMETHODIMP DynamicImage::GetIntrinsicSize(nsSize* aSize) { diff --git a/image/DynamicImage.h b/image/DynamicImage.h index a5d0a30db1ca..2b8a8339589b 100644 --- a/image/DynamicImage.h +++ b/image/DynamicImage.h @@ -28,8 +28,6 @@ class DynamicImage : public Image { } // Inherited methods from Image. - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; - size_t GetNativeSizesLength() const override; virtual already_AddRefed GetProgressTracker() override; virtual size_t SizeOfSourceWithComputedFallback( SizeOfState& aState) const override; diff --git a/image/ImageWrapper.cpp b/image/ImageWrapper.cpp index 693857744e12..c8d28e6a4ede 100644 --- a/image/ImageWrapper.cpp +++ b/image/ImageWrapper.cpp @@ -103,11 +103,14 @@ ImageWrapper::GetHeight(int32_t* aHeight) { return mInnerImage->GetHeight(aHeight); } -nsresult ImageWrapper::GetNativeSizes(nsTArray& aNativeSizes) const { +void ImageWrapper::MediaFeatureValuesChangedAllDocuments( + const mozilla::MediaFeatureChange& aChange) {} + +nsresult ImageWrapper::GetNativeSizes(nsTArray& aNativeSizes) { return mInnerImage->GetNativeSizes(aNativeSizes); } -size_t ImageWrapper::GetNativeSizesLength() const { +size_t ImageWrapper::GetNativeSizesLength() { return mInnerImage->GetNativeSizesLength(); } diff --git a/image/ImageWrapper.h b/image/ImageWrapper.h index 07dd5f73260e..d72393e97649 100644 --- a/image/ImageWrapper.h +++ b/image/ImageWrapper.h @@ -21,8 +21,6 @@ class ImageWrapper : public Image { NS_DECL_IMGICONTAINER // Inherited methods from Image. - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; - size_t GetNativeSizesLength() const override; virtual already_AddRefed GetProgressTracker() override; virtual size_t SizeOfSourceWithComputedFallback( diff --git a/image/OrientedImage.cpp b/image/OrientedImage.cpp index 988c0ad8d4c7..bc8588eb8153 100644 --- a/image/OrientedImage.cpp +++ b/image/OrientedImage.cpp @@ -42,7 +42,7 @@ OrientedImage::GetHeight(int32_t* aHeight) { } } -nsresult OrientedImage::GetNativeSizes(nsTArray& aNativeSizes) const { +nsresult OrientedImage::GetNativeSizes(nsTArray& aNativeSizes) { nsresult rv = InnerImage()->GetNativeSizes(aNativeSizes); if (mOrientation.SwapsWidthAndHeight()) { diff --git a/image/OrientedImage.h b/image/OrientedImage.h index 26d7082a8889..4d3a5bdbf3b7 100644 --- a/image/OrientedImage.h +++ b/image/OrientedImage.h @@ -29,7 +29,7 @@ class OrientedImage : public ImageWrapper { NS_IMETHOD GetWidth(int32_t* aWidth) override; NS_IMETHOD GetHeight(int32_t* aHeight) override; - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; + nsresult GetNativeSizes(nsTArray& aNativeSizes) override; NS_IMETHOD GetIntrinsicSize(nsSize* aSize) override; Maybe GetIntrinsicRatio() override; NS_IMETHOD_(already_AddRefed) diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index 67a4554223e7..49cf074c9f84 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -205,7 +205,11 @@ RasterImage::GetHeight(int32_t* aHeight) { } //****************************************************************************** -nsresult RasterImage::GetNativeSizes(nsTArray& aNativeSizes) const { +void RasterImage::MediaFeatureValuesChangedAllDocuments( + const mozilla::MediaFeatureChange& aChange) {} + +//****************************************************************************** +nsresult RasterImage::GetNativeSizes(nsTArray& aNativeSizes) { if (mError) { return NS_ERROR_FAILURE; } @@ -224,7 +228,7 @@ nsresult RasterImage::GetNativeSizes(nsTArray& aNativeSizes) const { } //****************************************************************************** -size_t RasterImage::GetNativeSizesLength() const { +size_t RasterImage::GetNativeSizesLength() { if (mError || !LoadHasSize()) { return 0; } diff --git a/image/RasterImage.h b/image/RasterImage.h index 4445c18c54a9..55522e6479a2 100644 --- a/image/RasterImage.h +++ b/image/RasterImage.h @@ -156,8 +156,6 @@ class RasterImage final : public ImageResource, NS_DECL_IMGICONTAINERDEBUG #endif - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; - size_t GetNativeSizesLength() const override; virtual nsresult StartAnimation() override; virtual nsresult StopAnimation() override; diff --git a/image/VectorImage.cpp b/image/VectorImage.cpp index 0aa039ca33fa..fa0cf03b865c 100644 --- a/image/VectorImage.cpp +++ b/image/VectorImage.cpp @@ -465,12 +465,12 @@ VectorImage::GetWidth(int32_t* aWidth) { } //****************************************************************************** -nsresult VectorImage::GetNativeSizes(nsTArray& aNativeSizes) const { +nsresult VectorImage::GetNativeSizes(nsTArray& aNativeSizes) { return NS_ERROR_NOT_IMPLEMENTED; } //****************************************************************************** -size_t VectorImage::GetNativeSizesLength() const { return 0; } +size_t VectorImage::GetNativeSizesLength() { return 0; } //****************************************************************************** NS_IMETHODIMP_(void) diff --git a/image/VectorImage.h b/image/VectorImage.h index ec9951d5c17e..4d23373ca762 100644 --- a/image/VectorImage.h +++ b/image/VectorImage.h @@ -36,9 +36,6 @@ class VectorImage final : public ImageResource, public nsIStreamListener { // (no public constructor - use ImageFactory) // Methods inherited from Image - void MediaFeatureValuesChangedAllDocuments(const MediaFeatureChange&) final; - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override; - size_t GetNativeSizesLength() const override; virtual size_t SizeOfSourceWithComputedFallback( SizeOfState& aState) const override; diff --git a/image/imgIContainer.idl b/image/imgIContainer.idl index d00eb674ad98..6eada166a186 100644 --- a/image/imgIContainer.idl +++ b/image/imgIContainer.idl @@ -82,6 +82,7 @@ native ImageResolution(mozilla::image::Resolution); native TempRefSourceSurface(already_AddRefed); native TempRefImgIContainer(already_AddRefed); native nsIntSizeByVal(nsIntSize); +[ref] native MediaFeatureChange(mozilla::MediaFeatureChange); /** @@ -674,20 +675,18 @@ interface imgIContainer : nsISupports */ [noscript, notxpcom] void propagateUseCounters(in Document aReferencingDocument); - %{C++ /* * Called when media feature values that apply to all documents (such as * those based on system metrics) have changed. If this image is a type * that can respond to media queries (i.e., an SVG image), this function * is overridden to handle restyling and invalidating the image. */ - virtual void MediaFeatureValuesChangedAllDocuments(const mozilla::MediaFeatureChange& aChange) {} + [notxpcom, nostdcall] void mediaFeatureValuesChangedAllDocuments([const] in MediaFeatureChange aChange); /* * Get the set of sizes the image can decode to natively. */ - virtual nsresult GetNativeSizes(nsTArray& aNativeSizes) const = 0; + [nostdcall] Array getNativeSizes(); - virtual size_t GetNativeSizesLength() const = 0; - %} + [nostdcall, notxpcom] size_t getNativeSizesLength(); }; diff --git a/image/imgTools.cpp b/image/imgTools.cpp index 519bbd6a393d..864efc6f4485 100644 --- a/image/imgTools.cpp +++ b/image/imgTools.cpp @@ -142,14 +142,6 @@ class ImageDecoderListener final : public nsIStreamListener, // imgIContainer NS_FORWARD_IMGICONTAINER(mImage->) - nsresult GetNativeSizes(nsTArray& aNativeSizes) const override { - return mImage->GetNativeSizes(aNativeSizes); - } - - size_t GetNativeSizesLength() const override { - return mImage->GetNativeSizesLength(); - } - private: virtual ~ImageDecoderListener() = default; diff --git a/intl/strres/nsIStringBundle.idl b/intl/strres/nsIStringBundle.idl index 11161d9b1992..2b8e72328d74 100644 --- a/intl/strres/nsIStringBundle.idl +++ b/intl/strres/nsIStringBundle.idl @@ -28,7 +28,11 @@ class FileDescriptor; %} -[scriptable, uuid(D85A17C2-AA7C-11d2-9B8C-00805F8A16D9)] +[ptr] native ContentParent(mozilla::dom::ContentParent); +[ref] native FileDescriptor(mozilla::ipc::FileDescriptor); +native MallocSizeOf(mozilla::MallocSizeOf); + +[scriptable, builtinclass, uuid(D85A17C2-AA7C-11d2-9B8C-00805F8A16D9)] interface nsIStringBundle : nsISupports { AString GetStringFromID(in long aID); @@ -67,13 +71,11 @@ interface nsIStringBundle : nsISupports // Preloads string bundle data asynchronously void asyncPreload(); -%{C++ - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; - virtual size_t SizeOfIncludingThisIfUnshared(mozilla::MallocSizeOf aMallocSizeOf) const = 0; -%} + [notxpcom, nostdcall] size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); + [notxpcom, nostdcall] size_t SizeOfIncludingThisIfUnshared(in MallocSizeOf aMallocSizeOf); }; -[scriptable, uuid(D85A17C0-AA7C-11d2-9B8C-00805F8A16D9)] +[scriptable, builtinclass, uuid(D85A17C0-AA7C-11d2-9B8C-00805F8A16D9)] interface nsIStringBundleService : nsISupports { nsIStringBundle createBundle(in string aURLSpec); @@ -99,13 +101,11 @@ interface nsIStringBundleService : nsISupports */ void flushBundles(); - %{C++ - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; + [notxpcom, nostdcall] size_t sizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); - virtual void SendContentBundles(mozilla::dom::ContentParent* aContentParent) const = 0; + [notxpcom, nostdcall] void sendContentBundles(in ContentParent aContentParent); - virtual void RegisterContentBundle(const nsCString& aBundleURL, - const mozilla::ipc::FileDescriptor& aMapFile, - size_t aMapSize) = 0; - %} + [notxpcom, nostdcall] void registerContentBundle(in ACString aBundleURL, + [const] in FileDescriptor aMapFile, + in size_t aMapSize); }; diff --git a/intl/strres/nsStringBundle.cpp b/intl/strres/nsStringBundle.cpp index 0e8a277b1fea..e92298d32237 100644 --- a/intl/strres/nsStringBundle.cpp +++ b/intl/strres/nsStringBundle.cpp @@ -117,20 +117,48 @@ class StringBundleProxy : public nsIStringBundle { explicit StringBundleProxy(already_AddRefed aTarget) : mMutex("StringBundleProxy::mMutex"), mTarget(aTarget) {} - NS_FORWARD_NSISTRINGBUNDLE(Target()->); - void Retarget(nsIStringBundle* aTarget) { MutexAutoLock automon(mMutex); mTarget = aTarget; } - size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override { + // Forward nsIStringBundle methods (other than the `SizeOf*` methods) to + // `Target()`. + NS_IMETHOD GetStringFromID(int32_t aID, nsAString& _retval) override { + return Target()->GetStringFromID(aID, _retval); + } + NS_IMETHOD GetStringFromAUTF8Name(const nsACString& aName, + nsAString& _retval) override { + return Target()->GetStringFromAUTF8Name(aName, _retval); + } + NS_IMETHOD GetStringFromName(const char* aName, nsAString& _retval) override { + return Target()->GetStringFromName(aName, _retval); + } + NS_IMETHOD FormatStringFromID(int32_t aID, const nsTArray& params, + nsAString& _retval) override { + return Target()->FormatStringFromID(aID, params, _retval); + } + NS_IMETHOD FormatStringFromAUTF8Name(const nsACString& aName, + const nsTArray& params, + nsAString& _retval) override { + return Target()->FormatStringFromAUTF8Name(aName, params, _retval); + } + NS_IMETHOD FormatStringFromName(const char* aName, + const nsTArray& params, + nsAString& _retval) override { + return Target()->FormatStringFromName(aName, params, _retval); + } + NS_IMETHOD GetSimpleEnumeration(nsISimpleEnumerator** _retval) override { + return Target()->GetSimpleEnumeration(_retval); + } + NS_IMETHOD AsyncPreload() override { return Target()->AsyncPreload(); } + + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) override { return aMallocSizeOf(this); } size_t SizeOfIncludingThisIfUnshared( - mozilla::MallocSizeOf aMallocSizeOf) const override { + mozilla::MallocSizeOf aMallocSizeOf) override { return mRefCnt == 1 ? SizeOfIncludingThis(aMallocSizeOf) : 0; } @@ -220,8 +248,7 @@ class SharedStringBundle final : public nsStringBundleBase { return descriptor; } - size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override; + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) override; static SharedStringBundle* Cast(nsIStringBundle* aStringBundle) { return static_cast(aStringBundle); @@ -322,7 +349,7 @@ nsStringBundleBase::AsyncPreload() { } size_t nsStringBundle::SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { size_t n = 0; if (mProps) { n += mProps->SizeOfIncludingThis(aMallocSizeOf); @@ -330,8 +357,13 @@ size_t nsStringBundle::SizeOfIncludingThis( return aMallocSizeOf(this) + n; } +size_t nsStringBundleBase::SizeOfIncludingThis( + mozilla::MallocSizeOf aMallocSizeOf) { + return 0; +} + size_t nsStringBundleBase::SizeOfIncludingThisIfUnshared( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { if (mRefCnt == 1) { return SizeOfIncludingThis(aMallocSizeOf); } else { @@ -340,7 +372,7 @@ size_t nsStringBundleBase::SizeOfIncludingThisIfUnshared( } size_t SharedStringBundle::SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { size_t n = 0; if (mStringMap) { n += aMallocSizeOf(mStringMap); @@ -733,7 +765,7 @@ nsresult nsStringBundleService::Init() { } size_t nsStringBundleService::SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { size_t n = mBundleMap.ShallowSizeOfExcludingThis(aMallocSizeOf); for (const auto& data : mBundleMap.Values()) { n += aMallocSizeOf(data); @@ -779,8 +811,7 @@ nsStringBundleService::FlushBundles() { return NS_OK; } -void nsStringBundleService::SendContentBundles( - ContentParent* aContentParent) const { +void nsStringBundleService::SendContentBundles(ContentParent* aContentParent) { nsTArray bundles; for (auto* entry : mSharedBundles) { @@ -795,7 +826,7 @@ void nsStringBundleService::SendContentBundles( } void nsStringBundleService::RegisterContentBundle( - const nsCString& aBundleURL, const FileDescriptor& aMapFile, + const nsACString& aBundleURL, const FileDescriptor& aMapFile, size_t aMapSize) { RefPtr proxy; @@ -812,7 +843,8 @@ void nsStringBundleService::RegisterContentBundle( delete cacheEntry; } - auto bundle = MakeBundleRefPtr(aBundleURL.get()); + auto bundle = MakeBundleRefPtr( + PromiseFlatCString(aBundleURL).get()); bundle->SetMapFile(aMapFile, aMapSize); if (proxy) { diff --git a/intl/strres/nsStringBundle.h b/intl/strres/nsStringBundle.h index 0a8a7b62f4f3..96781f81a1f3 100644 --- a/intl/strres/nsStringBundle.h +++ b/intl/strres/nsStringBundle.h @@ -57,9 +57,6 @@ class nsStringBundleBase : public nsIStringBundle, public nsIMemoryReporter { bool mAttemptedLoad; bool mLoaded; - size_t SizeOfIncludingThisIfUnshared( - mozilla::MallocSizeOf aMallocSizeOf) const override; - public: static nsresult FormatString(const char16_t* formatStr, const nsTArray& aParams, @@ -74,8 +71,7 @@ class nsStringBundle : public nsStringBundleBase { nsresult LoadProperties() override; - size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override; + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) override; protected: friend class nsStringBundleBase; diff --git a/intl/strres/nsStringBundleService.h b/intl/strres/nsStringBundleService.h index f6d54227a032..9fa9dfd9f245 100644 --- a/intl/strres/nsStringBundleService.h +++ b/intl/strres/nsStringBundleService.h @@ -45,16 +45,6 @@ class nsStringBundleService : public nsIStringBundleService, return NS_OK; }; - size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override; - - void SendContentBundles( - mozilla::dom::ContentParent* aContentParent) const override; - - void RegisterContentBundle(const nsCString& aBundleURL, - const mozilla::ipc::FileDescriptor& aMapFile, - size_t aMapSize) override; - private: virtual ~nsStringBundleService(); diff --git a/netwerk/protocol/http/ClassifierDummyChannel.cpp b/netwerk/protocol/http/ClassifierDummyChannel.cpp index 93468c95ca95..7b9f8fcee27e 100644 --- a/netwerk/protocol/http/ClassifierDummyChannel.cpp +++ b/netwerk/protocol/http/ClassifierDummyChannel.cpp @@ -796,5 +796,8 @@ ClassifierDummyChannel::SetEarlyHintObserver(nsIEarlyHintObserver* aObserver) { return NS_ERROR_NOT_IMPLEMENTED; } +void ClassifierDummyChannel::SetConnectionInfo( + mozilla::net::nsHttpConnectionInfo* aInfo) {} + } // namespace net } // namespace mozilla diff --git a/netwerk/protocol/http/NullHttpChannel.cpp b/netwerk/protocol/http/NullHttpChannel.cpp index 457c1bc0df20..983a272e5a1f 100644 --- a/netwerk/protocol/http/NullHttpChannel.cpp +++ b/netwerk/protocol/http/NullHttpChannel.cpp @@ -280,6 +280,9 @@ NullHttpChannel::GetEncodedBodySize(uint64_t* aEncodedBodySize) { return NS_ERROR_NOT_IMPLEMENTED; } +void NullHttpChannel::SetSource( + mozilla::UniquePtr aSource) {} + //----------------------------------------------------------------------------- // NullHttpChannel::nsIChannel //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/nsIHttpChannel.idl b/netwerk/protocol/http/nsIHttpChannel.idl index 6357f7cf2d62..0c61d079b879 100644 --- a/netwerk/protocol/http/nsIHttpChannel.idl +++ b/netwerk/protocol/http/nsIHttpChannel.idl @@ -12,6 +12,8 @@ interface nsIReferrerInfo; #include "GeckoProfiler.h" %} +native UniqueProfileChunkedBuffer(mozilla::UniquePtr); + /** * nsIHttpChannel * @@ -489,7 +491,5 @@ interface nsIHttpChannel : nsIIdentChannel in AString aURL, in AString aContentType); -%{ C++ - virtual void SetSource(mozilla::UniquePtr aSource) {} -%} + [notxpcom, nostdcall] void setSource(in UniqueProfileChunkedBuffer aSource); }; diff --git a/netwerk/protocol/http/nsIHttpChannelInternal.idl b/netwerk/protocol/http/nsIHttpChannelInternal.idl index a1205a87a2ab..2f91ba8bc146 100644 --- a/netwerk/protocol/http/nsIHttpChannelInternal.idl +++ b/netwerk/protocol/http/nsIHttpChannelInternal.idl @@ -21,9 +21,11 @@ enum class RequestMode : uint8_t; } } %} +[ptr] native nsHttpConnectionInfo(mozilla::net::nsHttpConnectionInfo); [ptr] native StringArray(nsTArray); [ref] native CStringArrayRef(const nsTArray); [ref] native securityMessagesArray(nsCOMArray); +[ptr] native WebSocketConnectionBase(mozilla::net::WebSocketConnectionBase); native TimeStamp(mozilla::TimeStamp); native RequestMode(mozilla::dom::RequestMode); @@ -50,9 +52,7 @@ interface nsIHttpUpgradeListener : nsISupports [must_use] void onUpgradeFailed(in nsresult aErrorCode); -%{C++ - virtual nsresult OnWebSocketConnectionAvailable(mozilla::net::WebSocketConnectionBase* aConnection) = 0; -%} + void onWebSocketConnectionAvailable(in WebSocketConnectionBase aConnection); }; /** @@ -468,8 +468,6 @@ interface nsIHttpChannelInternal : nsISupports */ [must_use] void setEarlyHintObserver(in nsIEarlyHintObserver aObserver); -%{ C++ - virtual void SetConnectionInfo(mozilla::net::nsHttpConnectionInfo* aInfo) {} -%} + [notxpcom, nostdcall] void setConnectionInfo(in nsHttpConnectionInfo aInfo); }; diff --git a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp index 1cfd69ee130a..45899a806ca5 100644 --- a/netwerk/protocol/viewsource/nsViewSourceChannel.cpp +++ b/netwerk/protocol/viewsource/nsViewSourceChannel.cpp @@ -1054,6 +1054,11 @@ nsViewSourceChannel::LogMimeTypeMismatch(const nsACString& aMessageName, aContentType); } +// FIXME: Should this forward to mHttpChannel? This was previously handled by a +// default empty implementation. +void nsViewSourceChannel::SetSource( + mozilla::UniquePtr aSource) {} + const nsTArray& nsViewSourceChannel::PreferredAlternativeDataTypes() { if (mCacheInfoChannel) { @@ -1080,6 +1085,11 @@ void nsViewSourceChannel::DoDiagnosticAssertWhenOnStopNotCalledOnDestroy() { } } +// FIXME: Should this forward to mHttpChannelInternal? This was previously +// handled by a default empty implementation. +void nsViewSourceChannel::SetConnectionInfo( + mozilla::net::nsHttpConnectionInfo* aInfo) {} + // nsIChildChannel methods NS_IMETHODIMP diff --git a/netwerk/protocol/websocket/IPCTransportProvider.cpp b/netwerk/protocol/websocket/IPCTransportProvider.cpp index a209769f97b5..ff902ae835fd 100644 --- a/netwerk/protocol/websocket/IPCTransportProvider.cpp +++ b/netwerk/protocol/websocket/IPCTransportProvider.cpp @@ -6,6 +6,7 @@ #include "mozilla/net/IPCTransportProvider.h" +#include "IPCTransportProvider.h" #include "nsISocketTransport.h" #include "nsIAsyncInputStream.h" #include "nsIAsyncOutputStream.h" @@ -51,6 +52,12 @@ TransportProviderParent::OnTransportAvailable( NS_IMETHODIMP TransportProviderParent::OnUpgradeFailed(nsresult aErrorCode) { return NS_OK; } +NS_IMETHODIMP +TransportProviderParent::OnWebSocketConnectionAvailable( + WebSocketConnectionBase* aConnection) { + return NS_ERROR_NOT_IMPLEMENTED; +} + void TransportProviderParent::MaybeNotify() { if (!mListener || !mTransport) { return; diff --git a/netwerk/protocol/websocket/IPCTransportProvider.h b/netwerk/protocol/websocket/IPCTransportProvider.h index 155aa6979526..de54be127aba 100644 --- a/netwerk/protocol/websocket/IPCTransportProvider.h +++ b/netwerk/protocol/websocket/IPCTransportProvider.h @@ -58,11 +58,7 @@ class TransportProviderParent final : public PTransportProviderParent, NS_DECL_NSITRANSPORTPROVIDER NS_DECL_NSIHTTPUPGRADELISTENER - void ActorDestroy(ActorDestroyReason aWhy) override{}; - nsresult OnWebSocketConnectionAvailable( - WebSocketConnectionBase* aConnection) override { - return NS_ERROR_NOT_IMPLEMENTED; - } + void ActorDestroy(ActorDestroyReason aWhy) override {} private: ~TransportProviderParent() = default; diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index b4969edfa152..8aa7533454ca 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -3719,7 +3719,8 @@ WebSocketChannel::OnTransportAvailable(nsISocketTransport* aTransport, return OnTransportAvailableInternal(); } -nsresult WebSocketChannel::OnWebSocketConnectionAvailable( +NS_IMETHODIMP +WebSocketChannel::OnWebSocketConnectionAvailable( WebSocketConnectionBase* aConnection) { if (!NS_IsMainThread()) { RefPtr self = this; diff --git a/netwerk/protocol/websocket/WebSocketChannel.h b/netwerk/protocol/websocket/WebSocketChannel.h index fb3567761887..b9a21f5761cc 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.h +++ b/netwerk/protocol/websocket/WebSocketChannel.h @@ -118,8 +118,6 @@ class WebSocketChannel : public BaseWebSocketChannel, bool IsEncrypted() const override; nsresult OnTransportAvailableInternal(); - nsresult OnWebSocketConnectionAvailable( - WebSocketConnectionBase* aConnection) override; void OnError(nsresult aStatus) override; void OnTCPClosed() override; nsresult OnDataReceived(uint8_t* aData, uint32_t aCount) override; diff --git a/netwerk/protocol/websocket/WebSocketConnectionChild.cpp b/netwerk/protocol/websocket/WebSocketConnectionChild.cpp index 7e0802165545..d914068dd12d 100644 --- a/netwerk/protocol/websocket/WebSocketConnectionChild.cpp +++ b/netwerk/protocol/websocket/WebSocketConnectionChild.cpp @@ -118,6 +118,12 @@ WebSocketConnectionChild::OnUpgradeFailed(nsresult aReason) { return NS_OK; } +NS_IMETHODIMP +WebSocketConnectionChild::OnWebSocketConnectionAvailable( + WebSocketConnectionBase* aConnection) { + return NS_ERROR_NOT_IMPLEMENTED; +} + mozilla::ipc::IPCResult WebSocketConnectionChild::RecvWriteOutputData( nsTArray&& aData) { LOG(("WebSocketConnectionChild::RecvWriteOutputData %p\n", this)); diff --git a/netwerk/protocol/websocket/WebSocketConnectionChild.h b/netwerk/protocol/websocket/WebSocketConnectionChild.h index db115322ddc4..a0f16b7fa85a 100644 --- a/netwerk/protocol/websocket/WebSocketConnectionChild.h +++ b/netwerk/protocol/websocket/WebSocketConnectionChild.h @@ -37,11 +37,6 @@ class WebSocketConnectionChild final : public PWebSocketConnectionChild, void ActorDestroy(ActorDestroyReason aWhy) override; - nsresult OnWebSocketConnectionAvailable( - WebSocketConnectionBase* aConnection) override { - return NS_ERROR_NOT_IMPLEMENTED; - } - void OnError(nsresult aStatus) override; void OnTCPClosed() override; nsresult OnDataReceived(uint8_t* aData, uint32_t aCount) override; diff --git a/storage/mozIStorageStatement.idl b/storage/mozIStorageStatement.idl index c791cf14933c..ad2821bb6ce9 100644 --- a/storage/mozIStorageStatement.idl +++ b/storage/mozIStorageStatement.idl @@ -255,7 +255,6 @@ interface mozIStorageStatement : mozIStorageBaseStatement { [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aByteLength, [shared,retval] out wstring aResult); [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aByteLength, [shared,retval] out octetPtr aResult); -%{C++ /** * Getters for native code that return their values as * the return type, for convenience and sanity. @@ -263,6 +262,7 @@ interface mozIStorageStatement : mozIStorageBaseStatement { * Not virtual; no vtable bloat. */ +%{C++ inline int32_t AsInt32(uint32_t idx) { int32_t v = 0; mozilla::DebugOnly rv = GetInt32(idx, &v); diff --git a/storage/mozIStorageValueArray.idl b/storage/mozIStorageValueArray.idl index 9d26e1b3edf1..98eeaaf551f4 100644 --- a/storage/mozIStorageValueArray.idl +++ b/storage/mozIStorageValueArray.idl @@ -82,7 +82,6 @@ interface mozIStorageValueArray : nsISupports { [noscript] void getSharedString(in unsigned long aIndex, out unsigned long aByteLength, [shared,retval] out wstring aResult); [noscript] void getSharedBlob(in unsigned long aIndex, out unsigned long aByteLength, [shared,retval] out octetPtr aResult); -%{C++ /** * Getters for native code that return their values as * the return type, for convenience and sanity. @@ -90,6 +89,7 @@ interface mozIStorageValueArray : nsISupports { * Not virtual; no vtable bloat. */ +%{C++ inline int32_t AsInt32(uint32_t idx) { int32_t v = 0; mozilla::DebugOnly rv = GetInt32(idx, &v); diff --git a/tools/profiler/gecko/nsIProfiler.idl b/tools/profiler/gecko/nsIProfiler.idl index bdd7511d78db..8b501d4b9f2b 100644 --- a/tools/profiler/gecko/nsIProfiler.idl +++ b/tools/profiler/gecko/nsIProfiler.idl @@ -14,6 +14,7 @@ [ref] native nsCString(const nsCString); [ref] native StringArrayRef(const nsTArray); +native ProfileDataBufferMozPromise(RefPtr, nsresult, true>>); /** * Start-up parameters for subprocesses are passed through nsIObserverService, @@ -203,7 +204,5 @@ interface nsIProfiler : nsISupports [implicit_jscontext] Promise getSymbolTable(in ACString aDebugPath, in ACString aBreakpadID); - %{C++ - virtual RefPtr, nsresult, true>> GetProfileDataAsGzippedArrayBufferAndroid(double aSinceTime) = 0; - %} + [notxpcom, nostdcall] ProfileDataBufferMozPromise getProfileDataAsGzippedArrayBufferAndroid(in double aSinceTime); }; diff --git a/tools/profiler/gecko/nsProfiler.h b/tools/profiler/gecko/nsProfiler.h index 1dcbbc7c2c5e..6fc1179645fe 100644 --- a/tools/profiler/gecko/nsProfiler.h +++ b/tools/profiler/gecko/nsProfiler.h @@ -60,9 +60,6 @@ class nsProfiler final : public nsIProfiler { RefPtr GetSymbolTableMozPromise( const nsACString& aDebugPath, const nsACString& aBreakpadID); - RefPtr - GetProfileDataAsGzippedArrayBufferAndroid(double aSinceTime) override; - struct ExitProfile { nsCString mJSON; uint64_t mBufferPositionAtGatherTime; diff --git a/widget/nsIPrintSettings.idl b/widget/nsIPrintSettings.idl index c2da8f122c4c..e40491808947 100644 --- a/widget/nsIPrintSettings.idl +++ b/widget/nsIPrintSettings.idl @@ -19,6 +19,7 @@ struct PrintSettingsInitializer; */ native nsNativeIntMargin(nsIntMargin); [ref] native nsNativeIntMarginRef(nsIntMargin); +native PrintSettingsInitializer(mozilla::PrintSettingsInitializer); interface nsIOutputStream; @@ -362,12 +363,12 @@ interface nsIPrintSettings : nsISupports */ attribute Array pageRanges; -%{C++ /** * Get a PrintSettingsInitializer populated with the relevant current settings. */ - virtual mozilla::PrintSettingsInitializer GetSettingsInitializer() = 0; + [notxpcom, nostdcall] PrintSettingsInitializer getSettingsInitializer(); +%{C++ static bool IsPageSkipped(int32_t aPageNum, const nsTArray& aRanges); %} }; diff --git a/widget/nsPrintSettingsImpl.h b/widget/nsPrintSettingsImpl.h index 2b43fad4a1dd..0f062b32d142 100644 --- a/widget/nsPrintSettingsImpl.h +++ b/widget/nsPrintSettingsImpl.h @@ -69,8 +69,6 @@ class nsPrintSettings : public nsIPrintSettings { */ virtual void InitWithInitializer(const PrintSettingsInitializer& aSettings); - PrintSettingsInitializer GetSettingsInitializer() final; - nsPrintSettings& operator=(const nsPrintSettings& rhs); // Sets a default file name for the print settings. diff --git a/xpcom/base/nsIWeakReference.idl b/xpcom/base/nsIWeakReference.idl index c55ccf13e143..723fa8434439 100644 --- a/xpcom/base/nsIWeakReference.idl +++ b/xpcom/base/nsIWeakReference.idl @@ -31,6 +31,8 @@ %} +native MallocSizeOf(mozilla::MallocSizeOf); + /** * An instance of |nsIWeakReference| is a proxy object that cooperates with * its referent to give clients a non-owning, non-dangling reference. Clients @@ -45,7 +47,7 @@ * @see nsWeakReference * @see nsWeakPtr */ -[scriptable, uuid(9188bc85-f92e-11d2-81ef-0060083a0bcf)] +[scriptable, builtinclass, uuid(9188bc85-f92e-11d2-81ef-0060083a0bcf)] interface nsIWeakReference : nsISupports { /** @@ -57,9 +59,8 @@ interface nsIWeakReference : nsISupports [binaryname(QueryReferentFromScript)] void QueryReferent( in nsIIDRef uuid, [iid_is(uuid), retval] out nsQIResult result ); + [notxpcom, nostdcall] size_t sizeOfOnlyThis(in MallocSizeOf aMallocSizeOf); %{C++ - virtual size_t SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; - /** * Returns true if the referring object is alive. Otherwise, false. */ diff --git a/xpcom/base/nsWeakReference.cpp b/xpcom/base/nsWeakReference.cpp index 6a37c8cb990e..bb9663fb9872 100644 --- a/xpcom/base/nsWeakReference.cpp +++ b/xpcom/base/nsWeakReference.cpp @@ -19,7 +19,6 @@ class nsWeakReference final : public nsIWeakReference { // nsIWeakReference... NS_DECL_NSIWEAKREFERENCE - size_t SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) const override; private: friend class nsSupportsWeakReference; @@ -147,8 +146,7 @@ nsresult nsIWeakReference::QueryReferent(const nsIID& aIID, return mObject->QueryInterface(aIID, aInstancePtr); } -size_t nsWeakReference::SizeOfOnlyThis( - mozilla::MallocSizeOf aMallocSizeOf) const { +size_t nsWeakReference::SizeOfOnlyThis(mozilla::MallocSizeOf aMallocSizeOf) { return aMallocSizeOf(this); } diff --git a/xpcom/base/nsrootidl.idl b/xpcom/base/nsrootidl.idl index 217c7f0ca5bf..107bb325cb65 100644 --- a/xpcom/base/nsrootidl.idl +++ b/xpcom/base/nsrootidl.idl @@ -48,9 +48,9 @@ typedef long long int64_t ; typedef unsigned long nsrefcnt ; typedef unsigned long nsresult ; -// XXX need this built into xpidl compiler so that it's really size_t or size_t -// and it's scriptable: -typedef unsigned long size_t; +// 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. + native size_t(size_t); [ptr] native voidPtr(void); [ptr] native charPtr(char); diff --git a/xpcom/ds/nsIPersistentProperties2.idl b/xpcom/ds/nsIPersistentProperties2.idl index d0158d6e5b48..02b6fcdc325c 100644 --- a/xpcom/ds/nsIPersistentProperties2.idl +++ b/xpcom/ds/nsIPersistentProperties2.idl @@ -13,13 +13,15 @@ interface nsISimpleEnumerator; #include "mozilla/MemoryReporting.h" %} +native MallocSizeOf(mozilla::MallocSizeOf); + [scriptable, uuid(283EE646-1AEF-11D4-98B3-00C04fA0CE9A)] interface nsIPropertyElement : nsISupports { attribute AUTF8String key; attribute AString value; }; -[scriptable, uuid(706867af-0400-4faa-beb1-0dae87308784)] +[scriptable, builtinclass, uuid(706867af-0400-4faa-beb1-0dae87308784)] interface nsIPersistentProperties : nsIProperties { /** @@ -53,8 +55,6 @@ interface nsIPersistentProperties : nsIProperties */ AString setStringProperty(in AUTF8String key, in AString value); -%{C++ - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; -%} + [notxpcom, nostdcall] size_t sizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); }; diff --git a/xpcom/ds/nsPersistentProperties.cpp b/xpcom/ds/nsPersistentProperties.cpp index e6dd02ae07f0..4e83870742b1 100644 --- a/xpcom/ds/nsPersistentProperties.cpp +++ b/xpcom/ds/nsPersistentProperties.cpp @@ -410,7 +410,7 @@ nsPersistentProperties::nsPersistentProperties() nsPersistentProperties::~nsPersistentProperties() = default; size_t nsPersistentProperties::SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const { + mozilla::MallocSizeOf aMallocSizeOf) { // The memory used by mTable is accounted for in mArena. size_t n = 0; n += mArena.SizeOfExcludingThis(aMallocSizeOf); diff --git a/xpcom/ds/nsPersistentProperties.h b/xpcom/ds/nsPersistentProperties.h index 7f3fa129cdaf..e35f93837101 100644 --- a/xpcom/ds/nsPersistentProperties.h +++ b/xpcom/ds/nsPersistentProperties.h @@ -24,9 +24,6 @@ class nsPersistentProperties final : public nsIPersistentProperties { NS_DECL_NSIPROPERTIES NS_DECL_NSIPERSISTENTPROPERTIES - size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override; - private: ~nsPersistentProperties(); diff --git a/xpcom/idl-parser/xpidl/xpidl.py b/xpcom/idl-parser/xpidl/xpidl.py index 758a44ce5604..38e284f5fa19 100755 --- a/xpcom/idl-parser/xpidl/xpidl.py +++ b/xpcom/idl-parser/xpidl/xpidl.py @@ -22,6 +22,7 @@ import re from ply import lex from ply import yacc import six +import textwrap from collections import namedtuple """A type conforms to the following pattern: @@ -311,17 +312,21 @@ class RustNoncompat(Exception): class IDLError(Exception): - def __init__(self, message, location, warning=False): + def __init__(self, message, location, warning=False, notes=None): self.message = message self.location = location self.warning = warning + self.notes = notes def __str__(self): - return "%s: %s, %s" % ( + error = "%s: %s, %s" % ( self.warning and "warning" or "error", self.message, self.location, ) + if self.notes is not None: + error += "\nnote: %s" % self.notes + return error class Include(object): @@ -431,7 +436,20 @@ class CDATA(object): self.location = location def resolve(self, parent): - pass + # This can be a false-positive if the word `virtual` is included in a + # comment, however this doesn't seem to happen very often. + if isinstance(parent, Interface) and re.search(r"\bvirtual\b", self.data): + raise IDLError( + "cannot declare a C++ `virtual` member in XPIDL interface", + self.location, + notes=textwrap.fill( + """All virtual members must be declared directly using XPIDL. + Both the Rust bindings and XPConnect rely on the per-platform + vtable layouts generated by the XPIDL compiler to allow + cross-language XPCOM method calls between JS and C++. + Consider using a `[notxpcom, nostdcall]` method instead.""" + ), + ) def __str__(self): return "cdata: %s\n\t%r\n" % (self.location.get(), self.data) diff --git a/xpcom/reflect/xptinfo/xptcodegen.py b/xpcom/reflect/xptinfo/xptcodegen.py index d933e93ddcfa..db34fb80a348 100644 --- a/xpcom/reflect/xptinfo/xptcodegen.py +++ b/xpcom/reflect/xptinfo/xptcodegen.py @@ -331,14 +331,21 @@ def link_to_cpp(interfaces, fd, header_fd): ) ) + def is_type_reflectable(type): + # All native types end up getting tagged as void*, or as wrapper types around void* + if type["tag"] == "TD_VOID": + return False + if type["tag"] in ("TD_ARRAY", "TD_LEGACY_ARRAY"): + return is_type_reflectable(type["element"]) + return True + def is_method_reflectable(method): if "hidden" in method["flags"]: return False for param in method["params"]: - # Reflected methods can't use native types. All native types end up - # getting tagged as void*, so this check is easy. - if param["type"]["tag"] == "TD_VOID": + # Reflected methods can't use non-reflectable types. + if not is_type_reflectable(param["type"]): return False return True diff --git a/xpcom/threads/nsITimer.idl b/xpcom/threads/nsITimer.idl index 8f862585d79c..16e9b4d36ad5 100644 --- a/xpcom/threads/nsITimer.idl +++ b/xpcom/threads/nsITimer.idl @@ -26,6 +26,7 @@ class nsITimer; typedef void (*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure); %} +native MallocSizeOf(mozilla::MallocSizeOf); native nsTimerCallbackFunc(nsTimerCallbackFunc); [ref] native TimeDuration(mozilla::TimeDuration); @@ -242,9 +243,7 @@ interface nsITimer : nsISupports */ [noscript] readonly attribute unsigned long allowedEarlyFiringMicroseconds; -%{C++ - virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; -%} + [notxpcom, nostdcall] size_t sizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); }; %{C++ diff --git a/xpcom/threads/nsTimerImpl.cpp b/xpcom/threads/nsTimerImpl.cpp index 302a867a27bc..7c22faabb103 100644 --- a/xpcom/threads/nsTimerImpl.cpp +++ b/xpcom/threads/nsTimerImpl.cpp @@ -781,7 +781,7 @@ void nsTimerImpl::SetHolder(nsTimerImplHolder* aHolder) { mHolder = aHolder; } nsTimer::~nsTimer() = default; -size_t nsTimer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const { +size_t nsTimer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) { return aMallocSizeOf(this); } diff --git a/xpcom/threads/nsTimerImpl.h b/xpcom/threads/nsTimerImpl.h index 1016100fed12..d8165dff843d 100644 --- a/xpcom/threads/nsTimerImpl.h +++ b/xpcom/threads/nsTimerImpl.h @@ -209,9 +209,6 @@ class nsTimer final : public nsITimer { : NS_ERROR_NULL_POINTER; } - virtual size_t SizeOfIncludingThis( - mozilla::MallocSizeOf aMallocSizeOf) const override; - // Create a timer targeting the given target. nullptr indicates that the // current thread should be used as the timer's target. static RefPtr WithEventTarget(nsIEventTarget* aTarget);