#ifndef RUNTIME_ROOT_H_
#define RUNTIME_ROOT_H_
#include "interpreter.h"
#if PLATFORM(MAC)
#include "jni_jsobject.h"
#endif
#include "protect.h"
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
namespace KJS {
class RuntimeObjectImp;
namespace Bindings {
class RootObject;
typedef PassRefPtr<RootObject> (*CreateRootObjectFunction)(void* nativeHandle);
typedef HashCountedSet<JSObject*> ProtectCountSet;
extern RootObject* findRootObject(JSObject*);
extern RootObject* findRootObject(Interpreter*);
class RootObject : Noncopyable
{
friend class JavaJSObject;
public:
static PassRefPtr<RootObject> create(const void* nativeHandle, PassRefPtr<Interpreter> interpreter);
void ref() { m_refCount++; }
void deref()
{
if (--m_refCount == 0)
delete this;
}
bool isValid() { return m_isValid; }
void invalidate();
void gcProtect(JSObject*);
void gcUnprotect(JSObject*);
bool gcIsProtected(JSObject*);
const void* nativeHandle() const;
Interpreter* interpreter() const;
#if PLATFORM(MAC)
static void setCreateRootObject(CreateRootObjectFunction);
static CreateRootObjectFunction createRootObject() {
return _createRootObject;
}
static CFRunLoopRef runLoop() { return _runLoop; }
static CFRunLoopSourceRef performJavaScriptSource() { return _performJavaScriptSource; }
static void dispatchToJavaScriptThread(JSObjectCallContext *context);
#endif
void addRuntimeObject(RuntimeObjectImp*);
void removeRuntimeObject(RuntimeObjectImp*);
private:
RootObject(const void* nativeHandle, PassRefPtr<Interpreter> interpreter);
~RootObject();
unsigned m_refCount;
bool m_isValid;
const void* m_nativeHandle;
RefPtr<Interpreter> m_interpreter;
ProtectCountSet m_protectCountSet;
HashSet<RuntimeObjectImp*> m_runtimeObjects;
#if PLATFORM(MAC)
static CreateRootObjectFunction _createRootObject;
static CFRunLoopRef _runLoop;
static CFRunLoopSourceRef _performJavaScriptSource;
#endif
};
}
}
#endif