diff --git a/js/xpconnect/tests/components/js/xpctest_params.js b/js/xpconnect/tests/components/js/xpctest_params.js index 7f7e04d5fb2d..1233317a57f6 100644 --- a/js/xpconnect/tests/components/js/xpctest_params.js +++ b/js/xpconnect/tests/components/js/xpctest_params.js @@ -64,6 +64,13 @@ TestParams.prototype = { testAUTF8String: f, testACString: f, testJsval: f, + testShortSequence: f, + testDoubleSequence: f, + testAStringSequence: f, + testACStringSequence: f, + testInterfaceSequence: f, + testJsvalSequence: f, + testInterfaceIsSequence: f_is, testShortArray: f_is, testDoubleArray: f_is, testStringArray: f_is, diff --git a/js/xpconnect/tests/components/native/xpctest_params.cpp b/js/xpconnect/tests/components/native/xpctest_params.cpp index 1e2a8aea8deb..413251662e6f 100644 --- a/js/xpconnect/tests/components/native/xpctest_params.cpp +++ b/js/xpconnect/tests/components/native/xpctest_params.cpp @@ -28,6 +28,14 @@ nsXPCTestParams::~nsXPCTestParams() return NS_OK; \ } +#define SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP) { \ + _retval.SwapElements(b); \ + b = a; \ + 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(val)->AddRef();} #define TAKE_OWNERSHIP_STRING(val) { \ @@ -313,3 +321,69 @@ NS_IMETHODIMP nsXPCTestParams::TestStringArrayOptionalSize(const char * *a, uint return NS_OK; } + +NS_IMETHODIMP +nsXPCTestParams::TestShortSequence(const nsTArray& a, nsTArray& b, nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +NS_IMETHODIMP +nsXPCTestParams::TestDoubleSequence(const nsTArray& a, nsTArray& b, nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +// XXX(nika): Consider generating the exposed type 'nsTArray>` here instead? +NS_IMETHODIMP +nsXPCTestParams::TestInterfaceSequence(const nsTArray& a, + nsTArray& b, + nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE); +} + +NS_IMETHODIMP +nsXPCTestParams::TestAStringSequence(const nsTArray& a, + nsTArray& b, + nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +NS_IMETHODIMP +nsXPCTestParams::TestACStringSequence(const nsTArray& a, + nsTArray& b, + nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +NS_IMETHODIMP +nsXPCTestParams::TestJsvalSequence(const nsTArray& a, + nsTArray& b, + nsTArray& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +NS_IMETHODIMP +nsXPCTestParams::TestSequenceSequence(const nsTArray>& a, + nsTArray>& b, + nsTArray>& _retval) +{ + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_NOOP); +} + +NS_IMETHODIMP +nsXPCTestParams::TestInterfaceIsSequence(const nsIID* aIID, const nsTArray& a, + nsIID** bIID, nsTArray& b, + nsIID** rvIID, nsTArray& _retval) +{ + // Shuffle around our nsIIDs + *rvIID = (*bIID)->Clone(); + *bIID = aIID->Clone(); + + // Perform the generic sequence shuffle. + SEQUENCE_METHOD_IMPL(TAKE_OWNERSHIP_INTERFACE); +} diff --git a/js/xpconnect/tests/idl/xpctest_params.idl b/js/xpconnect/tests/idl/xpctest_params.idl index fcbc690a4e5a..132d5306d5c1 100644 --- a/js/xpconnect/tests/idl/xpctest_params.idl +++ b/js/xpconnect/tests/idl/xpctest_params.idl @@ -39,6 +39,19 @@ interface nsIXPCTestParams : nsISupports { ACString testACString(in ACString a, inout ACString b); jsval testJsval(in jsval a, inout jsval b); + // Test various forms of the Sequence type. + Sequence testShortSequence(in Sequence a, inout Sequence b); + Sequence testDoubleSequence(in Sequence a, inout Sequence b); + Sequence testInterfaceSequence(in Sequence a, inout Sequence b); + Sequence testAStringSequence(in Sequence a, inout Sequence b); + Sequence testACStringSequence(in Sequence a, inout Sequence b); + Sequence testJsvalSequence(in Sequence a, inout Sequence b); + Sequence > testSequenceSequence(in Sequence > a, inout Sequence > b); + + void testInterfaceIsSequence(in nsIIDPtr aIID, [iid_is(aIID)] in Sequence a, + inout nsIIDPtr bIID, [iid_is(bIID)] inout Sequence b, + out nsIIDPtr rvIID, [retval, iid_is(rvIID)] out Sequence rv); + // // Dependent parameters use the same types as above, but are handled much differently. // diff --git a/js/xpconnect/tests/unit/test_params.js b/js/xpconnect/tests/unit/test_params.js index 7bd1a2480dce..e41d755616a6 100644 --- a/js/xpconnect/tests/unit/test_params.js +++ b/js/xpconnect/tests/unit/test_params.js @@ -197,4 +197,24 @@ function test_component(contractid) { // Test type mismatch (int16 <-> uint16); this should throw BAD_CONVERT_JS. doTypedArrayMismatchTest("testShortArray", new Uint16Array([0, 7, 4, 3]), 4, new Uint16Array([1, 5, 6]), 3); + + // Test Sequence types. + doTest("testShortSequence", [2, 4, 6], [1, 3, 5, 7], arrayComparator(standardComparator)); + doTest("testDoubleSequence", [-10, -0.5], [1, 3, 1e11, -8e-5 ], arrayComparator(fuzzComparator)); + doTest("testACStringSequence", ["mary", "hat", "hey", "lid", "tell", "lam"], + ["ids", "fleas", "woes", "wide", "has", "know", "!"], + arrayComparator(standardComparator)); + doTest("testAStringSequence", ["沒有語言", "的偉大嗎?]"], + ["we", "are", "being", "sooo", "international", "right", "now"], + arrayComparator(standardComparator)); + + doTest("testInterfaceSequence", [makeA(), makeA()], + [makeA(), makeA(), makeA(), makeA(), makeA(), makeA()], arrayComparator(interfaceComparator)); + + doTest("testJsvalSequence", [{ cheese: 'whiz', apple: 8 }, [1, 5, '3'], /regex/], + ['apple', 2.2e10, 3.3e30, { only: "wheedle", except: {} }], arrayComparator(standardComparator)); + + doIsTest("testInterfaceIsSequence", [makeA(), makeA(), makeA(), makeA(), makeA()], Ci['nsIXPCTestInterfaceA'], + [makeB(), makeB(), makeB()], Ci['nsIXPCTestInterfaceB'], + arrayComparator(interfaceComparator), dotEqualsComparator); }