Files
roytam1 27926d796f import changes from `dev' branch of rmottola/Arctic-Fox:
- fix assertion (528f0d0b2)
- fix assertion (8ca4607ca)
- fix broken assertions (8c64c1865)
- fix debug code (6e37f6aa7)
- remove broken assertion (090f9987d)
- fix assertion according to bug Bug 1328251 (b3835e0c5)
- fix debug code (f7a2841e6)
- Bug 1226241 - Use a #define instead of a magic number for self-hosted function name accesses. r=jandem (01e2ec474)
-  Bug 1235656 - Part 1: Set canonical name in self-hosted builtins. r=till (43cbd7cb9)
- Bug 912701 - When removing Unicode extension sequences from a locale, ignore similar syntax that might be found in a privateuse component. r=abargull (1524a8b48)
- remove broken assert (a93490758)
- remove broken assert (0ddc7e143)
- fix missing bracket (c4f524729)
- Bug 1179924 - Create a more modern JS object holder for cross-thread references to JS objects. r=smaug (0804d24cf)
2021-10-19 09:47:04 +08:00

43 lines
1.3 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_JSObjectHolder_h
#define mozilla_JSObjectHolder_h
#include "js/RootingAPI.h"
#include "nsISupportsImpl.h"
namespace mozilla {
// This class is useful when something on one thread needs to keep alive
// a JS Object from another thread. If they are both on the same thread, the
// owning class should instead be made a cycle collected SCRIPT_HOLDER class.
// This object should only be AddRefed and Released on the same thread as
// mJSObject.
//
// Note that this keeps alive the JS object until it goes away, so be sure not to
// create cycles that keep alive the holder.
//
// JSObjectHolder is ISupports to make it usable with NS_ReleaseOnMainThread.
class JSObjectHolder final : public nsISupports
{
public:
JSObjectHolder(JSContext* aCx, JSObject* aObject) : mJSObject(aCx, aObject) {}
NS_DECL_ISUPPORTS
JSObject* GetJSObject() { return mJSObject; }
private:
~JSObjectHolder() {}
JS::PersistentRooted<JSObject*> mJSObject;
};
} // namespace mozilla
#endif // mozilla_JSObjectHolder_h