Files
roytam1 e333860065 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1251090 - Shell functions should check whether an off main thread compilation is for a script or a module r=shu (41b89b1232)
- Bug 1222420 - Make AutoFinishGC into a function r=terrence (a8f535528c)
- Bug 1253094, part 4 - Stop using DebugOnly for class/struct members in js/. r=billm (2c790aa526)
- Bug 1080968 - Don't use constexpr on clang-cl when emulating MSVC 2013 (e9cc2d7c7c)
- Bug 1257496 - Add information about cycle count and GC state to our GC stats r=sfink (6c2250bfba)
- Bug 1256178 - Drop the moz prefix from the MozCSSKeyframeRule and MozCSSKeyframesRule interfaces; r=bzbarsky (894855bce1)
- Bug 1249896 - Part 1: Remove unused AndOrLeft, AndOrRight, RelationalLeft, and RelationalRight. r=jwalden (c4db9dfecf)
- Bug 1249896 - Part 2: Remove unused type member from SIMD Int8x16Defnetc. r=bbouvier (7d3d7a4db1)
- Bug 1249896 - Part 3: Add JS namespace for GenericNaN. r=luke (69acc1f3ec)
- Bug 1249896 - Part 4: Avoid declaring variable between cases in switch. r=luke (28e5f94c24)
- Bug 1249896 - Part 5: Remove unused ReportInvalidTrapResult. r=efaust (caa948acac)
- Bug 1249896 - Part 7: Remove unnecessary static from my_ErrorReporter. r=sfink (7f723e079d)
- Bug 1249896 - Part 8: Remove unreachable code from GetLine. r=jwalden (108c857a1a)
- Bug 1249896 - Part 9: Include shell/jsshell.h in js.cpp. r=sfink (638bfc13c4)
- Bug 1253094, part 3 - Stop using DebugOnly for class/struct members in ipc/. r=billm (ab9e014158)
- Bug 1259737 - Make sure BackgroundImpl.cpp's mBoundThread is not used in release builds. r=froydnj (5c278ab398)
- Bug 1254515 - GonkCameraImage.cpp:16:5: error: class 'mozilla::GonkCameraImage' does not have any field named 'mThread' r=reuben (e5cac8cf5b)
- Bug 1250952: Create a join block in case we're in dead code after the condition; r=luke (1d6b706ae5)
- Bug 1249601 - Implement wasm i64 comparisons. r=sunfish (4927f709db)
- Bug 1250165 - Implement wasm i64 bitwise ops. r=luke (5c25322772)
- Bug 1251225 - Implement wasm i64 binary arithmetic operators. r=sunfish (f478fa8b4b)
- Bug 1251392 - Baldr: Implement PopcntI. r=sunfish (79556e947f)
- Bug 1229985 - remove nsAutoArrayPtr; r=erahm (91c49451ca)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth managers, r=shuang (2c1dc7ca89)
- Bug 1251541: Pass arguments to AVRCP passthrough command as uint8_t, r=shuang (73a094bd26)
- Bug 1251541: Replace |nsAutoArrayPtr<>| with |UniquePtr<[]>| in Bluetooth interfaces, r=shuang (371041f093)
- Bug 1249424 - Remove use of nsAutoArrayPtr from librlz. r=gerald (7cbcfea1b0)
- Bug 1249389 - part 0 - use getter_Transfers in TestStartupCache.cpp; r=erahm (ecb8818959)
- Bug 1249389 - part 1 - change NewObjectInputStreamFromBuffer to take a UniquePtr argument; r=erahm (0bdafa20ae)
- Bug 1249389 - part 2 - change NewBufferFromStorageStream's outparam into a UniquePtr; r=erahm (b27a70ce2d)
- Bug 1249389 - part 3 - assert the size of nsZipItemPtr's storage type; r=erahm (7c55da9ea7)
- Bug 1249389 - part 4 - make StartupCache::GetBuffer take a UniquePtr outparam; r=erahm (84b722479b)
- Bug 1249389 - part 5 - use UniquePtr instead of nsAutoArrayPtr in mozilla::scache::CacheEntry; r=erahm (0fd492ea95)
- Bug 1249389 - part 6 - provide UniquePtr overload for nsIStartupCache::GetBuffer; r=erahm (c27231d945)
- Bug 1249389 - followup - fix compilation bustage in gfxFT2FontList.cpp; r=me (a86a1b0399)
- Bug 1249389 - part 7 - clean up calls to GetBuffer in TestStartupCache; r=erahm (98939334b6)
- Bug 1249369 - use UniquePtr instead of nsAutoArrayPtr in MediaPipeline.cpp; r=jesup (7402a75a8a)
- Bug 1238842 - Add error codes to Gecko by following W3C spec. r=brsun (0dd283f6ba)
- Bug 1253217 - Change filename from BluetoothUuid to BluetoothUuidHelper. r=jocelyn (1946bcac26)
- Bug 1241382 - Revise default value of BluetoothAdapter.address and BluetoothDevice.address to empty string, f=wiwang, r=shuang (d9fdb97743)
- Bug 1223722: Transfer arrays of Bluetooth UUIDs in |BluetoothValue|, r=brsun (344af40591)
- Bug 1222956: Use |BluetoothUuid| in |BluetoothDiscoveryHandle|, r=tzimmermann (40512de386)
- Bug 1250694: Use functions to return static const BluetoothAddress and BluetoothUuid; r=tzimmermann (0c4b20066f)
- Bug 1236561 - part 1 - convert easy cases of nsAutoArrayPtr<T> to UniquePtr<T[]> in dom/bluetooth/; r=btian (31ef8b7b50)
- Bug 1236561 - part 2 - remove ObexHeaderSet::GetAuthChallenge; r=btian (f70daddd53)
- Bug 1236561 - part 3 - make BluetoothConfigurationParameter.mValue a UniquePtr; r=btian (a5a0ac988a)
- Bug 1239979: Add |BluetoothSocket::Accept| method, r=btian (ca92a0ab7c)
- Bug 1239979: Store pointer to Bluetooth socket interface in |BluetoothSocket|, r=btian (7c15e75133)
- Bug 1239979: Cleanup |BluetoothSocket|'s internals when connections close, r=btian (b6ac677d2e)
- Bug 1252841: Convert Bluetooth module to |UniquePtr<>|, r=btian (76d9759afd)
- Bug 1232687: Start bluetoothd with HAL service interface, r=shuang (379a68064f)
- Bug 1223729 - HID Connection Implementation, r=jocelyn, sr=mrbkap (0eeddf875e)
- Bug 1232670: Prepare Bluetooth PDU for sending after checking connection status, r=shuang (699ff14d9b)
- Bug 1252841: Convert Bluetooth daemon interfaces to |UniquePtr<>|, r=brsun (797260c6dc)
2024-02-07 15:25:46 +08:00

496 lines
16 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// vim:cindent:ts=4:et:sw=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 "nsAutoPtr.h"
#include <stdio.h>
#include "nscore.h"
#include "mozilla/Attributes.h"
class TestObjectBaseA {
public:
// Virtual dtor for deleting through base class pointer
virtual ~TestObjectBaseA() { }
void MemberFunction( int, int*, int& )
{
printf("member function is invoked.\n");
}
virtual void VirtualMemberFunction(int, int*, int&) { };
virtual void VirtualConstMemberFunction(int, int*, int&) const { };
int fooA;
};
class TestObjectBaseB {
public:
// Virtual dtor for deleting through base class pointer
virtual ~TestObjectBaseB() { }
int fooB;
};
class TestObject : public TestObjectBaseA, public TestObjectBaseB {
public:
TestObject()
{
printf(" Creating TestObject %p.\n",
static_cast<void*>(this));
}
// Virtual dtor for deleting through base class pointer
virtual ~TestObject()
{
printf(" Destroying TestObject %p.\n",
static_cast<void*>(this));
}
virtual void VirtualMemberFunction(int, int*, int&) override
{
printf("override virtual member function is invoked.\n");
}
virtual void VirtualConstMemberFunction(int, int*, int&) const override
{
printf("override virtual const member function is invoked.\n");
}
};
class TestRefObjectBaseA {
public:
int fooA;
// Must return |nsrefcnt| to keep |nsDerivedSafe| happy.
virtual nsrefcnt AddRef() = 0;
virtual nsrefcnt Release() = 0;
};
class TestRefObjectBaseB {
public:
int fooB;
virtual nsrefcnt AddRef() = 0;
virtual nsrefcnt Release() = 0;
};
class TestRefObject final : public TestRefObjectBaseA, public TestRefObjectBaseB {
public:
TestRefObject()
: mRefCount(0)
{
printf(" Creating TestRefObject %p.\n",
static_cast<void*>(this));
}
~TestRefObject()
{
printf(" Destroying TestRefObject %p.\n",
static_cast<void*>(this));
}
nsrefcnt AddRef()
{
++mRefCount;
printf(" AddRef to %d on TestRefObject %p.\n",
mRefCount, static_cast<void*>(this));
return mRefCount;
}
nsrefcnt Release()
{
--mRefCount;
printf(" Release to %d on TestRefObject %p.\n",
mRefCount, static_cast<void*>(this));
if (mRefCount == 0) {
delete const_cast<TestRefObject*>(this);
return 0;
}
return mRefCount;
}
protected:
uint32_t mRefCount;
};
static void CreateTestObject(TestObject **aResult)
{
*aResult = new TestObject();
}
static void CreateTestRefObject(TestRefObject **aResult)
{
(*aResult = new TestRefObject())->AddRef();
}
static void DoSomethingWithTestObject(TestObject *aIn)
{
printf(" Doing something with |TestObject| %p.\n",
static_cast<void*>(aIn));
}
static void DoSomethingWithConstTestObject(const TestObject *aIn)
{
printf(" Doing something with |const TestObject| %p.\n",
static_cast<const void*>(aIn));
}
static void DoSomethingWithTestRefObject(TestRefObject *aIn)
{
printf(" Doing something with |TestRefObject| %p.\n",
static_cast<void*>(aIn));
}
static void DoSomethingWithConstTestRefObject(const TestRefObject *aIn)
{
printf(" Doing something with |const TestRefObject| %p.\n",
static_cast<const void*>(aIn));
}
static void DoSomethingWithTestObjectBaseB(TestObjectBaseB *aIn)
{
printf(" Doing something with |TestObjectBaseB| %p.\n",
static_cast<void*>(aIn));
}
static void DoSomethingWithConstTestObjectBaseB(const TestObjectBaseB *aIn)
{
printf(" Doing something with |const TestObjectBaseB| %p.\n",
static_cast<const void*>(aIn));
}
static void DoSomethingWithTestRefObjectBaseB(TestRefObjectBaseB *aIn)
{
printf(" Doing something with |TestRefObjectBaseB| %p.\n",
static_cast<void*>(aIn));
}
static void DoSomethingWithConstTestRefObjectBaseB(const TestRefObjectBaseB *aIn)
{
printf(" Doing something with |const TestRefObjectBaseB| %p.\n",
static_cast<const void*>(aIn));
}
int main()
{
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj( new TestObject() );
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj( new TestObject() );
printf("Should create one |TestObject| and then destroy one:\n");
pobj = new TestObject();
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj( new TestRefObject() );
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj( new TestRefObject() );
printf("Should create and AddRef one |TestRefObject| and then Release and destroy one:\n");
pobj = new TestRefObject();
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> p1( new TestRefObject() );
printf("Should AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> p2( p1 );
printf("Should Release twice and destroy one |TestRefObject|:\n");
}
printf("\nTesting equality (with all const-ness combinations):\n");
{
RefPtr<TestRefObject> p1( new TestRefObject() );
RefPtr<TestRefObject> p2( p1 );
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
RefPtr<TestRefObject> p2( p1 );
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
}
{
RefPtr<TestRefObject> p1( new TestRefObject() );
const RefPtr<TestRefObject> p2( p1 );
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
const RefPtr<TestRefObject> p2( p1 );
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2)) ? "OK" : "broken");
}
{
RefPtr<TestRefObject> p1( new TestRefObject() );
TestRefObject * p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
TestRefObject * p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
#if 0 /* MSVC++ 6.0 can't be coaxed to accept this */
{
RefPtr<TestRefObject> p1( new TestRefObject() );
TestRefObject * const p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
TestRefObject * const p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
#endif /* Things that MSVC++ 6.0 can't be coaxed to accept */
{
RefPtr<TestRefObject> p1( new TestRefObject() );
const TestRefObject * p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
const TestRefObject * p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
{
RefPtr<TestRefObject> p1( new TestRefObject() );
const TestRefObject * const p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
{
const RefPtr<TestRefObject> p1( new TestRefObject() );
const TestRefObject * const p2 = p1;
printf("equality %s.\n",
((p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1)) ? "OK" : "broken");
}
printf("\nTesting getter_Transfers and getter_AddRefs.\n");
{
nsAutoPtr<TestObject> ptr;
printf("Should create one |TestObject|:\n");
CreateTestObject(getter_Transfers(ptr));
printf("Should destroy one |TestObject|:\n");
}
{
RefPtr<TestRefObject> ptr;
printf("Should create and AddRef one |TestRefObject|:\n");
CreateTestRefObject(getter_AddRefs(ptr));
printf("Should Release and destroy one |TestRefObject|:\n");
}
printf("\nTesting casts and equality tests.\n");
// This comparison is always false, as it should be. The extra parens
// suppress a -Wunreachable-code warning about printf being unreachable.
if (((void*)(TestObject*)0x1000) ==
((void*)(TestObjectBaseB*)(TestObject*)0x1000))
printf("\n\nAll these tests are meaningless!\n\n\n");
{
nsAutoPtr<TestObject> p1(new TestObject());
TestObjectBaseB *p2 = p1;
printf("equality %s.\n",
((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
(p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
? "OK" : "broken");
}
{
TestObject *p1 = new TestObject();
nsAutoPtr<TestObjectBaseB> p2(p1);
printf("equality %s.\n",
((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
(p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
? "OK" : "broken");
}
{
RefPtr<TestRefObject> p1 = new TestRefObject();
// nsCOMPtr requires a |get| for something like this as well
RefPtr<TestRefObjectBaseB> p2 = p1.get();
printf("equality %s.\n",
((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
(p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
? "OK" : "broken");
}
{
RefPtr<TestRefObject> p1 = new TestRefObject();
TestRefObjectBaseB *p2 = p1;
printf("equality %s.\n",
((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
(p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
? "OK" : "broken");
}
{
TestRefObject *p1 = new TestRefObject();
RefPtr<TestRefObjectBaseB> p2 = p1;
printf("equality %s.\n",
((static_cast<void*>(p1) != static_cast<void*>(p2)) &&
(p1 == p2) && !(p1 != p2) && (p2 == p1) && !(p2 != p1))
? "OK" : "broken");
}
printf("\nTesting |forget()|.\n");
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj( new TestObject() );
printf("Should do nothing:\n");
nsAutoPtr<TestObject> pobj2( pobj.forget() );
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj( new TestRefObject() );
printf("Should do nothing:\n");
RefPtr<TestRefObject> pobj2( pobj.forget() );
printf("Should destroy one |TestRefObject|:\n");
}
printf("\nTesting construction.\n");
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj(new TestObject());
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
printf("Should Release and destroy one |TestRefObject|:\n");
}
printf("\nTesting calling of functions (including array access and casts).\n");
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj(new TestObject());
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(pobj);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(pobj);
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithTestRefObject(pobj);
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithConstTestRefObject(pobj);
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObject> pobj(new TestObject());
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(pobj);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(pobj);
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
RefPtr<TestRefObject> pobj = new TestRefObject();
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithTestRefObjectBaseB(pobj);
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithConstTestRefObjectBaseB(pobj);
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
printf("Should create one |TestObject|:\n");
const nsAutoPtr<TestObject> pobj(new TestObject());
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObject(pobj);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObject(pobj);
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
const RefPtr<TestRefObject> pobj = new TestRefObject();
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithTestRefObject(pobj);
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithConstTestRefObject(pobj);
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
printf("Should create one |TestObject|:\n");
const nsAutoPtr<TestObject> pobj(new TestObject());
printf("Should do something with one |TestObject|:\n");
DoSomethingWithTestObjectBaseB(pobj);
printf("Should do something with one |TestObject|:\n");
DoSomethingWithConstTestObjectBaseB(pobj);
printf("Should destroy one |TestObject|:\n");
}
{
printf("Should create and AddRef one |TestRefObject|:\n");
const RefPtr<TestRefObject> pobj = new TestRefObject();
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithTestRefObjectBaseB(pobj);
printf("Should do something with one |TestRefObject|:\n");
DoSomethingWithConstTestRefObjectBaseB(pobj);
printf("Should Release and destroy one |TestRefObject|:\n");
}
{
int test = 1;
void (TestObjectBaseA::*fPtr)( int, int*, int& ) = &TestObjectBaseA::MemberFunction;
void (TestObjectBaseA::*fVPtr)( int, int*, int& ) = &TestObjectBaseA::VirtualMemberFunction;
void (TestObjectBaseA::*fVCPtr)( int, int*, int& ) const = &TestObjectBaseA::VirtualConstMemberFunction;
printf("Should create one |TestObject|:\n");
nsAutoPtr<TestObjectBaseA> pobj(new TestObject());
printf("Should do something with operator->*:\n");
(pobj->*fPtr)(test, &test, test);
(pobj->*fVPtr)(test, &test, test);
(pobj->*fVCPtr)(test, &test, test);
printf("Should destroy one |TestObject|:\n");
}
return 0;
}