ScriptLoadRequestList.cpp (2238B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "ScriptLoadRequestList.h" 8 9 #include "ScriptLoadRequest.h" 10 11 namespace JS::loader { 12 13 ////////////////////////////////////////////////////////////// 14 // ScriptLoadRequestList 15 ////////////////////////////////////////////////////////////// 16 17 ScriptLoadRequestList::~ScriptLoadRequestList() { CancelRequestsAndClear(); } 18 19 void ScriptLoadRequestList::CancelRequestsAndClear() { 20 while (!isEmpty()) { 21 RefPtr<ScriptLoadRequest> first = StealFirst(); 22 first->Cancel(); 23 // And just let it go out of scope and die. 24 } 25 } 26 27 #ifdef DEBUG 28 bool ScriptLoadRequestList::Contains(ScriptLoadRequest* aElem) const { 29 for (const ScriptLoadRequest* req = getFirst(); req; req = req->getNext()) { 30 if (req == aElem) { 31 return true; 32 } 33 } 34 35 return false; 36 } 37 #endif // DEBUG 38 39 void ScriptLoadRequestList::AppendElement(ScriptLoadRequest* aElem) { 40 MOZ_ASSERT(!aElem->isInList()); 41 NS_ADDREF(aElem); 42 insertBack(aElem); 43 } 44 45 already_AddRefed<ScriptLoadRequest> ScriptLoadRequestList::Steal( 46 ScriptLoadRequest* aElem) { 47 aElem->removeFrom(*this); 48 return dont_AddRef(aElem); 49 } 50 51 already_AddRefed<ScriptLoadRequest> ScriptLoadRequestList::StealFirst() { 52 MOZ_ASSERT(!isEmpty()); 53 return Steal(getFirst()); 54 } 55 56 void ScriptLoadRequestList::Remove(ScriptLoadRequest* aElem) { 57 aElem->removeFrom(*this); 58 NS_RELEASE(aElem); 59 } 60 61 void ImplCycleCollectionUnlink(ScriptLoadRequestList& aField) { 62 while (!aField.isEmpty()) { 63 RefPtr<ScriptLoadRequest> first = aField.StealFirst(); 64 } 65 } 66 67 void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, 68 ScriptLoadRequestList& aField, 69 const char* aName, uint32_t aFlags) { 70 for (ScriptLoadRequest* request = aField.getFirst(); request; 71 request = request->getNext()) { 72 CycleCollectionNoteChild(aCallback, request, aName, aFlags); 73 } 74 } 75 76 } // namespace JS::loader