This source file includes following definitions.
- initializeScriptWrappableHelper
#ifndef ScriptWrappable_h
#define ScriptWrappable_h
#include "bindings/v8/UnsafePersistent.h"
#include "bindings/v8/WrapperTypeInfo.h"
#include "heap/Handle.h"
#include <v8.h>
template <class C> inline void initializeScriptWrappableHelper(C* object)
{
void webCoreInitializeScriptWrappableForInterface(C*);
webCoreInitializeScriptWrappableForInterface(object);
}
namespace WebCore {
class ScriptWrappable {
public:
ScriptWrappable() : m_wrapperOrTypeInfo(0) { }
template <class C> static void init(C* object)
{
initializeScriptWrappableHelper(object);
}
void setWrapper(v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
{
ASSERT(!containsWrapper());
if (!*wrapper) {
m_wrapperOrTypeInfo = 0;
return;
}
v8::Persistent<v8::Object> persistent(isolate, wrapper);
configuration.configureWrapper(&persistent);
persistent.SetWeak(this, &setWeakCallback);
m_wrapperOrTypeInfo = reinterpret_cast<uintptr_t>(persistent.ClearAndLeak()) | 1;
ASSERT(containsWrapper());
}
v8::Local<v8::Object> newLocalWrapper(v8::Isolate* isolate) const
{
return unsafePersistent().newLocal(isolate);
}
const WrapperTypeInfo* typeInfo()
{
if (containsTypeInfo())
return reinterpret_cast<const WrapperTypeInfo*>(m_wrapperOrTypeInfo);
if (containsWrapper())
return toWrapperTypeInfo(*(unsafePersistent().persistent()));
return 0;
}
void setTypeInfo(const WrapperTypeInfo* typeInfo)
{
m_wrapperOrTypeInfo = reinterpret_cast<uintptr_t>(typeInfo);
ASSERT(containsTypeInfo());
}
static bool wrapperCanBeStoredInObject(const void*) { return false; }
static bool wrapperCanBeStoredInObject(const ScriptWrappable*) { return true; }
static void setWrapperInObject(void*, v8::Handle<v8::Object>, v8::Isolate*, const WrapperConfiguration&)
{
ASSERT_NOT_REACHED();
}
static void setWrapperInObject(ScriptWrappable* object, v8::Handle<v8::Object> wrapper, v8::Isolate* isolate, const WrapperConfiguration& configuration)
{
object->setWrapper(wrapper, isolate, configuration);
}
static const WrapperTypeInfo* getTypeInfoFromObject(void* object)
{
ASSERT_NOT_REACHED();
return 0;
}
static const WrapperTypeInfo* getTypeInfoFromObject(ScriptWrappable* object)
{
return object->typeInfo();
}
static void setTypeInfoInObject(void* object, const WrapperTypeInfo*)
{
ASSERT_NOT_REACHED();
}
static void setTypeInfoInObject(ScriptWrappable* object, const WrapperTypeInfo* typeInfo)
{
object->setTypeInfo(typeInfo);
}
template<typename V8T, typename T>
static bool setReturnValueWithSecurityCheck(v8::ReturnValue<v8::Value> returnValue, T* object)
{
return ScriptWrappable::getUnsafeWrapperFromObject(object).template setReturnValueWithSecurityCheck<V8T>(returnValue, object);
}
template<typename T>
static bool setReturnValue(v8::ReturnValue<v8::Value> returnValue, T* object)
{
return ScriptWrappable::getUnsafeWrapperFromObject(object).setReturnValue(returnValue);
}
protected:
~ScriptWrappable()
{
RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(!containsWrapper());
ASSERT(m_wrapperOrTypeInfo);
m_wrapperOrTypeInfo = 0;
}
private:
friend class MinorGCWrapperVisitor;
friend class DOMDataStore;
UnsafePersistent<v8::Object> unsafePersistent() const
{
v8::Object* object = containsWrapper() ? reinterpret_cast<v8::Object*>(m_wrapperOrTypeInfo & ~1) : 0;
return UnsafePersistent<v8::Object>(object);
}
static UnsafePersistent<v8::Object> getUnsafeWrapperFromObject(void*)
{
ASSERT_NOT_REACHED();
return UnsafePersistent<v8::Object>();
}
static UnsafePersistent<v8::Object> getUnsafeWrapperFromObject(ScriptWrappable* object)
{
return object->unsafePersistent();
}
inline bool containsWrapper() const { return (m_wrapperOrTypeInfo & 1) == 1; }
inline bool containsTypeInfo() const { return m_wrapperOrTypeInfo && (m_wrapperOrTypeInfo & 1) == 0; }
inline void disposeWrapper(v8::Local<v8::Object> wrapper)
{
ASSERT(containsWrapper());
ASSERT(wrapper == *unsafePersistent().persistent());
unsafePersistent().dispose();
setTypeInfo(toWrapperTypeInfo(wrapper));
}
uintptr_t m_wrapperOrTypeInfo;
static void setWeakCallback(const v8::WeakCallbackData<v8::Object, ScriptWrappable>& data)
{
ASSERT(*data.GetParameter()->unsafePersistent().persistent() == data.GetValue());
data.GetParameter()->disposeWrapper(data.GetValue());
releaseObject(data.GetValue());
}
};
}
#endif