|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=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 file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_dom_indexeddb_idbwrappercache_h__ |
|
8 #define mozilla_dom_indexeddb_idbwrappercache_h__ |
|
9 |
|
10 #include "mozilla/DOMEventTargetHelper.h" |
|
11 #include "mozilla/dom/indexedDB/IndexedDatabase.h" |
|
12 |
|
13 BEGIN_INDEXEDDB_NAMESPACE |
|
14 |
|
15 class IDBWrapperCache : public DOMEventTargetHelper |
|
16 { |
|
17 public: |
|
18 NS_DECL_ISUPPORTS_INHERITED |
|
19 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED( |
|
20 IDBWrapperCache, |
|
21 DOMEventTargetHelper) |
|
22 |
|
23 JSObject* GetScriptOwner() const |
|
24 { |
|
25 return mScriptOwner; |
|
26 } |
|
27 void SetScriptOwner(JSObject* aScriptOwner); |
|
28 |
|
29 JSObject* GetParentObject() |
|
30 { |
|
31 if (mScriptOwner) { |
|
32 return mScriptOwner; |
|
33 } |
|
34 |
|
35 // Do what nsEventTargetSH::PreCreate does. |
|
36 nsCOMPtr<nsIScriptGlobalObject> parent; |
|
37 DOMEventTargetHelper::GetParentObject(getter_AddRefs(parent)); |
|
38 |
|
39 return parent ? parent->GetGlobalJSObject() : nullptr; |
|
40 } |
|
41 |
|
42 #ifdef DEBUG |
|
43 void AssertIsRooted() const; |
|
44 #else |
|
45 inline void AssertIsRooted() const |
|
46 { |
|
47 } |
|
48 #endif |
|
49 |
|
50 protected: |
|
51 IDBWrapperCache(DOMEventTargetHelper* aOwner) |
|
52 : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr) |
|
53 { } |
|
54 IDBWrapperCache(nsPIDOMWindow* aOwner) |
|
55 : DOMEventTargetHelper(aOwner), mScriptOwner(nullptr) |
|
56 { } |
|
57 |
|
58 virtual ~IDBWrapperCache(); |
|
59 |
|
60 private: |
|
61 JS::Heap<JSObject*> mScriptOwner; |
|
62 }; |
|
63 |
|
64 END_INDEXEDDB_NAMESPACE |
|
65 |
|
66 #endif // mozilla_dom_indexeddb_idbwrappercache_h__ |