summaryrefslogtreecommitdiffstats
path: root/js/xpconnect/tests/components
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/xpconnect/tests/components
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/xpconnect/tests/components')
-rw-r--r--js/xpconnect/tests/components/js/xpctest.manifest28
-rw-r--r--js/xpconnect/tests/components/js/xpctest_attributes.js48
-rw-r--r--js/xpconnect/tests/components/js/xpctest_bug809674.js19
-rw-r--r--js/xpconnect/tests/components/js/xpctest_interfaces.js48
-rw-r--r--js/xpconnect/tests/components/js/xpctest_params.js85
-rw-r--r--js/xpconnect/tests/components/js/xpctest_returncode_child.js49
-rw-r--r--js/xpconnect/tests/components/js/xpctest_utils.js17
-rw-r--r--js/xpconnect/tests/components/native/moz.build19
-rw-r--r--js/xpconnect/tests/components/native/xpctest.manifest1
-rw-r--r--js/xpconnect/tests/components/native/xpctest_attributes.cpp139
-rw-r--r--js/xpconnect/tests/components/native/xpctest_module.cpp59
-rw-r--r--js/xpconnect/tests/components/native/xpctest_params.cpp308
-rw-r--r--js/xpconnect/tests/components/native/xpctest_private.h80
-rw-r--r--js/xpconnect/tests/components/native/xpctest_returncode.cpp27
14 files changed, 927 insertions, 0 deletions
diff --git a/js/xpconnect/tests/components/js/xpctest.manifest b/js/xpconnect/tests/components/js/xpctest.manifest
new file mode 100644
index 000000000..ba28bf141
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest.manifest
@@ -0,0 +1,28 @@
+component {8ff41d9c-66e9-4453-924a-7d8de0a5e966} xpctest_attributes.js
+contract @mozilla.org/js/xpc/test/js/ObjectReadWrite;1 {8ff41d9c-66e9-4453-924a-7d8de0a5e966}
+
+component {916c4247-253d-4ed0-a425-adfedf53ecc8} xpctest_attributes.js
+contract @mozilla.org/js/xpc/test/js/ObjectReadOnly;1 {916c4247-253d-4ed0-a425-adfedf53ecc8}
+
+component {2df46559-da21-49bf-b863-0d7b7bbcbc73} xpctest_bug809674.js
+contract @mozilla.org/js/xpc/test/js/Bug809674;1 {2df46559-da21-49bf-b863-0d7b7bbcbc73}
+
+component {e3b86f4e-49c0-487c-a2b0-3a986720a044} xpctest_params.js
+contract @mozilla.org/js/xpc/test/js/Params;1 {e3b86f4e-49c0-487c-a2b0-3a986720a044}
+
+component {3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8} xpctest_interfaces.js
+contract @mozilla.org/js/xpc/test/js/InterfaceA;1 {3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8}
+
+component {ff528c3a-2410-46de-acaa-449aa6403a33} xpctest_interfaces.js
+contract @mozilla.org/js/xpc/test/js/InterfaceB;1 {ff528c3a-2410-46de-acaa-449aa6403a33}
+
+component {90ec5c9e-f6da-406b-9a38-14d00f59db76} xpctest_interfaces.js
+contract @mozilla.org/js/xpc/test/js/TestInterfaceAll;1 {90ec5c9e-f6da-406b-9a38-14d00f59db76}
+
+component {38dd78aa-467f-4fad-8dcf-4383a743e235} xpctest_returncode_child.js
+contract @mozilla.org/js/xpc/test/js/ReturnCodeChild;1 {38dd78aa-467f-4fad-8dcf-4383a743e235}
+
+component {e86573c4-a384-441a-8c92-7b99e8575b28} xpctest_utils.js
+contract @mozilla.org/js/xpc/test/js/TestUtils;1 {e86573c4-a384-441a-8c92-7b99e8575b28}
+
+interfaces xpctest.xpt
diff --git a/js/xpconnect/tests/components/js/xpctest_attributes.js b/js/xpconnect/tests/components/js/xpctest_attributes.js
new file mode 100644
index 000000000..6576f9d55
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_attributes.js
@@ -0,0 +1,48 @@
+/* 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/. */
+Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestObjectReadWrite() {}
+TestObjectReadWrite.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestObjectReadWrite"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/ObjectReadWrite;1",
+ classID: Components.ID("{8ff41d9c-66e9-4453-924a-7d8de0a5e966}"),
+
+ /* nsIXPCTestObjectReadWrite */
+ stringProperty: "XPConnect Read-Writable String",
+ booleanProperty: true,
+ shortProperty: 32767,
+ longProperty: 2147483647,
+ floatProperty: 5.5,
+ charProperty: "X",
+ // timeProperty is PRTime and signed type.
+ // So it has to allow negative value.
+ timeProperty: -1
+};
+
+
+function TestObjectReadOnly() {}
+TestObjectReadOnly.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestObjectReadOnly"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/ObjectReadOnly;1",
+ classID: Components.ID("{916c4247-253d-4ed0-a425-adfedf53ecc8}"),
+
+ /* nsIXPCTestObjectReadOnly */
+ strReadOnly: "XPConnect Read-Only String",
+ boolReadOnly: true,
+ shortReadOnly: 32767,
+ longReadOnly: 2147483647,
+ floatReadOnly: 5.5,
+ charReadOnly: "X",
+ // timeProperty is PRTime and signed type.
+ // So it has to allow negative value.
+ timeReadOnly: -1
+};
+
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestObjectReadWrite, TestObjectReadOnly]);
diff --git a/js/xpconnect/tests/components/js/xpctest_bug809674.js b/js/xpconnect/tests/components/js/xpctest_bug809674.js
new file mode 100644
index 000000000..4f018c128
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_bug809674.js
@@ -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/. */
+Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestBug809674() {}
+TestBug809674.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestBug809674"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/Bug809674;1",
+ classID: Components.ID("{2df46559-da21-49bf-b863-0d7b7bbcbc73}"),
+
+ /* nsIXPCTestBug809674 */
+ jsvalProperty: {},
+};
+
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestBug809674]);
diff --git a/js/xpconnect/tests/components/js/xpctest_interfaces.js b/js/xpconnect/tests/components/js/xpctest_interfaces.js
new file mode 100644
index 000000000..37d2eb407
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_interfaces.js
@@ -0,0 +1,48 @@
+/* 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/. */
+Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestInterfaceA() {}
+TestInterfaceA.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestInterfaceA"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceA;1",
+ classID: Components.ID("{3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8}"),
+
+ /* nsIXPCTestInterfaceA */
+ name: "TestInterfaceADefaultName"
+};
+
+function TestInterfaceB() {}
+TestInterfaceB.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestInterfaceB"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceB;1",
+ classID: Components.ID("{ff528c3a-2410-46de-acaa-449aa6403a33}"),
+
+ /* nsIXPCTestInterfaceA */
+ name: "TestInterfaceADefaultName"
+};
+
+function TestInterfaceAll() {}
+TestInterfaceAll.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestInterfaceA"],
+ Components.interfaces["nsIXPCTestInterfaceB"],
+ Components.interfaces["nsIXPCTestInterfaceC"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceAll;1",
+ classID: Components.ID("{90ec5c9e-f6da-406b-9a38-14d00f59db76}"),
+
+ /* nsIXPCTestInterfaceA / nsIXPCTestInterfaceB */
+ name: "TestInterfaceAllDefaultName",
+
+ /* nsIXPCTestInterfaceC */
+ someInteger: 42
+};
+
+var NSGetFactory = XPCOMUtils.generateNSGetFactory([TestInterfaceA, TestInterfaceB, TestInterfaceAll]);
+
diff --git a/js/xpconnect/tests/components/js/xpctest_params.js b/js/xpconnect/tests/components/js/xpctest_params.js
new file mode 100644
index 000000000..f06e9c2b6
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_params.js
@@ -0,0 +1,85 @@
+/* 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/. */
+Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestParams() {
+}
+
+/* For once I'm happy that JS is weakly typed. */
+function f(a, b) {
+ var rv = b.value;
+ b.value = a;
+ return rv;
+};
+
+/* Implementation for size_is and iid_is methods. */
+function f_is(aIs, a, bIs, b, rvIs) {
+
+ // Set up the return value and its 'is' parameter.
+ var rv = b.value;
+ rvIs.value = bIs.value;
+
+ // Set up b and its 'is' parameter.
+ b.value = a;
+ bIs.value = aIs;
+
+ return rv;
+}
+
+function f_size_and_iid(aSize, aIID, a, bSize, bIID, b, rvSize, rvIID) {
+
+ // Copy the iids.
+ rvIID.value = bIID.value;
+ bIID.value = aIID;
+
+ // Now that we've reduced the problem to one dependent variable, use f_is.
+ return f_is(aSize, a, bSize, b, rvSize);
+}
+
+TestParams.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestParams"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/Params;1",
+ classID: Components.ID("{e3b86f4e-49c0-487c-a2b0-3a986720a044}"),
+
+ /* nsIXPCTestParams */
+ testBoolean: f,
+ testOctet: f,
+ testShort: f,
+ testLong: f,
+ testLongLong: f,
+ testUnsignedShort: f,
+ testUnsignedLong: f,
+ testUnsignedLongLong: f,
+ testFloat: f,
+ testDouble: f,
+ testChar: f,
+ testString: f,
+ testWchar: f,
+ testWstring: f,
+ testDOMString: f,
+ testAString: f,
+ testAUTF8String: f,
+ testACString: f,
+ testJsval: f,
+ testShortArray: f_is,
+ testDoubleArray: f_is,
+ testStringArray: f_is,
+ testWstringArray: f_is,
+ testInterfaceArray: f_is,
+ testSizedString: f_is,
+ testSizedWstring: f_is,
+ testInterfaceIs: f_is,
+ testInterfaceIsArray: f_size_and_iid,
+ testOutAString: function(o) { o.value = "out"; },
+ testStringArrayOptionalSize: function(arr, size) {
+ if (arr.length != size) { throw "bad size passed to test method"; }
+ var rv = "";
+ arr.forEach((x) => rv += x);
+ return rv;
+ }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestParams]);
diff --git a/js/xpconnect/tests/components/js/xpctest_returncode_child.js b/js/xpconnect/tests/components/js/xpctest_returncode_child.js
new file mode 100644
index 000000000..ef1e48b2a
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_returncode_child.js
@@ -0,0 +1,49 @@
+/* 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/. */
+const {interfaces: Ci, classes: Cc, utils: Cu, results: Cr} = Components;
+Cu.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestReturnCodeChild() {}
+TestReturnCodeChild.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Ci["nsIXPCTestReturnCodeChild"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/ReturnCodeChild;1",
+ classID: Components.ID("{38dd78aa-467f-4fad-8dcf-4383a743e235}"),
+
+ doIt(behaviour) {
+ switch (behaviour) {
+ case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_THROW:
+ throw(new Error("a requested error"));
+ case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_SUCCESS:
+ return;
+ case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE:
+ Components.returnCode = Cr.NS_ERROR_FAILURE;
+ return;
+ case Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_NEST_RESULTCODES:
+ // Use xpconnect to create another instance of *this* component and
+ // call that. This way we have crossed the xpconnect bridge twice.
+
+ // We set *our* return code early - this should be what is returned
+ // to our caller, even though our "inner" component will set it to
+ // a different value that we will see (but our caller should not)
+ Components.returnCode = Cr.NS_ERROR_UNEXPECTED;
+ // call the child asking it to do the .returnCode set.
+ let sub = Cc[this.contractID].createInstance(Ci.nsIXPCTestReturnCodeChild);
+ let childResult = Cr.NS_OK;
+ try {
+ sub.doIt(Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE);
+ } catch (ex) {
+ childResult = ex.result;
+ }
+ // write it to the console so the test can check it.
+ let consoleService = Cc["@mozilla.org/consoleservice;1"]
+ .getService(Ci.nsIConsoleService);
+ consoleService.logStringMessage("nested child returned " + childResult);
+ return;
+ }
+ }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestReturnCodeChild]);
diff --git a/js/xpconnect/tests/components/js/xpctest_utils.js b/js/xpconnect/tests/components/js/xpctest_utils.js
new file mode 100644
index 000000000..91d7f1839
--- /dev/null
+++ b/js/xpconnect/tests/components/js/xpctest_utils.js
@@ -0,0 +1,17 @@
+/* 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/. */
+
+Components.utils.import("resource:///modules/XPCOMUtils.jsm");
+
+function TestUtils() {}
+TestUtils.prototype = {
+
+ /* Boilerplate */
+ QueryInterface: XPCOMUtils.generateQI([Components.interfaces["nsIXPCTestUtils"]]),
+ contractID: "@mozilla.org/js/xpc/test/js/TestUtils;1",
+ classID: Components.ID("{e86573c4-a384-441a-8c92-7b99e8575b28}"),
+ doubleWrapFunction(fun) { return fun }
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestUtils]);
diff --git a/js/xpconnect/tests/components/native/moz.build b/js/xpconnect/tests/components/native/moz.build
new file mode 100644
index 000000000..25d1cb942
--- /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/.
+
+FINAL_TARGET = '_tests/xpcshell/js/xpconnect/tests/components/native/'
+EXTRA_COMPONENTS += [
+ 'xpctest.manifest',
+]
+
+UNIFIED_SOURCES += [
+ 'xpctest_attributes.cpp',
+ 'xpctest_module.cpp',
+ 'xpctest_params.cpp',
+ 'xpctest_returncode.cpp',
+]
+
+XPCOMBinaryComponent('xpctest')
diff --git a/js/xpconnect/tests/components/native/xpctest.manifest b/js/xpconnect/tests/components/native/xpctest.manifest
new file mode 100644
index 000000000..5b01aca44
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest.manifest
@@ -0,0 +1 @@
+interfaces xpctest.xpt
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 000000000..6a844fee2
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_attributes.cpp
@@ -0,0 +1,139 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * 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){
+ char aString[] = "XPConnect Read-Only String";
+
+ if (!aStrReadOnly)
+ return NS_ERROR_NULL_POINTER;
+ *aStrReadOnly = (char*) nsMemory::Clone(aString,
+ sizeof(char)*(strlen(aString)+1));
+ return *aStrReadOnly ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+}
+
+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() {
+ const char s[] = "XPConnect Read-Writable String";
+ stringProperty = (char*) nsMemory::Clone(s, sizeof(char)*(strlen(s)+1));
+ 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 = (char*) nsMemory::Clone(stringProperty,
+ sizeof(char)*(strlen(stringProperty)+1));
+ return *aStringProperty ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+
+}
+NS_IMETHODIMP xpcTestObjectReadWrite :: SetStringProperty(const char * aStringProperty) {
+ free(stringProperty);
+ stringProperty = (char*) nsMemory::Clone(aStringProperty,
+ sizeof(char)*(strlen(aStringProperty)+1));
+ 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_module.cpp b/js/xpconnect/tests/components/native/xpctest_module.cpp
new file mode 100644
index 000000000..f6c29968b
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_module.cpp
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * 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 "mozilla/ModuleUtils.h"
+#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 } }
+
+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);
+
+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 },
+ { nullptr }
+};
+
+static const mozilla::Module::ContractIDEntry kXPCTestContracts[] = {
+ { "@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 }
+};
+
+static const mozilla::Module kXPCTestModule = {
+ mozilla::Module::kVersion,
+ kXPCTestCIDs,
+ kXPCTestContracts
+};
+
+NSMODULE_DEFN(xpconnect_test) = &kXPCTestModule;
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 000000000..e88746d89
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_params.cpp
@@ -0,0 +1,308 @@
+/* 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"
+
+NS_IMPL_ISUPPORTS(nsXPCTestParams, nsIXPCTestParams)
+
+nsXPCTestParams::nsXPCTestParams()
+{
+}
+
+nsXPCTestParams::~nsXPCTestParams()
+{
+}
+
+#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 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))); \
+ if (!*rv) \
+ return NS_ERROR_OUT_OF_MEMORY; \
+ memcpy(*rv, *b, elemSize * (*bLength + padding)); \
+ \
+ /* Copy a into b. */ \
+ *bLength = aLength; \
+ free(*b); \
+ *b = static_cast<type*>(moz_xmalloc(elemSize * (aLength + padding))); \
+ if (!*b) \
+ return NS_ERROR_OUT_OF_MEMORY; \
+ 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::TestDOMString(const nsAString & a, nsAString & b, nsAString & _retval)
+{
+ STRING_METHOD_IMPL;
+}
+
+
+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::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)));
+ if (!*rvIID)
+ return NS_ERROR_OUT_OF_MEMORY;
+ **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)));
+ if (!*rvIID)
+ return NS_ERROR_OUT_OF_MEMORY;
+ **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;
+}
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 000000000..45e3f12e4
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_private.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * 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 "nsStringGlue.h"
+#include "xpctest_attributes.h"
+#include "xpctest_params.h"
+#include "xpctest_returncode.h"
+#include "mozilla/Attributes.h"
+
+class xpcTestObjectReadOnly final : public nsIXPCTestObjectReadOnly {
+ public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTOBJECTREADONLY
+ xpcTestObjectReadOnly();
+
+ private:
+ ~xpcTestObjectReadOnly() {}
+
+ 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();
+
+private:
+ ~nsXPCTestParams();
+};
+
+class nsXPCTestReturnCodeParent final : public nsIXPCTestReturnCodeParent
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIXPCTESTRETURNCODEPARENT
+
+ nsXPCTestReturnCodeParent();
+
+private:
+ ~nsXPCTestReturnCodeParent();
+};
+
+#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 000000000..3ae7d4279
--- /dev/null
+++ b/js/xpconnect/tests/components/native/xpctest_returncode.cpp
@@ -0,0 +1,27 @@
+/* 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 "nsComponentManagerUtils.h"
+
+NS_IMPL_ISUPPORTS(nsXPCTestReturnCodeParent, nsIXPCTestReturnCodeParent)
+
+nsXPCTestReturnCodeParent::nsXPCTestReturnCodeParent()
+{
+}
+
+nsXPCTestReturnCodeParent::~nsXPCTestReturnCodeParent()
+{
+}
+
+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;
+}