| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/src/./../../../../js/xpconnect/src/XPCJSWeakReference.cpp |
| Warning: | line 40, column 12 Value stored to 'rv' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | |
| 5 | #include "XPCJSWeakReference.h" |
| 6 | |
| 7 | #include "nsContentUtils.h" |
| 8 | #include "xpcprivate.h" |
| 9 | |
| 10 | using namespace JS; |
| 11 | |
| 12 | xpcJSWeakReference::xpcJSWeakReference() = default; |
| 13 | |
| 14 | NS_IMPL_ISUPPORTS(xpcJSWeakReference, xpcIJSWeakReference)MozExternalRefCountType xpcJSWeakReference::AddRef(void) { static_assert (!std::is_destructible_v<xpcJSWeakReference>, "Reference-counted class " "xpcJSWeakReference" " should not have a public destructor. " "Make this class's destructor non-public"); do { static_assert ( mozilla::detail::AssertionConditionType<decltype(int32_t (mRefCnt) >= 0)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(int32_t(mRefCnt) >= 0))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("int32_t(mRefCnt) >= 0" " (" "illegal refcnt" ")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp" , 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 14 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("xpcJSWeakReference" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("xpcJSWeakReference" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"xpcJSWeakReference\" != nullptr" " (" "Must specify a name" ")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp" , 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"xpcJSWeakReference\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 14); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("xpcJSWeakReference" " not thread-safe"); nsrefcnt count = ++ mRefCnt; NS_LogAddRef((this), (count), ("xpcJSWeakReference") , (uint32_t)(sizeof(*this))); return count; } MozExternalRefCountType xpcJSWeakReference::Release(void) { do { static_assert( mozilla ::detail::AssertionConditionType<decltype(int32_t(mRefCnt) > 0)>::isValid, "invalid assertion condition"); if ((__builtin_expect (!!(!(!!(int32_t(mRefCnt) > 0))), 0))) { do { } while (false ); MOZ_ReportAssertionFailure("int32_t(mRefCnt) > 0" " (" "dup release" ")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp" , 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 14) ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("xpcJSWeakReference" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("xpcJSWeakReference" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"xpcJSWeakReference\" != nullptr" " (" "Must specify a name" ")", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp" , 14); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"xpcJSWeakReference\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 14); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("xpcJSWeakReference" " not thread-safe"); const char* const nametmp = "xpcJSWeakReference"; nsrefcnt count = --mRefCnt; NS_LogRelease ((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult xpcJSWeakReference ::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "QueryInterface requires a non-NULL destination!", "aInstancePtr" , "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp", 14 ); MOZ_PretendNoReturn(); } } while (0); nsresult rv = NS_ERROR_FAILURE ; static_assert(1 > 0, "Need more arguments to NS_INTERFACE_TABLE" ); static const QITableEntry table[] = { {&mozilla::detail ::kImplementedIID<xpcJSWeakReference, xpcIJSWeakReference> , int32_t( reinterpret_cast<char*>(static_cast<xpcIJSWeakReference *>((xpcJSWeakReference*)0x1000)) - reinterpret_cast<char *>((xpcJSWeakReference*)0x1000))}, {&mozilla::detail:: kImplementedIID<xpcJSWeakReference, nsISupports>, int32_t (reinterpret_cast<char*>(static_cast<nsISupports*> ( static_cast<xpcIJSWeakReference*>((xpcJSWeakReference *)0x1000))) - reinterpret_cast<char*>((xpcJSWeakReference *)0x1000))}, { nullptr, 0 } } ; static_assert(std::size(table ) > 1, "need at least 1 interface"); rv = NS_TableDrivenQI (static_cast<void*>(this), aIID, aInstancePtr, table); return rv; } |
| 15 | |
| 16 | nsresult xpcJSWeakReference::Init(JSContext* cx, const JS::Value& object) { |
| 17 | if (!object.isObject()) { |
| 18 | return NS_OK; |
| 19 | } |
| 20 | |
| 21 | JS::RootedObject obj(cx, &object.toObject()); |
| 22 | |
| 23 | XPCCallContext ccx(cx); |
| 24 | |
| 25 | // See if the object is a wrapped native that supports weak references. |
| 26 | nsCOMPtr<nsISupports> supports = xpc::ReflectorToISupportsDynamic(obj, cx); |
| 27 | nsCOMPtr<nsISupportsWeakReference> supportsWeakRef = |
| 28 | do_QueryInterface(supports); |
| 29 | if (supportsWeakRef) { |
| 30 | supportsWeakRef->GetWeakReference(getter_AddRefs(mReferent)); |
| 31 | if (mReferent) { |
| 32 | return NS_OK; |
| 33 | } |
| 34 | } |
| 35 | // If it's not a wrapped native, or it is a wrapped native that does not |
| 36 | // support weak references, fall back to getting a weak ref to the object. |
| 37 | |
| 38 | // See if object is a wrapped JSObject. |
| 39 | RefPtr<nsXPCWrappedJS> wrapped; |
| 40 | nsresult rv = nsXPCWrappedJS::GetNewOrUsed(cx, obj, NS_GET_IID(nsISupports)(nsISupports::kIID), |
Value stored to 'rv' during its initialization is never read | |
| 41 | getter_AddRefs(wrapped)); |
| 42 | if (!wrapped) { |
| 43 | NS_ERROR("can't get nsISupportsWeakReference wrapper for obj")do { NS_DebugBreak(NS_DEBUG_ASSERTION, "can't get nsISupportsWeakReference wrapper for obj" , "Error", "./../../../../js/xpconnect/src/XPCJSWeakReference.cpp" , 43); MOZ_PretendNoReturn(); } while (0); |
| 44 | return rv; |
| 45 | } |
| 46 | |
| 47 | return wrapped->GetWeakReference(getter_AddRefs(mReferent)); |
| 48 | } |
| 49 | |
| 50 | NS_IMETHODIMPnsresult |
| 51 | xpcJSWeakReference::Get(JSContext* aCx, MutableHandleValue aRetval) { |
| 52 | aRetval.setNull(); |
| 53 | |
| 54 | if (!mReferent) { |
| 55 | return NS_OK; |
| 56 | } |
| 57 | |
| 58 | nsCOMPtr<nsISupports> supports = do_QueryReferent(mReferent); |
| 59 | if (!supports) { |
| 60 | return NS_OK; |
| 61 | } |
| 62 | |
| 63 | nsCOMPtr<nsIXPConnectWrappedJS> wrappedObj = do_QueryInterface(supports); |
| 64 | if (!wrappedObj) { |
| 65 | // We have a generic XPCOM object that supports weak references here. |
| 66 | // Wrap it and pass it out. |
| 67 | return nsContentUtils::WrapNative(aCx, supports, &NS_GET_IID(nsISupports)(nsISupports::kIID), |
| 68 | aRetval); |
| 69 | } |
| 70 | |
| 71 | JS::RootedObject obj(aCx, wrappedObj->GetJSObject()); |
| 72 | if (!obj) { |
| 73 | return NS_OK; |
| 74 | } |
| 75 | |
| 76 | // Most users of XPCWrappedJS don't need to worry about |
| 77 | // re-wrapping because things are implicitly rewrapped by |
| 78 | // xpcconvert. However, because we're doing this directly |
| 79 | // through the native call context, we need to call |
| 80 | // JS_WrapObject(). |
| 81 | if (!JS_WrapObject(aCx, &obj)) { |
| 82 | return NS_ERROR_FAILURE; |
| 83 | } |
| 84 | |
| 85 | aRetval.setObject(*obj); |
| 86 | return NS_OK; |
| 87 | } |