Skip to content

Commit

Permalink
Bug 811206, Fix JSHolder drop handling, part 3 (fixes), r=mccr8,khuey
Browse files Browse the repository at this point in the history
  • Loading branch information
Olli Pettay authored and Olli Pettay committed Nov 28, 2012
1 parent b0429be commit b0e3eff
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 64 deletions.
2 changes: 0 additions & 2 deletions content/base/public/nsContentUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2239,8 +2239,6 @@ class nsContentUtils
static nsILineBreaker* sLineBreaker;
static nsIWordBreaker* sWordBreaker;

static uint32_t sJSGCThingRootCount;

#ifdef IBMBIDI
static nsIBidiKeyboard* sBidiKeyboard;
#endif
Expand Down
8 changes: 5 additions & 3 deletions content/base/src/nsContentUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ nsIContentPolicy *nsContentUtils::sContentPolicyService;
bool nsContentUtils::sTriedToGetContentPolicy = false;
nsILineBreaker *nsContentUtils::sLineBreaker;
nsIWordBreaker *nsContentUtils::sWordBreaker;
uint32_t nsContentUtils::sJSGCThingRootCount;
#ifdef IBMBIDI
nsIBidiKeyboard *nsContentUtils::sBidiKeyboard = nullptr;
#endif
Expand Down Expand Up @@ -4526,6 +4525,10 @@ nsContentUtils::HoldJSObjects(void* aScriptObjectHolder,
nsresult
nsContentUtils::DropJSObjects(void* aScriptObjectHolder)
{
if (!sXPConnect) {
return NS_OK;
}

return sXPConnect->RemoveJSHolder(aScriptObjectHolder);
}

Expand Down Expand Up @@ -6863,9 +6866,8 @@ nsContentUtils::ReleaseWrapper(void* aScriptObjectHolder,
if (aCache->IsDOMBinding() && obj) {
xpc::GetObjectScope(obj)->RemoveDOMExpandoObject(obj);
}
DropJSObjects(aScriptObjectHolder);

aCache->SetPreservingWrapper(false);
DropJSObjects(aScriptObjectHolder);
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/canvas/src/ImageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ void
ImageData::DropData()
{
if (mData) {
NS_DROP_JS_OBJECTS(this, ImageData);
mData = NULL;
NS_DROP_JS_OBJECTS(this, ImageData);
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/events/src/nsDOMMessageEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ void
nsDOMMessageEvent::UnrootData()
{
NS_ASSERTION(mDataRooted, "...");
NS_DROP_JS_OBJECTS(this, nsDOMMessageEvent);
mDataRooted = false;
mData = JSVAL_VOID;
NS_DROP_JS_OBJECTS(this, nsDOMMessageEvent);
}

NS_IMETHODIMP
Expand Down
4 changes: 2 additions & 2 deletions content/events/src/nsDOMNotifyAudioAvailableEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ NS_IMPL_RELEASE_INHERITED(nsDOMNotifyAudioAvailableEvent, nsDOMEvent)

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMNotifyAudioAvailableEvent, nsDOMEvent)
if (tmp->mCachedArray) {
NS_DROP_JS_OBJECTS(tmp, nsDOMNotifyAudioAvailableEvent);
tmp->mCachedArray = nullptr;
NS_DROP_JS_OBJECTS(tmp, nsDOMNotifyAudioAvailableEvent);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

Expand All @@ -60,8 +60,8 @@ nsDOMNotifyAudioAvailableEvent::~nsDOMNotifyAudioAvailableEvent()
{
MOZ_COUNT_DTOR(nsDOMNotifyAudioAvailableEvent);
if (mCachedArray) {
NS_DROP_JS_OBJECTS(this, nsDOMNotifyAudioAvailableEvent);
mCachedArray = nullptr;
NS_DROP_JS_OBJECTS(this, nsDOMNotifyAudioAvailableEvent);
}
}

Expand Down
1 change: 1 addition & 0 deletions content/media/webaudio/AudioBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ AudioBuffer::AudioBuffer(AudioContext* aContext, uint32_t aLength,

AudioBuffer::~AudioBuffer()
{
mChannels.Clear();
NS_DROP_JS_OBJECTS(this, AudioBuffer);
}

Expand Down
3 changes: 2 additions & 1 deletion content/xbl/src/nsXBLDocumentInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,9 @@ nsXBLDocumentInfo::~nsXBLDocumentInfo()
mGlobalObject->ClearGlobalObjectOwner(); // just in case
}
if (mBindingTable) {
NS_DROP_JS_OBJECTS(this, nsXBLDocumentInfo);
delete mBindingTable;
mBindingTable = nullptr;
NS_DROP_JS_OBJECTS(this, nsXBLDocumentInfo);
}
}

Expand Down
2 changes: 1 addition & 1 deletion content/xul/content/src/nsXULElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2491,8 +2491,8 @@ void
nsXULPrototypeScript::UnlinkJSObjects()
{
if (mScriptObject.mObject) {
nsContentUtils::DropJSObjects(this);
mScriptObject.mObject = nullptr;
nsContentUtils::DropJSObjects(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion dom/base/DOMRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(DOMRequest,
nsDOMEventTargetHelper)
if (tmp->mRooted) {
tmp->mResult = JSVAL_VOID;
tmp->UnrootResultVal();
}
NS_IMPL_CYCLE_COLLECTION_UNLINK(mError)
Expand Down Expand Up @@ -187,6 +186,7 @@ void
DOMRequest::UnrootResultVal()
{
NS_ASSERTION(mRooted, "Don't call me if not rooted!");
mResult = JSVAL_VOID;
NS_DROP_JS_OBJECTS(this, DOMRequest);
mRooted = false;
}
Expand Down
7 changes: 4 additions & 3 deletions dom/base/nsJSEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4144,12 +4144,13 @@ nsJSArgArray::~nsJSArgArray()
void
nsJSArgArray::ReleaseJSObjects()
{
if (mArgc > 0)
NS_DROP_JS_OBJECTS(this, nsJSArgArray);
if (mArgv) {
PR_DELETE(mArgv);
}
mArgc = 0;
if (mArgc > 0) {
mArgc = 0;
NS_DROP_JS_OBJECTS(this, nsJSArgArray);
}
}

// QueryInterface implementation for nsJSArgArray
Expand Down
15 changes: 5 additions & 10 deletions dom/base/nsJSTimeoutHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,12 @@ nsJSScriptTimeoutHandler::~nsJSScriptTimeoutHandler()
void
nsJSScriptTimeoutHandler::ReleaseJSObjects()
{
if (mExpr || mFunObj) {
if (mExpr) {
NS_DROP_JS_OBJECTS(this, nsJSScriptTimeoutHandler);
mExpr = nullptr;
} else if (mFunObj) {
NS_DROP_JS_OBJECTS(this, nsJSScriptTimeoutHandler);
mFunObj = nullptr;
} else {
NS_WARNING("No func and no expr - roots may not have been removed");
}
if (mExpr) {
mExpr = nullptr;
} else {
mFunObj = nullptr;
}
NS_DROP_JS_OBJECTS(this, nsJSScriptTimeoutHandler);
}

nsresult
Expand Down
2 changes: 1 addition & 1 deletion dom/bindings/CallbackFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ class CallbackFunction : public nsISupports
void DropCallback()
{
if (mCallable) {
NS_DROP_JS_OBJECTS(this, CallbackFunction);
mCallable = nullptr;
NS_DROP_JS_OBJECTS(this, CallbackFunction);
nsLayoutStatics::Release();
}
}
Expand Down
2 changes: 2 additions & 0 deletions dom/bluetooth/BluetoothAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ BluetoothAdapter::Unroot()
if (!mIsRooted) {
return;
}
mJsUuids = nullptr;
mJsDeviceAddresses = nullptr;
NS_DROP_JS_OBJECTS(this, BluetoothAdapter);
mIsRooted = false;
}
Expand Down
2 changes: 2 additions & 0 deletions dom/bluetooth/BluetoothDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void
BluetoothDevice::Unroot()
{
if (mIsRooted) {
mJsUuids = nullptr;
mJsServices = nullptr;
NS_DROP_JS_OBJECTS(this, BluetoothDevice);
mIsRooted = false;
}
Expand Down
2 changes: 1 addition & 1 deletion dom/devicestorage/nsDeviceStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,8 @@ nsDOMDeviceStorageCursor::Continue()
if (mRooted) {
// We call onsuccess multiple times. clear the last
// rooted result.
NS_DROP_JS_OBJECTS(this, nsDOMDeviceStorageCursor);
mResult = JSVAL_VOID;
NS_DROP_JS_OBJECTS(this, nsDOMDeviceStorageCursor);
mDone = false;
mRooted = false;
}
Expand Down
35 changes: 20 additions & 15 deletions dom/indexedDB/IDBCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,28 @@ IDBCursor::~IDBCursor()
NS_ASSERTION(!mActorChild, "Should have cleared in Send__delete__!");
}

if (mRooted) {
NS_DROP_JS_OBJECTS(this, IDBCursor);
}
DropJSObjects();
IDBObjectStore::ClearCloneReadInfo(mCloneReadInfo);
}

void
IDBCursor::DropJSObjects()
{
if (!mRooted) {
return;
}
mScriptOwner = nullptr;
mCachedKey = JSVAL_VOID;
mCachedPrimaryKey = JSVAL_VOID;
mCachedValue = JSVAL_VOID;
mHaveCachedKey = false;
mHaveCachedPrimaryKey = false;
mHaveCachedValue = false;
mRooted = false;
mHaveValue = false;
NS_DROP_JS_OBJECTS(this, IDBCursor);
}

nsresult
IDBCursor::ContinueInternal(const Key& aKey,
int32_t aCount)
Expand Down Expand Up @@ -455,18 +471,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBCursor)
// Don't unlink mObjectStore, mIndex, or mTransaction!
if (tmp->mRooted) {
NS_DROP_JS_OBJECTS(tmp, IDBCursor);
tmp->mScriptOwner = nullptr;
tmp->mCachedKey = JSVAL_VOID;
tmp->mCachedPrimaryKey = JSVAL_VOID;
tmp->mCachedValue = JSVAL_VOID;
tmp->mHaveCachedKey = false;
tmp->mHaveCachedPrimaryKey = false;
tmp->mHaveCachedValue = false;
tmp->mRooted = false;
tmp->mHaveValue = false;
}
tmp->DropJSObjects();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRequest)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

Expand Down
2 changes: 2 additions & 0 deletions dom/indexedDB/IDBCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class IDBCursor MOZ_FINAL : public nsIIDBCursorWithValue
IDBCursor();
~IDBCursor();

void DropJSObjects();

static
already_AddRefed<IDBCursor>
CreateCommon(IDBRequest* aRequest,
Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/IDBDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ IDBDatabase::~IDBDatabase()
mgr->UnregisterDatabase(this);
}
}

nsContentUtils::ReleaseWrapper(static_cast<nsIDOMEventTarget*>(this), this);
}

void
Expand Down
1 change: 1 addition & 0 deletions dom/indexedDB/IDBFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ IDBFactory::~IDBFactory()
NS_ASSERTION(!mActorChild, "Should have cleared in Send__delete__!");
}
if (mRootedOwningObject) {
mOwningObject = nullptr;
NS_DROP_JS_OBJECTS(this, IDBFactory);
}
}
Expand Down
1 change: 1 addition & 0 deletions dom/indexedDB/IDBIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ IDBIndex::~IDBIndex()
NS_ASSERTION(!mActorParent, "Actor parent owns us, how can we be dying?!");

if (mRooted) {
mCachedKeyPath = JSVAL_VOID;
NS_DROP_JS_OBJECTS(this, IDBIndex);
}

Expand Down
27 changes: 16 additions & 11 deletions dom/indexedDB/IDBKeyRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,7 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(IDBKeyRange)
NS_IMPL_CYCLE_COLLECTION_TRACE_END

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(IDBKeyRange)
if (tmp->mRooted) {
NS_DROP_JS_OBJECTS(tmp, IDBKeyRange);
tmp->mCachedLowerVal = JSVAL_VOID;
tmp->mCachedUpperVal = JSVAL_VOID;
tmp->mHaveCachedLowerVal = false;
tmp->mHaveCachedUpperVal = false;
tmp->mRooted = false;
}
tmp->DropJSObjects();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(IDBKeyRange)
Expand All @@ -339,11 +332,23 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(IDBKeyRange)

DOMCI_DATA(IDBKeyRange, IDBKeyRange)

IDBKeyRange::~IDBKeyRange()
void
IDBKeyRange::DropJSObjects()
{
if (mRooted) {
NS_DROP_JS_OBJECTS(this, IDBKeyRange);
if (!mRooted) {
return;
}
mCachedLowerVal = JSVAL_VOID;
mCachedUpperVal = JSVAL_VOID;
mHaveCachedLowerVal = false;
mHaveCachedUpperVal = false;
mRooted = false;
NS_DROP_JS_OBJECTS(this, IDBKeyRange);
}

IDBKeyRange::~IDBKeyRange()
{
DropJSObjects();
}

NS_IMETHODIMP
Expand Down
2 changes: 2 additions & 0 deletions dom/indexedDB/IDBKeyRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ class IDBKeyRange MOZ_FINAL : public nsIIDBKeyRange
template <class T>
void ToSerializedKeyRange(T& aKeyRange);

void DropJSObjects();

private:
~IDBKeyRange();

Expand Down
1 change: 1 addition & 0 deletions dom/indexedDB/IDBObjectStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ IDBObjectStore::~IDBObjectStore()
}

if (mRooted) {
mCachedKeyPath = JSVAL_VOID;
NS_DROP_JS_OBJECTS(this, IDBObjectStore);
}
}
Expand Down
1 change: 1 addition & 0 deletions dom/indexedDB/IDBRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ IDBRequest::IDBRequest()

IDBRequest::~IDBRequest()
{
mResultVal = JSVAL_VOID;
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
}

Expand Down
2 changes: 0 additions & 2 deletions dom/indexedDB/IDBTransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ IDBTransaction::~IDBTransaction()
mActorChild->Send__delete__(mActorChild);
NS_ASSERTION(!mActorChild, "Should have cleared in Send__delete__!");
}

nsContentUtils::ReleaseWrapper(static_cast<nsIDOMEventTarget*>(this), this);
}

void
Expand Down
8 changes: 4 additions & 4 deletions dom/indexedDB/IDBWrapperCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBWrapperCache,
nsDOMEventTargetHelper)
if (tmp->mScriptOwner) {
NS_DROP_JS_OBJECTS(tmp, IDBWrapperCache);
tmp->mScriptOwner = nullptr;
NS_DROP_JS_OBJECTS(tmp, IDBWrapperCache);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

Expand All @@ -40,9 +40,9 @@ NS_IMPL_RELEASE_INHERITED(IDBWrapperCache, nsDOMEventTargetHelper)

IDBWrapperCache::~IDBWrapperCache()
{
if (mScriptOwner) {
NS_DROP_JS_OBJECTS(this, IDBWrapperCache);
}
mScriptOwner = nullptr;
nsContentUtils::ReleaseWrapper(this, this);
NS_DROP_JS_OBJECTS(this, IDBWrapperCache);
}

bool
Expand Down
Loading

0 comments on commit b0e3eff

Please sign in to comment.