Bug 1893155 - Part 1: Make Calendar{WeekOfYear,YearOfWeek} return undefined. r=spider...
[gecko.git] / xpcom / base / JSObjectHolder.h
blobd64d41e47989862408360f9c922e8b4870994bca
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/. */
7 #ifndef mozilla_JSObjectHolder_h
8 #define mozilla_JSObjectHolder_h
10 #include "js/RootingAPI.h"
11 #include "nsISupportsImpl.h"
13 namespace mozilla {
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.
21 // Note that this keeps alive the JS object until it goes away, so be sure not
22 // to create cycles that keep alive the holder.
24 // JSObjectHolder is ISupports to make it usable with
25 // NS_ReleaseOnMainThread.
26 class JSObjectHolder final : public nsISupports {
27 public:
28 JSObjectHolder(JSContext* aCx, JSObject* aObject) : mJSObject(aCx, aObject) {}
30 NS_DECL_ISUPPORTS
32 JSObject* GetJSObject() { return mJSObject; }
34 private:
35 ~JSObjectHolder() = default;
37 JS::PersistentRooted<JSObject*> mJSObject;
40 } // namespace mozilla
42 #endif // mozilla_JSObjectHolder_h