#ifndef RUNTIME_ROOT_H_
#define RUNTIME_ROOT_H_
#include <JavaScriptCore/Strong.h>
#include <JavaScriptCore/Weak.h>
#include <JavaScriptCore/WeakInlines.h>
#include <wtf/Forward.h>
#include <wtf/HashCountedSet.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefCounted.h>
namespace JSC {
class Interpreter;
class JSGlobalObject;
namespace Bindings {
class RootObject;
class RuntimeObject;
typedef HashCountedSet<JSObject*> ProtectCountSet;
extern RootObject* findProtectingRootObject(JSObject*);
extern RootObject* findRootObject(JSGlobalObject*);
class RootObject : public RefCounted<RootObject>, private JSC::WeakHandleOwner {
friend class JavaJSObject;
public:
WEBCORE_EXPORT virtual ~RootObject();
static Ref<RootObject> create(const void* nativeHandle, JSGlobalObject*);
bool isValid() { return m_isValid; }
void invalidate();
void gcProtect(JSObject*);
void gcUnprotect(JSObject*);
bool gcIsProtected(JSObject*);
const void* nativeHandle() const;
WEBCORE_EXPORT JSGlobalObject* globalObject() const;
void updateGlobalObject(JSGlobalObject*);
void addRuntimeObject(VM&, RuntimeObject*);
void removeRuntimeObject(RuntimeObject*);
struct InvalidationCallback {
virtual void operator()(RootObject*) = 0;
virtual ~InvalidationCallback();
};
void addInvalidationCallback(InvalidationCallback* callback) { m_invalidationCallbacks.add(callback); }
private:
RootObject(const void* nativeHandle, JSGlobalObject*);
void finalize(JSC::Handle<JSC::Unknown>, void* context) override;
bool m_isValid;
const void* m_nativeHandle;
Strong<JSGlobalObject> m_globalObject;
ProtectCountSet m_protectCountSet;
HashMap<RuntimeObject*, JSC::Weak<RuntimeObject>> m_runtimeObjects;
HashSet<InvalidationCallback*> m_invalidationCallbacks;
};
}
}
#endif // RUNTIME_ROOT_H_