summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/components/native
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/xpconnect/tests/components/native
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/components/native')
-rw-r--r--js/xpconnect/tests/components/native/moz.build19
-rw-r--r--js/xpconnect/tests/components/native/xpctest_attributes.cpp136
-rw-r--r--js/xpconnect/tests/components/native/xpctest_cenums.cpp67
-rw-r--r--js/xpconnect/tests/components/native/xpctest_module.cpp80
-rw-r--r--js/xpconnect/tests/components/native/xpctest_params.cpp398
-rw-r--r--js/xpconnect/tests/components/native/xpctest_private.h92
-rw-r--r--js/xpconnect/tests/components/native/xpctest_returncode.cpp19
7 files changed, 811 insertions, 0 deletions
diff --git a/js/xpconnect/tests/components/native/moz.build b/js/xpconnect/tests/components/native/moz.build
new file mode 100644
index 0000000000..bda655aeb3
--- /dev/null
+++ b/js/xpconnect/tests/components/native/moz.build
@@ -0,0 +1,19 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+EXPORTS += [
+ "xpctest_private.h",
+]
+
+UNIFIED_SOURCES += [
+ "xpctest_attributes.cpp",
+ "xpctest_cenums.cpp",
+ "xpctest_module.cpp",
+ "xpctest_params.cpp",
+ "xpctest_returncode.cpp",
+]
+
+FINAL_LIBRARY = "xul"
diff --git a/js/xpconnect/tests/components/native/xpctest_attributes.cpp b/js/xpconnect/tests/components/native/xpctest_attributes.cpp
new file mode 100644
index 0000000000..180c1f7606
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_attributes.cpp
@@ -0,0 +1,136 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "xpctest_private.h"
+
+NS_IMPL_ISUPPORTS(xpcTestObjectReadOnly, nsIXPCTestObjectReadOnly)
+
+xpcTestObjectReadOnly ::xpcTestObjectReadOnly() {
+ boolProperty = true;
+ shortProperty = 32767;
+ longProperty = 2147483647;
+ floatProperty = 5.5f;
+ charProperty = 'X';
+ // timeProperty is PRTime and signed type.
+ // So it has to allow negative value.
+ timeProperty = -1;
+}
+
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetStrReadOnly(char** aStrReadOnly) {
+ if (!aStrReadOnly) return NS_ERROR_NULL_POINTER;
+ *aStrReadOnly = moz_xstrdup("XPConnect Read-Only String");
+ return NS_OK;
+}
+
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetBoolReadOnly(bool* aBoolReadOnly) {
+ *aBoolReadOnly = boolProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetShortReadOnly(
+ int16_t* aShortReadOnly) {
+ *aShortReadOnly = shortProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetLongReadOnly(int32_t* aLongReadOnly) {
+ *aLongReadOnly = longProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetFloatReadOnly(float* aFloatReadOnly) {
+ *aFloatReadOnly = floatProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetCharReadOnly(char* aCharReadOnly) {
+ *aCharReadOnly = charProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadOnly ::GetTimeReadOnly(PRTime* aTimeReadOnly) {
+ *aTimeReadOnly = timeProperty;
+ return NS_OK;
+}
+
+NS_IMPL_ISUPPORTS(xpcTestObjectReadWrite, nsIXPCTestObjectReadWrite)
+
+xpcTestObjectReadWrite ::xpcTestObjectReadWrite() {
+ stringProperty = moz_xstrdup("XPConnect Read-Writable String");
+ boolProperty = true;
+ shortProperty = 32767;
+ longProperty = 2147483647;
+ floatProperty = 5.5f;
+ charProperty = 'X';
+ // timeProperty is PRTime and signed type.
+ // So it has to allow negative value.
+ timeProperty = -1;
+}
+
+xpcTestObjectReadWrite ::~xpcTestObjectReadWrite() { free(stringProperty); }
+
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetStringProperty(
+ char** aStringProperty) {
+ if (!aStringProperty) {
+ return NS_ERROR_NULL_POINTER;
+ }
+ *aStringProperty = moz_xstrdup(stringProperty);
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetStringProperty(
+ const char* aStringProperty) {
+ free(stringProperty);
+ stringProperty = moz_xstrdup(aStringProperty);
+ return NS_OK;
+}
+
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetBooleanProperty(
+ bool* aBooleanProperty) {
+ *aBooleanProperty = boolProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetBooleanProperty(
+ bool aBooleanProperty) {
+ boolProperty = aBooleanProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetShortProperty(
+ int16_t* aShortProperty) {
+ *aShortProperty = shortProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetShortProperty(
+ int16_t aShortProperty) {
+ shortProperty = aShortProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetLongProperty(int32_t* aLongProperty) {
+ *aLongProperty = longProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetLongProperty(int32_t aLongProperty) {
+ longProperty = aLongProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetFloatProperty(float* aFloatProperty) {
+ *aFloatProperty = floatProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetFloatProperty(float aFloatProperty) {
+ floatProperty = aFloatProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetCharProperty(char* aCharProperty) {
+ *aCharProperty = charProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetCharProperty(char aCharProperty) {
+ charProperty = aCharProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::GetTimeProperty(PRTime* aTimeProperty) {
+ *aTimeProperty = timeProperty;
+ return NS_OK;
+}
+NS_IMETHODIMP xpcTestObjectReadWrite ::SetTimeProperty(PRTime aTimeProperty) {
+ timeProperty = aTimeProperty;
+ return NS_OK;
+}
diff --git a/js/xpconnect/tests/components/native/xpctest_cenums.cpp b/js/xpconnect/tests/components/native/xpctest_cenums.cpp
new file mode 100644
index 0000000000..ae72351b77
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_cenums.cpp
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* local header for xpconnect tests components */
+
+#include "xpctest_private.h"
+
+NS_IMPL_ISUPPORTS(xpcTestCEnums, nsIXPCTestCEnums)
+
+// If this compiles, we pass. Otherwise, this means that XPIDL bitflag
+// generation is broken.
+xpcTestCEnums::xpcTestCEnums() {
+ static_assert(
+ 0 == static_cast<uint32_t>(shouldBe0Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe0Implicit flag");
+ static_assert(
+ 1 == static_cast<uint32_t>(shouldBe1Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe1Implicit flag");
+ static_assert(
+ 2 == static_cast<uint32_t>(shouldBe2Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe2Implicit flag");
+ static_assert(
+ 3 == static_cast<uint32_t>(shouldBe3Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe3Implicit flag");
+ static_assert(
+ 5 == static_cast<uint32_t>(shouldBe5Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe5Implicit flag");
+ static_assert(
+ 6 == static_cast<uint32_t>(shouldBe6Implicit),
+ "XPIDL bitflag generation did not create correct shouldBe6Implicit flag");
+ static_assert(2 == static_cast<uint32_t>(shouldBe2AgainImplicit),
+ "XPIDL bitflag generation did not create correct "
+ "shouldBe2AgainImplicit flag");
+ static_assert(3 == static_cast<uint32_t>(shouldBe3AgainImplicit),
+ "XPIDL bitflag generation did not create correct "
+ "shouldBe3AgainImplicit flag");
+ static_assert(
+ 1 == static_cast<uint32_t>(shouldBe1Explicit),
+ "XPIDL bitflag generation did not create correct shouldBe1Explicit flag");
+ static_assert(
+ 2 == static_cast<uint32_t>(shouldBe2Explicit),
+ "XPIDL bitflag generation did not create correct shouldBe2Explicit flag");
+ static_assert(
+ 4 == static_cast<uint32_t>(shouldBe4Explicit),
+ "XPIDL bitflag generation did not create correct shouldBe4Explicit flag");
+ static_assert(
+ 8 == static_cast<uint32_t>(shouldBe8Explicit),
+ "XPIDL bitflag generation did not create correct shouldBe8Explicit flag");
+ static_assert(12 == static_cast<uint32_t>(shouldBe12Explicit),
+ "XPIDL bitflag generation did not create correct "
+ "shouldBe12Explicit flag");
+}
+
+nsresult xpcTestCEnums::TestCEnumInput(testFlagsExplicit a) {
+ if (a != shouldBe12Explicit) {
+ return NS_ERROR_FAILURE;
+ }
+ return NS_OK;
+}
+
+nsresult xpcTestCEnums::TestCEnumOutput(testFlagsExplicit* a) {
+ *a = shouldBe8Explicit;
+ return NS_OK;
+}
diff --git a/js/xpconnect/tests/components/native/xpctest_module.cpp b/js/xpconnect/tests/components/native/xpctest_module.cpp
new file mode 100644
index 0000000000..5fc61631b4
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_module.cpp
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* module registration and factory code. */
+
+#include "xpctest_private.h"
+
+#define NS_XPCTESTOBJECTREADONLY_CID \
+ { \
+ 0x492609a7, 0x2582, 0x436b, { \
+ 0xb0, 0xef, 0x92, 0xe2, 0x9b, 0xb9, 0xe1, 0x43 \
+ } \
+ }
+
+#define NS_XPCTESTOBJECTREADWRITE_CID \
+ { \
+ 0x8f37f760, 0x3686, 0x4dbb, { \
+ 0xb1, 0x21, 0x96, 0x93, 0xba, 0x81, 0x3f, 0x8f \
+ } \
+ }
+
+#define NS_XPCTESTPARAMS_CID \
+ { \
+ 0x1f11076a, 0x0fa2, 0x4f07, { \
+ 0xb4, 0x7a, 0xa1, 0x54, 0x31, 0xf2, 0xce, 0xf7 \
+ } \
+ }
+
+#define NS_XPCTESTRETURNCODEPARENT_CID \
+ { \
+ 0x3818f744, 0x5445, 0x4e9c, { \
+ 0x9b, 0xb8, 0x64, 0x62, 0xfe, 0x81, 0xb6, 0x19 \
+ } \
+ }
+
+#define NS_XPCTESTCENUMS_CID \
+ { \
+ 0x89ba673a, 0xa987, 0xb89c, { \
+ 0x92, 0x02, 0xb9, 0xc6, 0x23, 0x38, 0x64, 0x55 \
+ } \
+ }
+
+NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestCEnums)
+NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestObjectReadOnly)
+NS_GENERIC_FACTORY_CONSTRUCTOR(xpcTestObjectReadWrite)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCTestParams)
+NS_GENERIC_FACTORY_CONSTRUCTOR(nsXPCTestReturnCodeParent)
+NS_DEFINE_NAMED_CID(NS_XPCTESTOBJECTREADONLY_CID);
+NS_DEFINE_NAMED_CID(NS_XPCTESTOBJECTREADWRITE_CID);
+NS_DEFINE_NAMED_CID(NS_XPCTESTPARAMS_CID);
+NS_DEFINE_NAMED_CID(NS_XPCTESTRETURNCODEPARENT_CID);
+NS_DEFINE_NAMED_CID(NS_XPCTESTCENUMS_CID);
+
+static const mozilla::Module::CIDEntry kXPCTestCIDs[] = {
+ {&kNS_XPCTESTOBJECTREADONLY_CID, false, nullptr,
+ xpcTestObjectReadOnlyConstructor},
+ {&kNS_XPCTESTOBJECTREADWRITE_CID, false, nullptr,
+ xpcTestObjectReadWriteConstructor},
+ {&kNS_XPCTESTPARAMS_CID, false, nullptr, nsXPCTestParamsConstructor},
+ {&kNS_XPCTESTRETURNCODEPARENT_CID, false, nullptr,
+ nsXPCTestReturnCodeParentConstructor},
+ {&kNS_XPCTESTCENUMS_CID, false, nullptr, xpcTestCEnumsConstructor},
+ {nullptr}};
+
+static const mozilla::Module::ContractIDEntry kXPCTestContracts[] = {
+ {"@mozilla.org/js/xpc/test/native/CEnums;1", &kNS_XPCTESTCENUMS_CID},
+ {"@mozilla.org/js/xpc/test/native/ObjectReadOnly;1",
+ &kNS_XPCTESTOBJECTREADONLY_CID},
+ {"@mozilla.org/js/xpc/test/native/ObjectReadWrite;1",
+ &kNS_XPCTESTOBJECTREADWRITE_CID},
+ {"@mozilla.org/js/xpc/test/native/Params;1", &kNS_XPCTESTPARAMS_CID},
+ {"@mozilla.org/js/xpc/test/native/ReturnCodeParent;1",
+ &kNS_XPCTESTRETURNCODEPARENT_CID},
+ {nullptr}};
+
+const mozilla::Module kXPCTestModule = {mozilla::Module::kVersion, kXPCTestCIDs,
+ kXPCTestContracts};
diff --git a/js/xpconnect/tests/components/native/xpctest_params.cpp b/js/xpconnect/tests/components/native/xpctest_params.cpp
new file mode 100644
index 0000000000..e8c7b9787b
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_params.cpp
@@ -0,0 +1,398 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "xpctest_private.h"
+#include "xpctest_interfaces.h"
+#include "js/Value.h"
+
+#include "nsCOMPtr.h"
+#include "nsComponentManagerUtils.h"
+#include "nsIURI.h"
+
+NS_IMPL_ISUPPORTS(nsXPCTestParams, nsIXPCTestParams)
+
+#define GENERIC_METHOD_IMPL \
+ { \
+ *_retval = *b; \
+ *b = a; \
+ return NS_OK; \
+ }
+
+#define STRING_METHOD_IMPL \
+ { \
+ _retval.Assign(b); \
+ b.Assign(a); \
+ return NS_OK; \
+ }
+
+#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; \
+ }
+
+#define TAKE_OWNERSHIP_NOOP(val) \
+ {}
+#define TAKE_OWNERSHIP_INTERFACE(val) \
+ { static_cast<nsISupports*>(val)->AddRef(); }
+#define TAKE_OWNERSHIP_STRING(val) \
+ { \
+ nsDependentCString vprime(val); \
+ val = ToNewCString(vprime); \
+ }
+#define TAKE_OWNERSHIP_WSTRING(val) \
+ { \
+ nsDependentString vprime(val); \
+ val = ToNewUnicode(vprime); \
+ }
+
+// Macro for our buffer-oriented types:
+// 'type' is the type of element that the buffer contains.
+// 'padding' is an offset added to length, allowing us to handle
+// null-terminated strings.
+// 'TAKE_OWNERSHIP' is one of the macros above.
+#define BUFFER_METHOD_IMPL(type, padding, TAKE_OWNERSHIP) \
+ { \
+ uint32_t elemSize = sizeof(type); \
+ \
+ /* Copy b into rv. */ \
+ *rvLength = *bLength; \
+ *rv = static_cast<type*>(moz_xmalloc(elemSize * (*bLength + padding))); \
+ memcpy(*rv, *b, elemSize*(*bLength + padding)); \
+ \
+ /* Copy a into b. */ \
+ *bLength = aLength; \
+ free(*b); \
+ *b = static_cast<type*>(moz_xmalloc(elemSize * (aLength + padding))); \
+ memcpy(*b, a, elemSize*(aLength + padding)); \
+ \
+ /* We need to take ownership of the data we got from a, \
+ since the caller owns it. */ \
+ for (unsigned i = 0; i < *bLength + padding; ++i) TAKE_OWNERSHIP((*b)[i]); \
+ \
+ return NS_OK; \
+ }
+
+NS_IMETHODIMP nsXPCTestParams::TestBoolean(bool a, bool* b, bool* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestOctet(uint8_t a, uint8_t* b,
+ uint8_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestShort(int16_t a, int16_t* b,
+ int16_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestLong(int32_t a, int32_t* b,
+ int32_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestLongLong(int64_t a, int64_t* b,
+ int64_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestUnsignedShort(uint16_t a, uint16_t* b,
+ uint16_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestUnsignedLong(uint32_t a, uint32_t* b,
+ uint32_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestUnsignedLongLong(uint64_t a, uint64_t* b,
+ uint64_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestFloat(float a, float* b, float* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestDouble(double a, float* b, double* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestChar(char a, char* b, char* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestString(const char* a, char** b,
+ char** _retval) {
+ nsDependentCString aprime(a);
+ nsDependentCString bprime(*b);
+ *_retval = ToNewCString(bprime);
+ *b = ToNewCString(aprime);
+
+ // XPCOM ownership rules dictate that overwritten inout params must be
+ // callee-freed. See https://developer.mozilla.org/en/XPIDL
+ free(const_cast<char*>(bprime.get()));
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestWchar(char16_t a, char16_t* b,
+ char16_t* _retval) {
+ GENERIC_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestWstring(const char16_t* a, char16_t** b,
+ char16_t** _retval) {
+ nsDependentString aprime(a);
+ nsDependentString bprime(*b);
+ *_retval = ToNewUnicode(bprime);
+ *b = ToNewUnicode(aprime);
+
+ // XPCOM ownership rules dictate that overwritten inout params must be
+ // callee-freed. See https://developer.mozilla.org/en/XPIDL
+ free((void*)bprime.get());
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestAString(const nsAString& a, nsAString& b,
+ nsAString& _retval) {
+ STRING_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestAUTF8String(const nsACString& a,
+ nsACString& b,
+ nsACString& _retval) {
+ STRING_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestACString(const nsACString& a, nsACString& b,
+ nsACString& _retval) {
+ STRING_METHOD_IMPL;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestJsval(JS::Handle<JS::Value> a,
+ JS::MutableHandle<JS::Value> b,
+ JS::MutableHandle<JS::Value> _retval) {
+ _retval.set(b);
+ b.set(a);
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestShortArray(uint32_t aLength, int16_t* a,
+ uint32_t* bLength, int16_t** b,
+ uint32_t* rvLength,
+ int16_t** rv) {
+ BUFFER_METHOD_IMPL(int16_t, 0, TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestDoubleArray(uint32_t aLength, double* a,
+ uint32_t* bLength, double** b,
+ uint32_t* rvLength,
+ double** rv) {
+ BUFFER_METHOD_IMPL(double, 0, TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestStringArray(uint32_t aLength, const char** a,
+ uint32_t* bLength, char*** b,
+ uint32_t* rvLength, char*** rv) {
+ BUFFER_METHOD_IMPL(char*, 0, TAKE_OWNERSHIP_STRING);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestWstringArray(
+ uint32_t aLength, const char16_t** a, uint32_t* bLength, char16_t*** b,
+ uint32_t* rvLength, char16_t*** rv) {
+ BUFFER_METHOD_IMPL(char16_t*, 0, TAKE_OWNERSHIP_WSTRING);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestInterfaceArray(
+ uint32_t aLength, nsIXPCTestInterfaceA** a, uint32_t* bLength,
+ nsIXPCTestInterfaceA*** b, uint32_t* rvLength, nsIXPCTestInterfaceA*** rv) {
+ BUFFER_METHOD_IMPL(nsIXPCTestInterfaceA*, 0, TAKE_OWNERSHIP_INTERFACE);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestJsvalArray(uint32_t aLength, JS::Value* a,
+ uint32_t* bLength, JS::Value** b,
+ uint32_t* rvLength,
+ JS::Value** rv) {
+ BUFFER_METHOD_IMPL(JS::Value, 0, TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestSizedString(uint32_t aLength, const char* a,
+ uint32_t* bLength, char** b,
+ uint32_t* rvLength, char** rv) {
+ BUFFER_METHOD_IMPL(char, 1, TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestSizedWstring(uint32_t aLength,
+ const char16_t* a,
+ uint32_t* bLength, char16_t** b,
+ uint32_t* rvLength,
+ char16_t** rv) {
+ BUFFER_METHOD_IMPL(char16_t, 1, TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestInterfaceIs(const nsIID* aIID, void* a,
+ nsIID** bIID, void** b,
+ nsIID** rvIID, void** rv) {
+ //
+ // Getting the buffers and ownership right here can be a little tricky.
+ //
+
+ // The interface pointers are heap-allocated, and b has been AddRef'd
+ // by XPConnect for the duration of the call. If we snatch it away from b
+ // and leave no trace, XPConnect won't Release it. Since we also need to
+ // return an already-AddRef'd pointer in rv, we don't need to do anything
+ // special here.
+ *rv = *b;
+
+ // rvIID is out-only, so nobody allocated an IID buffer for us. Do that now,
+ // and store b's IID in the new buffer.
+ *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID)));
+ **rvIID = **bIID;
+
+ // Copy the interface pointer from a to b. Since a is in-only, XPConnect will
+ // release it upon completion of the call. AddRef it for b.
+ *b = a;
+ static_cast<nsISupports*>(*b)->AddRef();
+
+ // We already had a buffer allocated for b's IID, so we can re-use it.
+ **bIID = *aIID;
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestInterfaceIsArray(
+ uint32_t aLength, const nsIID* aIID, void** a, uint32_t* bLength,
+ nsIID** bIID, void*** b, uint32_t* rvLength, nsIID** rvIID, void*** rv) {
+ // Transfer the IIDs. See the comments in TestInterfaceIs (above) for an
+ // explanation of what we're doing.
+ *rvIID = static_cast<nsIID*>(moz_xmalloc(sizeof(nsID)));
+ **rvIID = **bIID;
+ **bIID = *aIID;
+
+ // The macro is agnostic to the actual interface types, so we can re-use code
+ // here.
+ //
+ // Do this second, since the macro returns.
+ BUFFER_METHOD_IMPL(void*, 0, TAKE_OWNERSHIP_INTERFACE);
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestOutAString(nsAString& o) {
+ o.AssignLiteral("out");
+ return NS_OK;
+}
+
+NS_IMETHODIMP nsXPCTestParams::TestStringArrayOptionalSize(const char** a,
+ uint32_t length,
+ nsACString& out) {
+ out.Truncate();
+ for (uint32_t i = 0; i < length; ++i) {
+ out.Append(a[i]);
+ }
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestShortSequence(const nsTArray<short>& a, nsTArray<short>& b,
+ nsTArray<short>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestDoubleSequence(const nsTArray<double>& a,
+ nsTArray<double>& b,
+ nsTArray<double>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestInterfaceSequence(
+ const nsTArray<RefPtr<nsIXPCTestInterfaceA>>& a,
+ nsTArray<RefPtr<nsIXPCTestInterfaceA>>& b,
+ nsTArray<RefPtr<nsIXPCTestInterfaceA>>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestAStringSequence(const nsTArray<nsString>& a,
+ nsTArray<nsString>& b,
+ nsTArray<nsString>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestACStringSequence(const nsTArray<nsCString>& a,
+ nsTArray<nsCString>& b,
+ nsTArray<nsCString>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestJsvalSequence(const nsTArray<JS::Value>& a,
+ nsTArray<JS::Value>& b,
+ nsTArray<JS::Value>& _retval) {
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestSequenceSequence(const nsTArray<nsTArray<short>>& a,
+ nsTArray<nsTArray<short>>& b,
+ nsTArray<nsTArray<short>>& _retval) {
+ _retval = std::move(b);
+ for (const auto& element : a) {
+ b.AppendElement(element.Clone());
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestInterfaceIsSequence(const nsIID* aIID,
+ const nsTArray<void*>& a, nsIID** bIID,
+ nsTArray<void*>& b, nsIID** rvIID,
+ nsTArray<void*>& _retval) {
+ // Shuffle around our nsIIDs
+ *rvIID = (*bIID)->Clone();
+ *bIID = aIID->Clone();
+
+ // Perform the generic sequence shuffle.
+ SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE);
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestOptionalSequence(const nsTArray<uint8_t>& aInArr,
+ nsTArray<uint8_t>& aReturnArr) {
+ aReturnArr = aInArr.Clone();
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXPCTestParams::TestOmittedOptionalOut(nsIURI** aOut) {
+ MOZ_ASSERT(!(*aOut), "Unexpected value received");
+ // Call the js component, to check XPConnect won't crash when passing nullptr
+ // as the optional out parameter, and that the out object is built regardless.
+ nsresult rv;
+ nsCOMPtr<nsIXPCTestParams> jsComponent =
+ do_CreateInstance("@mozilla.org/js/xpc/test/js/Params;1", &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
+ // Invoke it directly passing nullptr.
+ rv = jsComponent->TestOmittedOptionalOut(nullptr);
+ NS_ENSURE_SUCCESS(rv, rv);
+ // Also invoke it with a ref pointer.
+ nsCOMPtr<nsIURI> someURI;
+ rv = jsComponent->TestOmittedOptionalOut(getter_AddRefs(someURI));
+ NS_ENSURE_SUCCESS(rv, rv);
+ nsAutoCString spec;
+ rv = someURI->GetSpec(spec);
+ if (!spec.EqualsLiteral("http://example.com/")) {
+ return NS_ERROR_UNEXPECTED;
+ }
+ someURI.forget(aOut);
+ return NS_OK;
+}
diff --git a/js/xpconnect/tests/components/native/xpctest_private.h b/js/xpconnect/tests/components/native/xpctest_private.h
new file mode 100644
index 0000000000..371ccd6621
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_private.h
@@ -0,0 +1,92 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* local header for xpconnect tests components */
+
+#ifndef xpctest_private_h___
+#define xpctest_private_h___
+
+#include "nsISupports.h"
+#include "nsMemory.h"
+#include "nsString.h"
+#include "xpctest_attributes.h"
+#include "xpctest_params.h"
+#include "xpctest_returncode.h"
+#include "xpctest_cenums.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/ModuleUtils.h"
+
+extern const mozilla::Module kXPCTestModule;
+
+class xpcTestObjectReadOnly final : public nsIXPCTestObjectReadOnly {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTOBJECTREADONLY
+ xpcTestObjectReadOnly();
+
+ private:
+ ~xpcTestObjectReadOnly() = default;
+
+ bool boolProperty;
+ int16_t shortProperty;
+ int32_t longProperty;
+ float floatProperty;
+ char charProperty;
+ PRTime timeProperty;
+};
+
+class xpcTestObjectReadWrite final : public nsIXPCTestObjectReadWrite {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTOBJECTREADWRITE
+
+ xpcTestObjectReadWrite();
+
+ private:
+ ~xpcTestObjectReadWrite();
+
+ bool boolProperty;
+ int16_t shortProperty;
+ int32_t longProperty;
+ float floatProperty;
+ char charProperty;
+ char* stringProperty;
+ PRTime timeProperty;
+};
+
+class nsXPCTestParams final : public nsIXPCTestParams {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTPARAMS
+
+ nsXPCTestParams() = default;
+
+ private:
+ ~nsXPCTestParams() = default;
+};
+
+class nsXPCTestReturnCodeParent final : public nsIXPCTestReturnCodeParent {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTRETURNCODEPARENT
+
+ nsXPCTestReturnCodeParent() = default;
+
+ private:
+ ~nsXPCTestReturnCodeParent() = default;
+};
+
+class xpcTestCEnums final : public nsIXPCTestCEnums {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTCENUMS
+
+ xpcTestCEnums();
+
+ private:
+ ~xpcTestCEnums() = default;
+};
+#endif /* xpctest_private_h___ */
diff --git a/js/xpconnect/tests/components/native/xpctest_returncode.cpp b/js/xpconnect/tests/components/native/xpctest_returncode.cpp
new file mode 100644
index 0000000000..6b9b24a3cd
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_returncode.cpp
@@ -0,0 +1,19 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "xpctest_private.h"
+#include "nsComponentManagerUtils.h"
+
+NS_IMPL_ISUPPORTS(nsXPCTestReturnCodeParent, nsIXPCTestReturnCodeParent)
+
+NS_IMETHODIMP nsXPCTestReturnCodeParent::CallChild(int32_t childBehavior,
+ nsresult* _retval) {
+ nsresult rv;
+ nsCOMPtr<nsIXPCTestReturnCodeChild> child(
+ do_CreateInstance("@mozilla.org/js/xpc/test/js/ReturnCodeChild;1", &rv));
+ NS_ENSURE_SUCCESS(rv, rv);
+ rv = child->DoIt(childBehavior);
+ *_retval = rv;
+ return NS_OK;
+}