/* 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/. */
// 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;
}
// 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;
}
// XPCOM ownership rules dictate that overwritten inout params must be // callee-freed. See https://developer.mozilla.org/en/XPIDL
free((void*)bprime.get());
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::TestOmittedOptionalOut(nsIXPCTestParams* aJSObj,
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; // Invoke it directly passing nullptr.
rv = aJSObj->TestOmittedOptionalOut(nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv); // Also invoke it with a ref pointer.
nsCOMPtr<nsIURI> someURI;
rv = aJSObj->TestOmittedOptionalOut(nullptr, 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;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.