#ifndef JSClassRef_h
#define JSClassRef_h
#include "OpaqueJSString.h"
#include "Protect.h"
#include "Weak.h"
#include <JavaScriptCore/JSObjectRef.h>
#include <wtf/HashMap.h>
#include <wtf/text/WTFString.h>
struct StaticValueEntry {
WTF_MAKE_FAST_ALLOCATED;
public:
StaticValueEntry(JSObjectGetPropertyCallback _getProperty, JSObjectSetPropertyCallback _setProperty, JSPropertyAttributes _attributes, String& propertyName)
: getProperty(_getProperty)
, setProperty(_setProperty)
, attributes(_attributes)
, propertyNameRef(OpaqueJSString::tryCreate(propertyName))
{
}
JSObjectGetPropertyCallback getProperty;
JSObjectSetPropertyCallback setProperty;
JSPropertyAttributes attributes;
RefPtr<OpaqueJSString> propertyNameRef;
};
struct StaticFunctionEntry {
WTF_MAKE_FAST_ALLOCATED;
public:
StaticFunctionEntry(JSObjectCallAsFunctionCallback _callAsFunction, JSPropertyAttributes _attributes)
: callAsFunction(_callAsFunction), attributes(_attributes)
{
}
JSObjectCallAsFunctionCallback callAsFunction;
JSPropertyAttributes attributes;
};
typedef HashMap<RefPtr<StringImpl>, std::unique_ptr<StaticValueEntry>> OpaqueJSClassStaticValuesTable;
typedef HashMap<RefPtr<StringImpl>, std::unique_ptr<StaticFunctionEntry>> OpaqueJSClassStaticFunctionsTable;
struct OpaqueJSClass;
struct OpaqueJSClassContextData {
WTF_MAKE_NONCOPYABLE(OpaqueJSClassContextData); WTF_MAKE_FAST_ALLOCATED;
public:
OpaqueJSClassContextData(JSC::VM&, OpaqueJSClass*);
RefPtr<OpaqueJSClass> m_class;
std::unique_ptr<OpaqueJSClassStaticValuesTable> staticValues;
std::unique_ptr<OpaqueJSClassStaticFunctionsTable> staticFunctions;
JSC::Weak<JSC::JSObject> cachedPrototype;
};
struct OpaqueJSClass : public ThreadSafeRefCounted<OpaqueJSClass> {
static Ref<OpaqueJSClass> create(const JSClassDefinition*);
static Ref<OpaqueJSClass> createNoAutomaticPrototype(const JSClassDefinition*);
JS_EXPORT_PRIVATE ~OpaqueJSClass();
String className();
OpaqueJSClassStaticValuesTable* staticValues(JSC::JSGlobalObject*);
OpaqueJSClassStaticFunctionsTable* staticFunctions(JSC::JSGlobalObject*);
JSC::JSObject* prototype(JSC::JSGlobalObject*);
OpaqueJSClass* parentClass;
OpaqueJSClass* prototypeClass;
JSObjectInitializeCallback initialize;
JSObjectFinalizeCallback finalize;
JSObjectHasPropertyCallback hasProperty;
JSObjectGetPropertyCallback getProperty;
JSObjectSetPropertyCallback setProperty;
JSObjectDeletePropertyCallback deleteProperty;
JSObjectGetPropertyNamesCallback getPropertyNames;
JSObjectCallAsFunctionCallback callAsFunction;
JSObjectCallAsConstructorCallback callAsConstructor;
JSObjectHasInstanceCallback hasInstance;
JSObjectConvertToTypeCallback convertToType;
private:
friend struct OpaqueJSClassContextData;
OpaqueJSClass();
OpaqueJSClass(const OpaqueJSClass&);
OpaqueJSClass(const JSClassDefinition*, OpaqueJSClass* protoClass);
OpaqueJSClassContextData& contextData(JSC::JSGlobalObject*);
String m_className;
std::unique_ptr<OpaqueJSClassStaticValuesTable> m_staticValues;
std::unique_ptr<OpaqueJSClassStaticFunctionsTable> m_staticFunctions;
};
#endif // JSClassRef_h