#pragma once
#include "JSBase.h"
#include "VM.h"
#include "WeakGCMap.h"
#include <glib.h>
#include <wtf/HashMap.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/text/CString.h>
typedef struct _JSCClass JSCClass;
typedef struct _JSCContext JSCContext;
typedef struct _JSCValue JSCValue;
namespace JSC {
class JSObject;
class WrapperMap {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit WrapperMap(JSGlobalContextRef);
~WrapperMap();
GRefPtr<JSCValue> gobjectWrapper(JSCContext*, JSValueRef);
void unwrap(JSValueRef);
void registerClass(JSCClass*);
JSCClass* registeredClass(JSClassRef) const;
JSObject* createJSWrappper(JSGlobalContextRef, JSClassRef, JSValueRef prototype, gpointer, GDestroyNotify);
JSGlobalContextRef createContextWithJSWrappper(JSContextGroupRef, JSClassRef, JSValueRef prototype, gpointer, GDestroyNotify);
JSObject* jsWrapper(gpointer wrappedObject) const;
gpointer wrappedObject(JSGlobalContextRef, JSObjectRef) const;
private:
HashMap<JSValueRef, JSCValue*> m_cachedGObjectWrappers;
std::unique_ptr<JSC::WeakGCMap<gpointer, JSC::JSObject>> m_cachedJSWrappers;
HashMap<JSClassRef, GRefPtr<JSCClass>> m_classMap;
};
}