Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsCycleCollectionParticipant.h" |
michael@0 | 7 | #include "nsCOMPtr.h" |
michael@0 | 8 | #include "jsapi.h" |
michael@0 | 9 | |
michael@0 | 10 | #ifdef MOZILLA_INTERNAL_API |
michael@0 | 11 | #include "nsString.h" |
michael@0 | 12 | #else |
michael@0 | 13 | #include "nsStringAPI.h" |
michael@0 | 14 | #endif |
michael@0 | 15 | |
michael@0 | 16 | void |
michael@0 | 17 | nsScriptObjectTracer::NoteJSChild(void *aScriptThing, const char *name, |
michael@0 | 18 | void *aClosure) |
michael@0 | 19 | { |
michael@0 | 20 | nsCycleCollectionTraversalCallback *cb = |
michael@0 | 21 | static_cast<nsCycleCollectionTraversalCallback*>(aClosure); |
michael@0 | 22 | NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, name); |
michael@0 | 23 | cb->NoteJSChild(aScriptThing); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMETHODIMP_(void) |
michael@0 | 27 | nsXPCOMCycleCollectionParticipant::Root(void *p) |
michael@0 | 28 | { |
michael@0 | 29 | nsISupports *s = static_cast<nsISupports*>(p); |
michael@0 | 30 | NS_ADDREF(s); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | NS_IMETHODIMP_(void) |
michael@0 | 34 | nsXPCOMCycleCollectionParticipant::Unroot(void *p) |
michael@0 | 35 | { |
michael@0 | 36 | nsISupports *s = static_cast<nsISupports*>(p); |
michael@0 | 37 | NS_RELEASE(s); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | // We define a default trace function because some participants don't need |
michael@0 | 41 | // to trace anything, so it is okay for them not to define one. |
michael@0 | 42 | NS_IMETHODIMP_(void) |
michael@0 | 43 | nsXPCOMCycleCollectionParticipant::Trace(void *p, const TraceCallbacks &cb, |
michael@0 | 44 | void *closure) |
michael@0 | 45 | { |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | bool |
michael@0 | 49 | nsXPCOMCycleCollectionParticipant::CheckForRightISupports(nsISupports *s) |
michael@0 | 50 | { |
michael@0 | 51 | nsISupports* foo; |
michael@0 | 52 | s->QueryInterface(NS_GET_IID(nsCycleCollectionISupports), |
michael@0 | 53 | reinterpret_cast<void**>(&foo)); |
michael@0 | 54 | return s == foo; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | void |
michael@0 | 58 | CycleCollectionNoteEdgeNameImpl(nsCycleCollectionTraversalCallback& aCallback, |
michael@0 | 59 | const char* aName, |
michael@0 | 60 | uint32_t aFlags) |
michael@0 | 61 | { |
michael@0 | 62 | nsAutoCString arrayEdgeName(aName); |
michael@0 | 63 | if (aFlags & CycleCollectionEdgeNameArrayFlag) { |
michael@0 | 64 | arrayEdgeName.AppendLiteral("[i]"); |
michael@0 | 65 | } |
michael@0 | 66 | aCallback.NoteNextEdgeName(arrayEdgeName.get()); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | void |
michael@0 | 70 | TraceCallbackFunc::Trace(JS::Heap<JS::Value>* p, const char* name, void* closure) const |
michael@0 | 71 | { |
michael@0 | 72 | if (p->isMarkable()) { |
michael@0 | 73 | mCallback(p->toGCThing(), name, closure); |
michael@0 | 74 | } |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | void |
michael@0 | 78 | TraceCallbackFunc::Trace(JS::Heap<jsid>* p, const char* name, void* closure) const |
michael@0 | 79 | { |
michael@0 | 80 | void *thing = JSID_TO_GCTHING(*p); |
michael@0 | 81 | if (thing) { |
michael@0 | 82 | mCallback(thing, name, closure); |
michael@0 | 83 | } |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | void |
michael@0 | 87 | TraceCallbackFunc::Trace(JS::Heap<JSObject*>* p, const char* name, void* closure) const |
michael@0 | 88 | { |
michael@0 | 89 | mCallback(*p, name, closure); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void |
michael@0 | 93 | TraceCallbackFunc::Trace(JS::TenuredHeap<JSObject*>* p, const char* name, void* closure) const |
michael@0 | 94 | { |
michael@0 | 95 | mCallback(*p, name, closure); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | void |
michael@0 | 99 | TraceCallbackFunc::Trace(JS::Heap<JSFunction*>* p, const char* name, void* closure) const |
michael@0 | 100 | { |
michael@0 | 101 | mCallback(*p, name, closure); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | void |
michael@0 | 105 | TraceCallbackFunc::Trace(JS::Heap<JSString*>* p, const char* name, void* closure) const |
michael@0 | 106 | { |
michael@0 | 107 | mCallback(*p, name, closure); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | void |
michael@0 | 111 | TraceCallbackFunc::Trace(JS::Heap<JSScript*>* p, const char* name, void* closure) const |
michael@0 | 112 | { |
michael@0 | 113 | mCallback(p->get(), name, closure); |
michael@0 | 114 | } |