Bug 792209 - Remove nsISupportsArray. r=froydnj

MozReview-Commit-ID: G28VUoYj9Wj
This commit is contained in:
Eric Rahm 2016-11-17 11:45:41 -08:00
Родитель 2fb7abf24c
Коммит 3bec954d62
14 изменённых файлов: 4 добавлений и 970 удалений

Просмотреть файл

@ -38,24 +38,6 @@
#include "nsTraceRefcnt.h"
#include "nsErrorService.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
#include "nsSupportsArray.h"
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif
#include "nsArray.h"
#include "nsINIParserImpl.h"
#include "nsSupportsPrimitives.h"

Просмотреть файл

@ -16,7 +16,6 @@
COMPONENT(PERSISTENTPROPERTIES, nsPersistentProperties::Create)
COMPONENT(SUPPORTSARRAY, nsSupportsArray::Create)
COMPONENT(ARRAY, nsArrayBase::XPCOMConstructor)
COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor)
COMPONENT(ATOMSERVICE, nsAtomServiceConstructor)

Просмотреть файл

@ -9,8 +9,6 @@ XPIDL_SOURCES += [
'nsIArrayExtensions.idl',
'nsIAtom.idl',
'nsIAtomService.idl',
'nsICollection.idl',
'nsIEnumerator.idl',
'nsIHashable.idl',
'nsIINIParser.idl',
'nsIMutableArray.idl',
@ -24,7 +22,6 @@ XPIDL_SOURCES += [
'nsISerializable.idl',
'nsISimpleEnumerator.idl',
'nsIStringEnumerator.idl',
'nsISupportsArray.idl',
'nsISupportsIterators.idl',
'nsISupportsPrimitives.idl',
'nsIVariant.idl',
@ -69,7 +66,6 @@ EXPORTS += [
'nsStaticAtom.h',
'nsStaticNameTable.h',
'nsStringEnumerator.h',
'nsSupportsArray.h',
'nsSupportsPrimitives.h',
'nsTArray-inl.h',
'nsTArray.h',
@ -108,8 +104,6 @@ UNIFIED_SOURCES += [
'nsProperties.cpp',
'nsQuickSort.cpp',
'nsStringEnumerator.cpp',
'nsSupportsArray.cpp',
'nsSupportsArrayEnumerator.cpp',
'nsSupportsPrimitives.cpp',
'nsTArray.cpp',
'nsTObserverArray.cpp',

Просмотреть файл

@ -1,67 +0,0 @@
/* -*- Mode: IDL; tab-width: 4; 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 "nsISerializable.idl"
interface nsIEnumerator;
[deprecated, scriptable, uuid(83b6019c-cbc4-11d2-8cca-0060b0fc14a3)]
interface nsICollection : nsISerializable
{
uint32_t Count();
nsISupports GetElementAt(in uint32_t index);
void QueryElementAt(in uint32_t index, in nsIIDRef uuid,
[iid_is(uuid),retval] out nsQIResult result);
void SetElementAt(in uint32_t index, in nsISupports item);
void AppendElement(in nsISupports item);
void RemoveElement(in nsISupports item);
/**
* This clashes with |nsISimpleEnumerator nsIArray.enumerate()| (only on the
* binary side), so it is renamed with a 'Deprecated' prefix in favor of the
* non-deprecated |nsIArray.enumerate|.
*/
[binaryname(DeprecatedEnumerate)]
nsIEnumerator Enumerate();
void Clear();
};
%{C++
#ifndef nsCOMPtr_h__
#include "nsCOMPtr.h"
#endif
class MOZ_STACK_CLASS nsQueryElementAt : public nsCOMPtr_helper
{
public:
nsQueryElementAt( nsICollection* aCollection, uint32_t aIndex, nsresult* aErrorPtr )
: mCollection(aCollection),
mIndex(aIndex),
mErrorPtr(aErrorPtr)
{
// nothing else to do here
}
virtual nsresult NS_FASTCALL operator()( const nsIID& aIID, void** )
const override;
private:
nsICollection* MOZ_NON_OWNING_REF mCollection;
uint32_t mIndex;
nsresult* mErrorPtr;
};
inline
const nsQueryElementAt
do_QueryElementAt( nsICollection* aCollection, uint32_t aIndex, nsresult* aErrorPtr = 0 )
{
return nsQueryElementAt(aCollection, aIndex, aErrorPtr);
}
%}

Просмотреть файл

@ -1,50 +0,0 @@
/* -*- Mode: C++; tab-width: 4; 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 "nsISupports.idl"
%{C++
#define NS_ENUMERATOR_FALSE 1
%}
/*
* DO NOT USE THIS INTERFACE. IT IS HORRIBLY BROKEN, USES NS_COMFALSE
* AND IS BASICALLY IMPOSSIBLE TO USE CORRECTLY THROUGH PROXIES OR
* XPCONNECT. IF YOU SEE NEW USES OF THIS INTERFACE IN CODE YOU ARE
* REVIEWING, YOU SHOULD INSIST ON nsISimpleEnumerator.
*
* DON'T MAKE ME COME OVER THERE.
*/
[deprecated, scriptable, uuid(ad385286-cbc4-11d2-8cca-0060b0fc14a3)]
interface nsIEnumerator : nsISupports {
/** First will reset the list. will return NS_FAILED if no items
*/
void first();
/** Next will advance the list. will return failed if already at end
*/
void next();
/** CurrentItem will return the CurrentItem item it will fail if the
* list is empty
*/
nsISupports currentItem();
/** return if the collection is at the end. that is the beginning following
* a call to Prev and it is the end of the list following a call to next
*/
void isDone();
};
[deprecated, uuid(75f158a0-cadd-11d2-8cca-0060b0fc14a3)]
interface nsIBidirectionalEnumerator : nsIEnumerator {
/** Last will reset the list to the end. will return NS_FAILED if no items
*/
void last();
/** Prev will decrement the list. will return failed if already at beginning
*/
void prev();
};

Просмотреть файл

@ -1,60 +0,0 @@
/* -*- Mode: C++; tab-width: 4; 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 "nsICollection.idl"
/*
* This entire interface is deprecated and should not be used.
* See nsIArray and nsIMutableArray for the new implementations.
*
* http://groups.google.com/groups?q=nsisupportsarray+group:netscape.public.mozilla.xpcom&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3D779491.3050506%40netscape.com&rnum=2
* http://groups.google.com/groups?q=nsisupportsarray+group:netscape.public.mozilla.xpcom&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=al8412%245ab2%40ripley.netscape.com&rnum=8
*/
%{C++
class nsIBidirectionalEnumerator;
class nsISupportsArray;
#define NS_SUPPORTSARRAY_CID \
{ /* bda17d50-0d6b-11d3-9331-00104ba0fd40 */ \
0xbda17d50, \
0x0d6b, \
0x11d3, \
{0x93, 0x31, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
#define NS_SUPPORTSARRAY_CONTRACTID "@mozilla.org/supports-array;1"
%}
[deprecated, scriptable, uuid(241addc8-3608-4e73-8083-2fd6fa09eba2)]
interface nsISupportsArray : nsICollection {
[notxpcom] long IndexOf([const] in nsISupports aPossibleElement);
// xpcom-compatible versions
long GetIndexOf(in nsISupports aPossibleElement);
[notxpcom] boolean InsertElementAt(in nsISupports aElement,
in unsigned long aIndex);
[notxpcom] boolean ReplaceElementAt(in nsISupports aElement,
in unsigned long aIndex);
[notxpcom] boolean RemoveElementAt(in unsigned long aIndex);
// xpcom-compatible versions
void DeleteElementAt(in unsigned long aIndex);
nsISupportsArray clone();
};
%{C++
// Construct and return a default implementation of nsISupportsArray:
extern MOZ_MUST_USE nsresult
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult);
%}

Просмотреть файл

@ -1,264 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 <stdint.h>
#include <string.h>
#include "nsArrayEnumerator.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
#include "nsSupportsArray.h"
#include "nsSupportsArrayEnumerator.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
nsresult
nsQueryElementAt::operator()(const nsIID& aIID, void** aResult) const
{
nsresult status =
mCollection ? mCollection->QueryElementAt(mIndex, aIID, aResult) :
NS_ERROR_NULL_POINTER;
if (mErrorPtr) {
*mErrorPtr = status;
}
return status;
}
nsSupportsArray::nsSupportsArray()
{
}
nsSupportsArray::~nsSupportsArray()
{
Clear();
}
nsresult
nsSupportsArray::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
{
if (aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
nsCOMPtr<nsISupportsArray> it = new nsSupportsArray();
return it->QueryInterface(aIID, aResult);
}
NS_IMPL_ISUPPORTS(nsSupportsArray, nsIArray, nsISupportsArray, nsICollection,
nsISerializable)
NS_IMETHODIMP
nsSupportsArray::Read(nsIObjectInputStream* aStream)
{
nsresult rv;
uint32_t newArraySize;
rv = aStream->Read32(&newArraySize);
if (NS_FAILED(rv)) {
return rv;
}
uint32_t count;
rv = aStream->Read32(&count);
if (NS_FAILED(rv)) {
return rv;
}
NS_ASSERTION(count <= newArraySize, "overlarge mCount!");
if (count > newArraySize) {
count = newArraySize;
}
// Don't clear out our array until we know we have enough space for the new
// one and have successfully copied everything out of the stream.
nsCOMArray<nsISupports> tmp;
tmp.SetCapacity(newArraySize);
tmp.SetCount(count);
auto elems = tmp.Elements();
for (uint32_t i = 0; i < count; i++) {
rv = aStream->ReadObject(true, &elems[i]);
if (NS_FAILED(rv)) {
return rv;
}
}
// Now clear out existing refs and replace with the new array.
mArray.Clear();
mArray.SwapElements(tmp);
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArray::Write(nsIObjectOutputStream* aStream)
{
nsresult rv;
rv = aStream->Write32(mArray.Capacity());
if (NS_FAILED(rv)) {
return rv;
}
rv = aStream->Write32(mArray.Length());
if (NS_FAILED(rv)) {
return rv;
}
for (size_t i = 0; i < mArray.Length(); i++) {
rv = aStream->WriteObject(mArray[i], true);
if (NS_FAILED(rv)) {
return rv;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArray::GetElementAt(uint32_t aIndex, nsISupports** aOutPtr)
{
nsCOMPtr<nsISupports> elm = mArray.SafeElementAt(aIndex);
elm.forget(aOutPtr);
return NS_OK;
}
NS_IMETHODIMP_(int32_t)
nsSupportsArray::IndexOf(const nsISupports* aPossibleElement)
{
// nsCOMArray takes a non-const param, but it just passes through to
// nsTArray which takes a const param.
return mArray.IndexOf(const_cast<nsISupports*>(aPossibleElement));
}
NS_IMETHODIMP_(bool)
nsSupportsArray::InsertElementAt(nsISupports* aElement, uint32_t aIndex)
{
return mArray.InsertObjectAt(aElement, aIndex);
}
NS_IMETHODIMP_(bool)
nsSupportsArray::ReplaceElementAt(nsISupports* aElement, uint32_t aIndex)
{
// nsCOMArray::ReplaceObjectAt will grow the array if necessary. Instead
// we do the bounds check and only replace if it's in range.
if (aIndex < mArray.Length()) {
mArray.ReplaceElementAt(aIndex, aElement);
return true;
}
return false;
}
NS_IMETHODIMP_(bool)
nsSupportsArray::RemoveElementAt(uint32_t aIndex)
{
return mArray.RemoveObjectAt(aIndex);
}
NS_IMETHODIMP
nsSupportsArray::RemoveElement(nsISupports* aElement)
{
return mArray.RemoveObject(aElement) ? NS_OK : NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSupportsArray::Clear(void)
{
mArray.Clear();
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArray::DeprecatedEnumerate(nsIEnumerator** aResult)
{
RefPtr<nsSupportsArrayEnumerator> e = new nsSupportsArrayEnumerator(this);
e.forget(aResult);
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArray::Clone(nsISupportsArray** aResult)
{
nsCOMPtr<nsISupportsArray> newArray;
nsresult rv = NS_NewISupportsArray(getter_AddRefs(newArray));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
for (size_t i = 0; i < mArray.Length(); i++) {
// AppendElement does an odd cast of bool to nsresult, we just cast back
// here.
if (!(bool)newArray->AppendElement(mArray[i])) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
newArray.forget(aResult);
return NS_OK;
}
nsresult
NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
{
nsresult rv;
rv = nsSupportsArray::Create(nullptr, NS_GET_IID(nsISupportsArray),
(void**)aInstancePtrResult);
return rv;
}
/**
* nsIArray adapters.
*/
NS_IMETHODIMP
nsSupportsArray::GetLength(uint32_t* aLength) {
return Count(aLength);
}
NS_IMETHODIMP
nsSupportsArray::QueryElementAt(uint32_t aIndex, const nsIID& aIID, void** aResult)
{
nsISupports* element = mArray.SafeElementAt(aIndex);
if (element) {
return element->QueryInterface(aIID, aResult);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSupportsArray::IndexOf(uint32_t aStartIndex, nsISupports* aElement, uint32_t* aResult)
{
int32_t idx = mArray.IndexOf(aElement, aStartIndex);
if (idx < 0) {
return NS_ERROR_FAILURE;
}
*aResult = static_cast<uint32_t>(idx);
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArray::Enumerate(nsISimpleEnumerator** aResult)
{
return NS_NewArrayEnumerator(aResult, this);
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif

Просмотреть файл

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef nsSupportsArray_h__
#define nsSupportsArray_h__
#include "nsIArray.h"
#include "nsCOMArray.h"
#include "mozilla/Attributes.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
#include "nsISupportsArray.h"
class nsSupportsArray final : public nsISupportsArray,
public nsIArray
{
~nsSupportsArray(void); // nonvirtual since we're not subclassed
public:
nsSupportsArray(void);
static MOZ_MUST_USE nsresult
Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSISERIALIZABLE
// nsICollection methods:
NS_IMETHOD Count(uint32_t* aResult) override
{
*aResult = mArray.Length();
return NS_OK;
}
NS_IMETHOD GetElementAt(uint32_t aIndex, nsISupports** aResult) override;
MOZ_MUST_USE NS_IMETHOD
SetElementAt(uint32_t aIndex, nsISupports* aValue) override
{
return ReplaceElementAt(aValue, aIndex) ? NS_OK : NS_ERROR_FAILURE;
}
MOZ_MUST_USE NS_IMETHOD AppendElement(nsISupports* aElement) override
{
// XXX Invalid cast of bool to nsresult (bug 778110)
return (nsresult)InsertElementAt(aElement, mArray.Length())/* ? NS_OK : NS_ERROR_FAILURE*/;
}
// XXX this is badly named - should be RemoveFirstElement
MOZ_MUST_USE NS_IMETHOD RemoveElement(nsISupports* aElement) override;
NS_IMETHOD DeprecatedEnumerate(nsIEnumerator** aResult) override;
NS_IMETHOD Clear(void) override;
// nsISupportsArray methods:
NS_IMETHOD_(int32_t) IndexOf(const nsISupports* aPossibleElement) override;
NS_IMETHOD GetIndexOf(nsISupports* aPossibleElement, int32_t* aResult) override
{
*aResult = IndexOf(aPossibleElement);
return NS_OK;
}
MOZ_MUST_USE NS_IMETHOD_(bool)
InsertElementAt(nsISupports* aElement, uint32_t aIndex) override;
MOZ_MUST_USE NS_IMETHOD_(bool)
ReplaceElementAt(nsISupports* aElement, uint32_t aIndex) override;
MOZ_MUST_USE NS_IMETHOD_(bool)
RemoveElementAt(uint32_t aIndex) override;
MOZ_MUST_USE NS_IMETHOD DeleteElementAt(uint32_t aIndex) override
{
return (RemoveElementAt(aIndex) ? NS_OK : NS_ERROR_FAILURE);
}
MOZ_MUST_USE NS_IMETHOD Clone(nsISupportsArray** aResult) override;
/**
* nsIArray adapters.
*/
NS_DECL_NSIARRAY
private:
// Copy constructors are not allowed
explicit nsSupportsArray(const nsISupportsArray& aOther);
nsCOMArray<nsISupports> mArray;
};
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif // nsSupportsArray_h__

Просмотреть файл

@ -1,131 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "nsSupportsArrayEnumerator.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
#include "nsISupportsArray.h"
nsSupportsArrayEnumerator::nsSupportsArrayEnumerator(nsISupportsArray* array)
: mArray(array)
, mCursor(0)
{
NS_ASSERTION(array, "null array");
}
nsSupportsArrayEnumerator::~nsSupportsArrayEnumerator()
{
}
NS_IMPL_ISUPPORTS(nsSupportsArrayEnumerator, nsIBidirectionalEnumerator,
nsIEnumerator)
NS_IMETHODIMP
nsSupportsArrayEnumerator::First()
{
mCursor = 0;
uint32_t cnt;
nsresult rv = mArray->Count(&cnt);
if (NS_FAILED(rv)) {
return rv;
}
int32_t end = (int32_t)cnt;
if (mCursor < end) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP
nsSupportsArrayEnumerator::Next()
{
uint32_t cnt;
nsresult rv = mArray->Count(&cnt);
if (NS_FAILED(rv)) {
return rv;
}
int32_t end = (int32_t)cnt;
if (mCursor < end) { // don't count upward forever
mCursor++;
}
if (mCursor < end) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
}
NS_IMETHODIMP
nsSupportsArrayEnumerator::CurrentItem(nsISupports** aItem)
{
NS_ASSERTION(aItem, "null out parameter");
uint32_t cnt;
nsresult rv = mArray->Count(&cnt);
if (NS_FAILED(rv)) {
return rv;
}
if (mCursor >= 0 && mCursor < (int32_t)cnt) {
return mArray->GetElementAt(mCursor, aItem);
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSupportsArrayEnumerator::IsDone()
{
uint32_t cnt;
nsresult rv = mArray->Count(&cnt);
if (NS_FAILED(rv)) {
return rv;
}
// XXX This is completely incompatible with the meaning of nsresult.
// NS_ENUMERATOR_FALSE is defined to be 1. (bug 778111)
return (mCursor >= 0 && mCursor < (int32_t)cnt)
? (nsresult)NS_ENUMERATOR_FALSE : NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsSupportsArrayEnumerator::Last()
{
uint32_t cnt;
nsresult rv = mArray->Count(&cnt);
if (NS_FAILED(rv)) {
return rv;
}
mCursor = cnt - 1;
return NS_OK;
}
NS_IMETHODIMP
nsSupportsArrayEnumerator::Prev()
{
if (mCursor >= 0) {
--mCursor;
}
if (mCursor >= 0) {
return NS_OK;
} else {
return NS_ERROR_FAILURE;
}
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif

Просмотреть файл

@ -1,56 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef nsSupportsArrayEnumerator_h___
#define nsSupportsArrayEnumerator_h___
#include "nsCOMPtr.h"
#include "mozilla/Attributes.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
#include "nsIEnumerator.h"
class nsISupportsArray;
class nsSupportsArrayEnumerator final : public nsIBidirectionalEnumerator
{
public:
NS_DECL_ISUPPORTS
explicit nsSupportsArrayEnumerator(nsISupportsArray* aArray);
// nsIEnumerator methods:
NS_DECL_NSIENUMERATOR
// nsIBidirectionalEnumerator methods:
NS_DECL_NSIBIDIRECTIONALENUMERATOR
private:
~nsSupportsArrayEnumerator();
protected:
nsCOMPtr<nsISupportsArray> mArray;
int32_t mCursor;
};
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif // __nsSupportsArrayEnumerator_h

Просмотреть файл

@ -1,169 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 <stdio.h>
#include <stdlib.h>
#include "gtest/gtest.h"
// Disable deprecation warnings generated by nsISupportsArray and associated
// classes.
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#elif defined(_MSC_VER)
#pragma warning (push)
#pragma warning (disable : 4996)
#endif
#include "nsISupportsArray.h"
// {9e70a320-be02-11d1-8031-006008159b5a}
#define NS_IFOO_IID \
{0x9e70a320, 0xbe02, 0x11d1, \
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
namespace TestArray {
class IFoo : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFOO_IID)
NS_IMETHOD_(nsrefcnt) RefCnt() = 0;
NS_IMETHOD_(int32_t) ID() = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(IFoo, NS_IFOO_IID)
class Foo final : public IFoo {
public:
explicit Foo(int32_t aID);
// nsISupports implementation
NS_DECL_ISUPPORTS
// IFoo implementation
NS_IMETHOD_(nsrefcnt) RefCnt() override { return mRefCnt; }
NS_IMETHOD_(int32_t) ID() override { return mID; }
static int32_t gCount;
int32_t mID;
private:
~Foo();
};
int32_t Foo::gCount;
Foo::Foo(int32_t aID)
{
mID = aID;
++gCount;
}
Foo::~Foo()
{
--gCount;
}
NS_IMPL_ISUPPORTS(Foo, IFoo)
void CheckArray(nsISupportsArray* aArray, int32_t aExpectedCount, int32_t aElementIDs[], int32_t aExpectedTotal)
{
uint32_t cnt = 0;
#ifdef DEBUG
nsresult rv =
#endif
aArray->Count(&cnt);
NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
int32_t count = cnt;
int32_t index;
EXPECT_EQ(Foo::gCount, aExpectedTotal);
EXPECT_EQ(count, aExpectedCount);
for (index = 0; (index < count) && (index < aExpectedCount); index++) {
nsCOMPtr<IFoo> foo = do_QueryElementAt(aArray, index);
EXPECT_EQ(foo->ID(), aElementIDs[index]);
}
}
void FillArray(nsISupportsArray* aArray, int32_t aCount)
{
int32_t index;
for (index = 0; index < aCount; index++) {
nsCOMPtr<IFoo> foo = new Foo(index);
aArray->AppendElement(foo);
}
}
} // namespace TestArray
using namespace TestArray;
TEST(Array, main)
{
nsISupportsArray* array;
nsresult rv;
if (NS_OK == (rv = NS_NewISupportsArray(&array))) {
FillArray(array, 10);
int32_t fillResult[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
CheckArray(array, 10, fillResult, 10);
// test insert
nsCOMPtr<IFoo> foo = do_QueryElementAt(array, 3);
array->InsertElementAt(foo, 5);
int32_t insertResult[11] = {0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
CheckArray(array, 11, insertResult, 10);
array->InsertElementAt(foo, 0);
int32_t insertResult2[12] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9};
CheckArray(array, 12, insertResult2, 10);
array->AppendElement(foo);
int32_t appendResult[13] = {3, 0, 1, 2, 3, 4, 3, 5, 6, 7, 8, 9, 3};
CheckArray(array, 13, appendResult, 10);
// test IndexOf
int32_t expectedIndex = 0;
int32_t index = array->IndexOf(foo);
EXPECT_EQ(index, expectedIndex);
// test ReplaceElementAt
array->ReplaceElementAt(foo, 8);
int32_t replaceResult[13] = {3, 0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3};
CheckArray(array, 13, replaceResult, 9);
// test RemoveElementAt, RemoveElement
array->RemoveElementAt(0);
int32_t removeResult[12] = {0, 1, 2, 3, 4, 3, 5, 3, 7, 8, 9, 3};
CheckArray(array, 12, removeResult, 9);
array->RemoveElementAt(7);
int32_t removeResult2[11] = {0, 1, 2, 3, 4, 3, 5, 7, 8, 9, 3};
CheckArray(array, 11, removeResult2, 9);
array->RemoveElement(foo);
int32_t removeResult3[10] = {0, 1, 2, 4, 3, 5, 7, 8, 9, 3};
CheckArray(array, 10, removeResult3, 9);
foo = nullptr;
// test clear
array->Clear();
FillArray(array, 4);
CheckArray(array, 4, fillResult, 4);
// test delete
NS_RELEASE(array);
}
}
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop)
#endif

Просмотреть файл

@ -9,6 +9,10 @@
#include "nsCRT.h"
#include "mozilla/TypeTraits.h"
#include <stdio.h>
#include <functional>
using mozilla::IsSame;
using mozilla::DeclVal;
/**************************************************************
Now define the token deallocator class...

Просмотреть файл

@ -6,7 +6,6 @@
UNIFIED_SOURCES += [
'Helpers.cpp',
'TestArray.cpp',
'TestAtoms.cpp',
'TestAutoPtr.cpp',
'TestAutoRef.cpp',

Просмотреть файл

@ -107,45 +107,6 @@ function test_enumerate()
do_check_eq(arr.length, i);
}
function test_nssupportsarray_interop() {
// Tests to check that an nsSupportsArray instance can behave like an
// nsIArray.
let test = Components.classes["@mozilla.org/supports-array;1"]
.createInstance(Ci.nsISupportsArray);
let str = new SupportsString();
str.data = "element";
test.AppendElement(str);
// Now query to an nsIArray.
let iarray = test.QueryInterface(Ci.nsIArray);
do_check_neq(iarray, null);
// Make sure |nsIArray.length| works.
do_check_eq(iarray.length, 1);
// Make sure |nsIArray.queryElementAt| works.
let elm = iarray.queryElementAt(0, Ci.nsISupportsString);
do_check_eq(elm.data, "element");
// Make sure |nsIArray.indexOf| works.
let idx = iarray.indexOf(0, str);
do_check_eq(idx, 0);
// Make sure |nsIArray.enumerate| works.
let en = iarray.enumerate();
do_check_neq(en, null);
let i = 0;
while (en.hasMoreElements()) {
let str = en.getNext();
do_check_true(str instanceof Ci.nsISupportsString);
do_check_eq(str.data, "element");
i++;
}
do_check_eq(iarray.length, i);
}
function test_nsiarrayextensions() {
// Tests to check that the extensions that make an nsArray act like an
// nsISupportsArray for iteration purposes works.
@ -174,7 +135,6 @@ var tests = [
test_replace_element,
test_clear,
test_enumerate,
test_nssupportsarray_interop,
test_nsiarrayextensions,
];