| File: | root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/tests/components/native/./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp |
| Warning: | line 404, column 3 Value stored to 'rv' 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 "mozilla/Casting.h" |
| 6 | |
| 7 | #include "nsComponentManagerUtils.h" |
| 8 | #include "nsCOMPtr.h" |
| 9 | #include "nsIURI.h" |
| 10 | #include "xpctest_interfaces.h" |
| 11 | #include "xpctest_private.h" |
| 12 | |
| 13 | #include "js/Value.h" |
| 14 | |
| 15 | using namespace mozilla; |
| 16 | |
| 17 | NS_IMPL_ISUPPORTS(nsXPCTestParams, nsIXPCTestParams)MozExternalRefCountType nsXPCTestParams::AddRef(void) { static_assert (!std::is_destructible_v<nsXPCTestParams>, "Reference-counted class " "nsXPCTestParams" " 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/tests/components/native/xpctest_params.cpp" , 17); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) >= 0" ") (" "illegal refcnt" ")"); do { MOZ_CrashSequence(__null, 17 ); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsXPCTestParams" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsXPCTestParams" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"nsXPCTestParams\" != nullptr" " (" "Must specify a name" ")" , "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 17); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsXPCTestParams\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 17); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("nsXPCTestParams" " not thread-safe"); nsrefcnt count = ++mRefCnt ; NS_LogAddRef((this), (count), ("nsXPCTestParams"), (uint32_t )(sizeof(*this))); return count; } MozExternalRefCountType nsXPCTestParams ::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/tests/components/native/xpctest_params.cpp" , 17); AnnotateMozCrashReason("MOZ_ASSERT" "(" "int32_t(mRefCnt) > 0" ") (" "dup release" ")"); do { MOZ_CrashSequence(__null, 17) ; __attribute__((nomerge)) ::abort(); } while (false); } } while (false); do { static_assert( mozilla::detail::AssertionConditionType <decltype("nsXPCTestParams" != nullptr)>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!("nsXPCTestParams" != nullptr ))), 0))) { do { } while (false); MOZ_ReportAssertionFailure( "\"nsXPCTestParams\" != nullptr" " (" "Must specify a name" ")" , "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 17); AnnotateMozCrashReason("MOZ_ASSERT" "(" "\"nsXPCTestParams\" != nullptr" ") (" "Must specify a name" ")"); do { MOZ_CrashSequence(__null , 17); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); if (!mRefCnt.isThreadSafe) _mOwningThread.AssertOwnership ("nsXPCTestParams" " not thread-safe"); const char* const nametmp = "nsXPCTestParams"; nsrefcnt count = --mRefCnt; NS_LogRelease ((this), (count), (nametmp)); if (count == 0) { mRefCnt = 1; delete (this); return 0; } return count; } nsresult nsXPCTestParams ::QueryInterface(const nsIID& aIID, void** aInstancePtr) { do { if (!(aInstancePtr)) { NS_DebugBreak(NS_DEBUG_ASSERTION , "QueryInterface requires a non-NULL destination!", "aInstancePtr" , "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 17); 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<nsXPCTestParams, nsIXPCTestParams>, int32_t ( reinterpret_cast<char*>(static_cast<nsIXPCTestParams *>((nsXPCTestParams*)0x1000)) - reinterpret_cast<char*> ((nsXPCTestParams*)0x1000))}, {&mozilla::detail::kImplementedIID <nsXPCTestParams, nsISupports>, int32_t(reinterpret_cast <char*>(static_cast<nsISupports*>( static_cast< nsIXPCTestParams*>((nsXPCTestParams*)0x1000))) - reinterpret_cast <char*>((nsXPCTestParams*)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; } |
| 18 | |
| 19 | #define GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; } \ |
| 20 | { \ |
| 21 | *_retval = *b; \ |
| 22 | *b = a; \ |
| 23 | return NS_OK; \ |
| 24 | } |
| 25 | |
| 26 | #define STRING_METHOD_IMPL{ _retval.Assign(b); b.Assign(a); return NS_OK; } \ |
| 27 | { \ |
| 28 | _retval.Assign(b); \ |
| 29 | b.Assign(a); \ |
| 30 | return NS_OK; \ |
| 31 | } |
| 32 | |
| 33 | #define SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) TAKE_OWNERSHIP(b[i]); return NS_OK; } \ |
| 34 | { \ |
| 35 | _retval = std::move(b); \ |
| 36 | b = a.Clone(); \ |
| 37 | for (uint32_t i = 0; i < b.Length(); ++i) TAKE_OWNERSHIP(b[i]); \ |
| 38 | return NS_OK; \ |
| 39 | } |
| 40 | |
| 41 | #define TAKE_OWNERSHIP_NOOP(val){ } \ |
| 42 | { \ |
| 43 | } |
| 44 | #define TAKE_OWNERSHIP_INTERFACE(val){ static_cast<nsISupports*>(val)->AddRef(); } \ |
| 45 | { \ |
| 46 | static_cast<nsISupports*>(val)->AddRef(); \ |
| 47 | } |
| 48 | #define TAKE_OWNERSHIP_STRING(val){ nsDependentCString vprime(val); val = ToNewCString(vprime); } \ |
| 49 | { \ |
| 50 | nsDependentCString vprime(val); \ |
| 51 | val = ToNewCString(vprime); \ |
| 52 | } |
| 53 | #define TAKE_OWNERSHIP_WSTRING(val){ nsDependentString vprime(val); val = ToNewUnicode(vprime); } \ |
| 54 | { \ |
| 55 | nsDependentString vprime(val); \ |
| 56 | val = ToNewUnicode(vprime); \ |
| 57 | } |
| 58 | |
| 59 | // Macro for our buffer-oriented types: |
| 60 | // 'type' is the type of element that the buffer contains. |
| 61 | // 'padding' is an offset added to length, allowing us to handle |
| 62 | // null-terminated strings. |
| 63 | // 'TAKE_OWNERSHIP' is one of the macros above. |
| 64 | #define BUFFER_METHOD_IMPL(type, padding, TAKE_OWNERSHIP){ uint32_t elemSize = sizeof(type); *rvLength = *bLength; *rv = static_cast<type*>(moz_xmalloc(elemSize * (*bLength + padding))); memcpy(*rv, *b, elemSize * (*bLength + padding)) ; *bLength = aLength; free(*b); *b = static_cast<type*> (moz_xmalloc(elemSize * (aLength + padding))); memcpy(*b, a, elemSize * (aLength + padding)); for (unsigned i = 0; i < *bLength + padding; ++i) TAKE_OWNERSHIP((*b)[i]); return NS_OK; } \ |
| 65 | { \ |
| 66 | uint32_t elemSize = sizeof(type); \ |
| 67 | \ |
| 68 | /* Copy b into rv. */ \ |
| 69 | *rvLength = *bLength; \ |
| 70 | *rv = static_cast<type*>(moz_xmalloc(elemSize * (*bLength + padding))); \ |
| 71 | memcpy(*rv, *b, elemSize * (*bLength + padding)); \ |
| 72 | \ |
| 73 | /* Copy a into b. */ \ |
| 74 | *bLength = aLength; \ |
| 75 | free(*b); \ |
| 76 | *b = static_cast<type*>(moz_xmalloc(elemSize * (aLength + padding))); \ |
| 77 | memcpy(*b, a, elemSize * (aLength + padding)); \ |
| 78 | \ |
| 79 | /* We need to take ownership of the data we got from a, \ |
| 80 | since the caller owns it. */ \ |
| 81 | for (unsigned i = 0; i < *bLength + padding; ++i) TAKE_OWNERSHIP((*b)[i]); \ |
| 82 | \ |
| 83 | return NS_OK; \ |
| 84 | } |
| 85 | |
| 86 | NS_IMETHODIMPnsresult nsXPCTestParams::TestBoolean(bool a, bool* b, bool* _retval) { |
| 87 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 88 | } |
| 89 | |
| 90 | NS_IMETHODIMPnsresult nsXPCTestParams::TestOctet(uint8_t a, uint8_t* b, |
| 91 | uint8_t* _retval) { |
| 92 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 93 | } |
| 94 | |
| 95 | NS_IMETHODIMPnsresult nsXPCTestParams::TestShort(int16_t a, int16_t* b, |
| 96 | int16_t* _retval) { |
| 97 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 98 | } |
| 99 | |
| 100 | NS_IMETHODIMPnsresult nsXPCTestParams::TestLong(int32_t a, int32_t* b, |
| 101 | int32_t* _retval) { |
| 102 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 103 | } |
| 104 | |
| 105 | NS_IMETHODIMPnsresult nsXPCTestParams::TestLongLong(int64_t a, int64_t* b, |
| 106 | int64_t* _retval) { |
| 107 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 108 | } |
| 109 | |
| 110 | NS_IMETHODIMPnsresult nsXPCTestParams::TestUnsignedShort(uint16_t a, uint16_t* b, |
| 111 | uint16_t* _retval) { |
| 112 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 113 | } |
| 114 | |
| 115 | NS_IMETHODIMPnsresult nsXPCTestParams::TestUnsignedLong(uint32_t a, uint32_t* b, |
| 116 | uint32_t* _retval) { |
| 117 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 118 | } |
| 119 | |
| 120 | NS_IMETHODIMPnsresult nsXPCTestParams::TestUnsignedLongLong(uint64_t a, uint64_t* b, |
| 121 | uint64_t* _retval) { |
| 122 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 123 | } |
| 124 | |
| 125 | NS_IMETHODIMPnsresult nsXPCTestParams::TestFloat(float a, float* b, float* _retval) { |
| 126 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 127 | } |
| 128 | |
| 129 | NS_IMETHODIMPnsresult nsXPCTestParams::TestDouble(double a, float* b, double* _retval) { |
| 130 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 131 | } |
| 132 | |
| 133 | NS_IMETHODIMPnsresult nsXPCTestParams::TestChar(char a, char* b, char* _retval) { |
| 134 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 135 | } |
| 136 | |
| 137 | NS_IMETHODIMPnsresult nsXPCTestParams::TestString(const char* a, char** b, |
| 138 | char** _retval) { |
| 139 | nsDependentCString aprime(a); |
| 140 | nsDependentCString bprime(*b); |
| 141 | *_retval = ToNewCString(bprime); |
| 142 | *b = ToNewCString(aprime); |
| 143 | |
| 144 | // XPCOM ownership rules dictate that overwritten inout params must be |
| 145 | // callee-freed. See https://developer.mozilla.org/en/XPIDL |
| 146 | free(const_cast<char*>(bprime.get())); |
| 147 | |
| 148 | return NS_OK; |
| 149 | } |
| 150 | |
| 151 | NS_IMETHODIMPnsresult nsXPCTestParams::TestWchar(char16_t a, char16_t* b, |
| 152 | char16_t* _retval) { |
| 153 | GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; }; |
| 154 | } |
| 155 | |
| 156 | NS_IMETHODIMPnsresult nsXPCTestParams::TestWstring(const char16_t* a, char16_t** b, |
| 157 | char16_t** _retval) { |
| 158 | nsDependentString aprime(a); |
| 159 | nsDependentString bprime(*b); |
| 160 | *_retval = ToNewUnicode(bprime); |
| 161 | *b = ToNewUnicode(aprime); |
| 162 | |
| 163 | // XPCOM ownership rules dictate that overwritten inout params must be |
| 164 | // callee-freed. See https://developer.mozilla.org/en/XPIDL |
| 165 | free((void*)bprime.get()); |
| 166 | |
| 167 | return NS_OK; |
| 168 | } |
| 169 | |
| 170 | NS_IMETHODIMPnsresult nsXPCTestParams::TestAString(const nsAString& a, nsAString& b, |
| 171 | nsAString& _retval) { |
| 172 | STRING_METHOD_IMPL{ _retval.Assign(b); b.Assign(a); return NS_OK; }; |
| 173 | } |
| 174 | |
| 175 | NS_IMETHODIMPnsresult nsXPCTestParams::TestAUTF8String(const nsACString& a, |
| 176 | nsACString& b, |
| 177 | nsACString& _retval) { |
| 178 | STRING_METHOD_IMPL{ _retval.Assign(b); b.Assign(a); return NS_OK; }; |
| 179 | } |
| 180 | |
| 181 | NS_IMETHODIMPnsresult nsXPCTestParams::TestACString(const nsACString& a, nsACString& b, |
| 182 | nsACString& _retval) { |
| 183 | STRING_METHOD_IMPL{ _retval.Assign(b); b.Assign(a); return NS_OK; }; |
| 184 | } |
| 185 | |
| 186 | NS_IMETHODIMPnsresult nsXPCTestParams::TestJsval(JS::Handle<JS::Value> a, |
| 187 | JS::MutableHandle<JS::Value> b, |
| 188 | JS::MutableHandle<JS::Value> _retval) { |
| 189 | _retval.set(b); |
| 190 | b.set(a); |
| 191 | return NS_OK; |
| 192 | } |
| 193 | |
| 194 | NS_IMETHODIMPnsresult nsXPCTestParams::TestShortArray(uint32_t aLength, int16_t* a, |
| 195 | uint32_t* bLength, int16_t** b, |
| 196 | uint32_t* rvLength, |
| 197 | int16_t** rv) { |
| 198 | BUFFER_METHOD_IMPL(int16_t, 0, TAKE_OWNERSHIP_NOOP){ uint32_t elemSize = sizeof(int16_t); *rvLength = *bLength; * rv = static_cast<int16_t*>(moz_xmalloc(elemSize * (*bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); *bLength = aLength; free(*b); *b = static_cast<int16_t*>(moz_xmalloc (elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++i) { }; return NS_OK; }; |
| 199 | } |
| 200 | |
| 201 | NS_IMETHODIMPnsresult nsXPCTestParams::TestDoubleArray(uint32_t aLength, double* a, |
| 202 | uint32_t* bLength, double** b, |
| 203 | uint32_t* rvLength, |
| 204 | double** rv) { |
| 205 | BUFFER_METHOD_IMPL(double, 0, TAKE_OWNERSHIP_NOOP){ uint32_t elemSize = sizeof(double); *rvLength = *bLength; * rv = static_cast<double*>(moz_xmalloc(elemSize * (*bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); *bLength = aLength; free(*b); *b = static_cast<double*>(moz_xmalloc (elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++i) { }; return NS_OK; }; |
| 206 | } |
| 207 | |
| 208 | NS_IMETHODIMPnsresult nsXPCTestParams::TestByteArrayOptionalLength(uint8_t* a, |
| 209 | uint32_t aLength, |
| 210 | uint32_t* rv) { |
| 211 | *rv = aLength; |
| 212 | return NS_OK; |
| 213 | } |
| 214 | |
| 215 | NS_IMETHODIMPnsresult nsXPCTestParams::TestStringArray(uint32_t aLength, const char** a, |
| 216 | uint32_t* bLength, char*** b, |
| 217 | uint32_t* rvLength, char*** rv) { |
| 218 | BUFFER_METHOD_IMPL(char*, 0, TAKE_OWNERSHIP_STRING){ uint32_t elemSize = sizeof(char*); *rvLength = *bLength; *rv = static_cast<char**>(moz_xmalloc(elemSize * (*bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); *bLength = aLength; free(*b); *b = static_cast<char**>(moz_xmalloc (elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++i) { nsDependentCString vprime((*b)[i]); (*b)[i] = ToNewCString(vprime); }; return NS_OK ; }; |
| 219 | } |
| 220 | |
| 221 | NS_IMETHODIMPnsresult nsXPCTestParams::TestWstringArray( |
| 222 | uint32_t aLength, const char16_t** a, uint32_t* bLength, char16_t*** b, |
| 223 | uint32_t* rvLength, char16_t*** rv) { |
| 224 | BUFFER_METHOD_IMPL(char16_t*, 0, TAKE_OWNERSHIP_WSTRING){ uint32_t elemSize = sizeof(char16_t*); *rvLength = *bLength ; *rv = static_cast<char16_t**>(moz_xmalloc(elemSize * ( *bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); * bLength = aLength; free(*b); *b = static_cast<char16_t**> (moz_xmalloc(elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++ i) { nsDependentString vprime((*b)[i]); (*b)[i] = ToNewUnicode (vprime); }; return NS_OK; }; |
| 225 | } |
| 226 | |
| 227 | NS_IMETHODIMPnsresult nsXPCTestParams::TestInterfaceArray( |
| 228 | uint32_t aLength, nsIXPCTestInterfaceA** a, uint32_t* bLength, |
| 229 | nsIXPCTestInterfaceA*** b, uint32_t* rvLength, nsIXPCTestInterfaceA*** rv) { |
| 230 | BUFFER_METHOD_IMPL(nsIXPCTestInterfaceA*, 0, TAKE_OWNERSHIP_INTERFACE){ uint32_t elemSize = sizeof(nsIXPCTestInterfaceA*); *rvLength = *bLength; *rv = static_cast<nsIXPCTestInterfaceA**>( moz_xmalloc(elemSize * (*bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); *bLength = aLength; free(*b); *b = static_cast <nsIXPCTestInterfaceA**>(moz_xmalloc(elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++i) { static_cast<nsISupports *>((*b)[i])->AddRef(); }; return NS_OK; }; |
| 231 | } |
| 232 | |
| 233 | NS_IMETHODIMPnsresult nsXPCTestParams::TestJsvalArray(uint32_t aLength, JS::Value* a, |
| 234 | uint32_t* bLength, JS::Value** b, |
| 235 | uint32_t* rvLength, |
| 236 | JS::Value** rv) { |
| 237 | BUFFER_METHOD_IMPL(JS::Value, 0, TAKE_OWNERSHIP_NOOP){ uint32_t elemSize = sizeof(JS::Value); *rvLength = *bLength ; *rv = static_cast<JS::Value*>(moz_xmalloc(elemSize * ( *bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); * bLength = aLength; free(*b); *b = static_cast<JS::Value*> (moz_xmalloc(elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++ i) { }; return NS_OK; }; |
| 238 | } |
| 239 | |
| 240 | NS_IMETHODIMPnsresult nsXPCTestParams::TestSizedString(uint32_t aLength, const char* a, |
| 241 | uint32_t* bLength, char** b, |
| 242 | uint32_t* rvLength, char** rv) { |
| 243 | BUFFER_METHOD_IMPL(char, 1, TAKE_OWNERSHIP_NOOP){ uint32_t elemSize = sizeof(char); *rvLength = *bLength; *rv = static_cast<char*>(moz_xmalloc(elemSize * (*bLength + 1))); memcpy(*rv, *b, elemSize * (*bLength + 1)); *bLength = aLength; free(*b); *b = static_cast<char*>(moz_xmalloc (elemSize * (aLength + 1))); memcpy(*b, a, elemSize * (aLength + 1)); for (unsigned i = 0; i < *bLength + 1; ++i) { }; return NS_OK; }; |
| 244 | } |
| 245 | |
| 246 | NS_IMETHODIMPnsresult nsXPCTestParams::TestSizedWstring(uint32_t aLength, |
| 247 | const char16_t* a, |
| 248 | uint32_t* bLength, char16_t** b, |
| 249 | uint32_t* rvLength, |
| 250 | char16_t** rv) { |
| 251 | BUFFER_METHOD_IMPL(char16_t, 1, TAKE_OWNERSHIP_NOOP){ uint32_t elemSize = sizeof(char16_t); *rvLength = *bLength; *rv = static_cast<char16_t*>(moz_xmalloc(elemSize * (* bLength + 1))); memcpy(*rv, *b, elemSize * (*bLength + 1)); * bLength = aLength; free(*b); *b = static_cast<char16_t*> (moz_xmalloc(elemSize * (aLength + 1))); memcpy(*b, a, elemSize * (aLength + 1)); for (unsigned i = 0; i < *bLength + 1; ++ i) { }; return NS_OK; }; |
| 252 | } |
| 253 | |
| 254 | NS_IMETHODIMPnsresult nsXPCTestParams::TestInterfaceIs(const nsIID* aIID, void* a, |
| 255 | nsIID** bIID, void** b, |
| 256 | nsIID** rvIID, void** rv) { |
| 257 | // |
| 258 | // Getting the buffers and ownership right here can be a little tricky. |
| 259 | // |
| 260 | |
| 261 | // The interface pointers are heap-allocated, and b has been AddRef'd |
| 262 | // by XPConnect for the duration of the call. If we snatch it away from b |
| 263 | // and leave no trace, XPConnect won't Release it. Since we also need to |
| 264 | // return an already-AddRef'd pointer in rv, we don't need to do anything |
| 265 | // special here. |
| 266 | *rv = *b; |
| 267 | |
| 268 | // rvIID is out-only, so nobody allocated an IID buffer for us. Do that now, |
| 269 | // and store b's IID in the new buffer. |
| 270 | *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID))); |
| 271 | **rvIID = **bIID; |
| 272 | |
| 273 | // Copy the interface pointer from a to b. Since a is in-only, XPConnect will |
| 274 | // release it upon completion of the call. AddRef it for b. |
| 275 | *b = a; |
| 276 | static_cast<nsISupports*>(*b)->AddRef(); |
| 277 | |
| 278 | // We already had a buffer allocated for b's IID, so we can re-use it. |
| 279 | **bIID = *aIID; |
| 280 | |
| 281 | return NS_OK; |
| 282 | } |
| 283 | |
| 284 | NS_IMETHODIMPnsresult nsXPCTestParams::TestInterfaceIsArray( |
| 285 | uint32_t aLength, const nsIID* aIID, void** a, uint32_t* bLength, |
| 286 | nsIID** bIID, void*** b, uint32_t* rvLength, nsIID** rvIID, void*** rv) { |
| 287 | // Transfer the IIDs. See the comments in TestInterfaceIs (above) for an |
| 288 | // explanation of what we're doing. |
| 289 | *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID))); |
| 290 | **rvIID = **bIID; |
| 291 | **bIID = *aIID; |
| 292 | |
| 293 | // The macro is agnostic to the actual interface types, so we can re-use code |
| 294 | // here. |
| 295 | // |
| 296 | // Do this second, since the macro returns. |
| 297 | BUFFER_METHOD_IMPL(void*, 0, TAKE_OWNERSHIP_INTERFACE){ uint32_t elemSize = sizeof(void*); *rvLength = *bLength; *rv = static_cast<void**>(moz_xmalloc(elemSize * (*bLength + 0))); memcpy(*rv, *b, elemSize * (*bLength + 0)); *bLength = aLength; free(*b); *b = static_cast<void**>(moz_xmalloc (elemSize * (aLength + 0))); memcpy(*b, a, elemSize * (aLength + 0)); for (unsigned i = 0; i < *bLength + 0; ++i) { static_cast <nsISupports*>((*b)[i])->AddRef(); }; return NS_OK; }; |
| 298 | } |
| 299 | |
| 300 | NS_IMETHODIMPnsresult nsXPCTestParams::TestOutAString(nsAString& o) { |
| 301 | o.AssignLiteral("out"); |
| 302 | return NS_OK; |
| 303 | } |
| 304 | |
| 305 | NS_IMETHODIMPnsresult nsXPCTestParams::TestStringArrayOptionalSize(const char** a, |
| 306 | uint32_t length, |
| 307 | nsACString& out) { |
| 308 | out.Truncate(); |
| 309 | for (uint32_t i = 0; i < length; ++i) { |
| 310 | out.Append(a[i]); |
| 311 | } |
| 312 | |
| 313 | return NS_OK; |
| 314 | } |
| 315 | |
| 316 | NS_IMETHODIMPnsresult |
| 317 | nsXPCTestParams::TestShortSequence(const nsTArray<short>& a, nsTArray<short>& b, |
| 318 | nsTArray<short>& _retval) { |
| 319 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 320 | } |
| 321 | |
| 322 | NS_IMETHODIMPnsresult |
| 323 | nsXPCTestParams::TestDoubleSequence(const nsTArray<double>& a, |
| 324 | nsTArray<double>& b, |
| 325 | nsTArray<double>& _retval) { |
| 326 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 327 | } |
| 328 | |
| 329 | NS_IMETHODIMPnsresult |
| 330 | nsXPCTestParams::TestInterfaceSequence( |
| 331 | const nsTArray<RefPtr<nsIXPCTestInterfaceA>>& a, |
| 332 | nsTArray<RefPtr<nsIXPCTestInterfaceA>>& b, |
| 333 | nsTArray<RefPtr<nsIXPCTestInterfaceA>>& _retval) { |
| 334 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 335 | } |
| 336 | |
| 337 | NS_IMETHODIMPnsresult |
| 338 | nsXPCTestParams::TestAStringSequence(const nsTArray<nsString>& a, |
| 339 | nsTArray<nsString>& b, |
| 340 | nsTArray<nsString>& _retval) { |
| 341 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 342 | } |
| 343 | |
| 344 | NS_IMETHODIMPnsresult |
| 345 | nsXPCTestParams::TestACStringSequence(const nsTArray<nsCString>& a, |
| 346 | nsTArray<nsCString>& b, |
| 347 | nsTArray<nsCString>& _retval) { |
| 348 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 349 | } |
| 350 | |
| 351 | NS_IMETHODIMPnsresult |
| 352 | nsXPCTestParams::TestJsvalSequence(const nsTArray<JS::Value>& a, |
| 353 | nsTArray<JS::Value>& b, |
| 354 | nsTArray<JS::Value>& _retval) { |
| 355 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { }; return NS_OK; }; |
| 356 | } |
| 357 | |
| 358 | NS_IMETHODIMPnsresult |
| 359 | nsXPCTestParams::TestSequenceSequence(const nsTArray<nsTArray<short>>& a, |
| 360 | nsTArray<nsTArray<short>>& b, |
| 361 | nsTArray<nsTArray<short>>& _retval) { |
| 362 | _retval = std::move(b); |
| 363 | for (const auto& element : a) { |
| 364 | b.AppendElement(element.Clone()); |
| 365 | } |
| 366 | return NS_OK; |
| 367 | } |
| 368 | |
| 369 | NS_IMETHODIMPnsresult |
| 370 | nsXPCTestParams::TestInterfaceIsSequence(const nsIID* aIID, |
| 371 | const nsTArray<void*>& a, nsIID** bIID, |
| 372 | nsTArray<void*>& b, nsIID** rvIID, |
| 373 | nsTArray<void*>& _retval) { |
| 374 | // Shuffle around our nsIIDs |
| 375 | *rvIID = (*bIID)->Clone(); |
| 376 | *bIID = aIID->Clone(); |
| 377 | |
| 378 | // Perform the generic sequence shuffle. |
| 379 | SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE){ _retval = std::move(b); b = a.Clone(); for (uint32_t i = 0; i < b.Length(); ++i) { static_cast<nsISupports*>(b[ i])->AddRef(); }; return NS_OK; }; |
| 380 | } |
| 381 | |
| 382 | NS_IMETHODIMPnsresult |
| 383 | nsXPCTestParams::TestOptionalSequence(const nsTArray<uint8_t>& aInArr, |
| 384 | nsTArray<uint8_t>& aReturnArr) { |
| 385 | aReturnArr = aInArr.Clone(); |
| 386 | return NS_OK; |
| 387 | } |
| 388 | |
| 389 | NS_IMETHODIMPnsresult |
| 390 | nsXPCTestParams::TestOmittedOptionalOut(nsIXPCTestParams* aJSObj, |
| 391 | nsIURI** aOut) { |
| 392 | MOZ_ASSERT(!(*aOut), "Unexpected value received")do { static_assert( mozilla::detail::AssertionConditionType< decltype(!(*aOut))>::isValid, "invalid assertion condition" ); if ((__builtin_expect(!!(!(!!(!(*aOut)))), 0))) { do { } while (false); MOZ_ReportAssertionFailure("!(*aOut)" " (" "Unexpected value received" ")", "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 392); AnnotateMozCrashReason("MOZ_ASSERT" "(" "!(*aOut)" ") (" "Unexpected value received" ")"); do { MOZ_CrashSequence(__null , 392); __attribute__((nomerge)) ::abort(); } while (false); } } while (false); |
| 393 | // Call the js component, to check XPConnect won't crash when passing nullptr |
| 394 | // as the optional out parameter, and that the out object is built regardless. |
| 395 | nsresult rv; |
| 396 | // Invoke it directly passing nullptr. |
| 397 | rv = aJSObj->TestOmittedOptionalOut(nullptr, nullptr); |
| 398 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 398); return rv; } } while (false); |
| 399 | // Also invoke it with a ref pointer. |
| 400 | nsCOMPtr<nsIURI> someURI; |
| 401 | rv = aJSObj->TestOmittedOptionalOut(nullptr, getter_AddRefs(someURI)); |
| 402 | NS_ENSURE_SUCCESS(rv, rv)do { nsresult __rv = rv; if (((bool)(__builtin_expect(!!(NS_FAILED_impl (__rv)), 0)))) { const char* name = mozilla::GetStaticErrorName (__rv); mozilla::SmprintfPointer msg = mozilla::Smprintf( "NS_ENSURE_SUCCESS(%s, %s) failed with " "result 0x%" "X" "%s%s%s", "rv", "rv", static_cast<uint32_t >(__rv), name ? " (" : "", name ? name : "", name ? ")" : "" ); NS_DebugBreak(NS_DEBUG_WARNING, msg.get(), nullptr, "./../../../../../../js/xpconnect/tests/components/native/xpctest_params.cpp" , 402); return rv; } } while (false); |
| 403 | nsAutoCString spec; |
| 404 | rv = someURI->GetSpec(spec); |
Value stored to 'rv' is never read | |
| 405 | if (!spec.EqualsLiteral("http://example.com/")) { |
| 406 | return NS_ERROR_UNEXPECTED; |
| 407 | } |
| 408 | someURI.forget(aOut); |
| 409 | return NS_OK; |
| 410 | } |
| 411 | |
| 412 | NS_IMETHODIMPnsresult |
| 413 | nsXPCTestParams::GetTestNaN(double* aResult) { |
| 414 | *aResult = |
| 415 | BitwiseCast<double>((uint64_t(JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT47) + 1); |
| 416 | return NS_OK; |
| 417 | } |