Bug Summary

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

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Unified_cpp_components_native0.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/tests/components/native -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/tests/components/native -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/stl_wrappers -D _GLIBCXX_ASSERTIONS=1 -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D MOZ_HAS_MOZGLUE -D MOZILLA_INTERNAL_API -D IMPL_LIBXUL -D MOZ_SUPPORT_LEAKCHECKING -D STATIC_EXPORTABLE_JS_API -I /root/firefox-clang/js/xpconnect/tests/components/native -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/js/xpconnect/tests/components/native -I /root/firefox-clang/xpcom/components -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/x86_64-linux-gnu/c++/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../include/c++/16/backward -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=pessimizing-move -Wno-error=large-by-value-copy=128 -Wno-error=implicit-int-float-conversion -Wno-error=thread-safety-analysis -Wno-error=tautological-type-limit-compare -Wno-invalid-offsetof -Wno-range-loop-analysis -Wno-deprecated-anon-enum-enum-conversion -Wno-deprecated-enum-enum-conversion -Wno-inline-new-delete -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-vla-cxx-extension -Wno-unknown-warning-option -Wno-character-conversion -std=gnu++20 -fdeprecated-macro -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fno-rtti -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fno-sized-deallocation -fno-aligned-allocation -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c++ Unified_cpp_components_native0.cpp
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
15using namespace mozilla;
16
17NS_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
86NS_IMETHODIMPnsresult nsXPCTestParams::TestBoolean(bool a, bool* b, bool* _retval) {
87 GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; };
88}
89
90NS_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
95NS_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
100NS_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
105NS_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
110NS_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
115NS_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
120NS_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
125NS_IMETHODIMPnsresult nsXPCTestParams::TestFloat(float a, float* b, float* _retval) {
126 GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; };
127}
128
129NS_IMETHODIMPnsresult nsXPCTestParams::TestDouble(double a, float* b, double* _retval) {
130 GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; };
131}
132
133NS_IMETHODIMPnsresult nsXPCTestParams::TestChar(char a, char* b, char* _retval) {
134 GENERIC_METHOD_IMPL{ *_retval = *b; *b = a; return NS_OK; };
135}
136
137NS_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
151NS_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
156NS_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
170NS_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
175NS_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
181NS_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
186NS_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
194NS_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
201NS_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
208NS_IMETHODIMPnsresult nsXPCTestParams::TestByteArrayOptionalLength(uint8_t* a,
209 uint32_t aLength,
210 uint32_t* rv) {
211 *rv = aLength;
212 return NS_OK;
213}
214
215NS_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
221NS_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
227NS_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
233NS_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
240NS_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
246NS_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
254NS_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
284NS_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
300NS_IMETHODIMPnsresult nsXPCTestParams::TestOutAString(nsAString& o) {
301 o.AssignLiteral("out");
302 return NS_OK;
303}
304
305NS_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
316NS_IMETHODIMPnsresult
317nsXPCTestParams::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
322NS_IMETHODIMPnsresult
323nsXPCTestParams::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
329NS_IMETHODIMPnsresult
330nsXPCTestParams::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
337NS_IMETHODIMPnsresult
338nsXPCTestParams::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
344NS_IMETHODIMPnsresult
345nsXPCTestParams::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
351NS_IMETHODIMPnsresult
352nsXPCTestParams::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
358NS_IMETHODIMPnsresult
359nsXPCTestParams::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
369NS_IMETHODIMPnsresult
370nsXPCTestParams::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
382NS_IMETHODIMPnsresult
383nsXPCTestParams::TestOptionalSequence(const nsTArray<uint8_t>& aInArr,
384 nsTArray<uint8_t>& aReturnArr) {
385 aReturnArr = aInArr.Clone();
386 return NS_OK;
387}
388
389NS_IMETHODIMPnsresult
390nsXPCTestParams::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
412NS_IMETHODIMPnsresult
413nsXPCTestParams::GetTestNaN(double* aResult) {
414 *aResult =
415 BitwiseCast<double>((uint64_t(JSVAL_TAG_OBJECT) << JSVAL_TAG_SHIFT47) + 1);
416 return NS_OK;
417}