/src/mozilla-central/xpcom/base/JSObjectHolder.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef mozilla_JSObjectHolder_h |
8 | | #define mozilla_JSObjectHolder_h |
9 | | |
10 | | #include "js/RootingAPI.h" |
11 | | #include "nsISupportsImpl.h" |
12 | | |
13 | | namespace mozilla { |
14 | | |
15 | | // This class is useful when something on one thread needs to keep alive |
16 | | // a JS Object from another thread. If they are both on the same thread, the |
17 | | // owning class should instead be made a cycle collected SCRIPT_HOLDER class. |
18 | | // This object should only be AddRefed and Released on the same thread as |
19 | | // mJSObject. |
20 | | // |
21 | | // Note that this keeps alive the JS object until it goes away, so be sure not to |
22 | | // create cycles that keep alive the holder. |
23 | | // |
24 | | // JSObjectHolder is ISupports to make it usable with |
25 | | // NS_ReleaseOnMainThreadSystemGroup. |
26 | | class JSObjectHolder final : public nsISupports |
27 | | { |
28 | | public: |
29 | | JSObjectHolder(JSContext* aCx, JSObject* aObject) : mJSObject(aCx, aObject) {} |
30 | | |
31 | | NS_DECL_ISUPPORTS |
32 | | |
33 | | JSObject* GetJSObject() { return mJSObject; } |
34 | | |
35 | | private: |
36 | 0 | ~JSObjectHolder() {} |
37 | | |
38 | | JS::PersistentRooted<JSObject*> mJSObject; |
39 | | }; |
40 | | |
41 | | } // namespace mozilla |
42 | | |
43 | | #endif // mozilla_JSObjectHolder_h |