#pragma once
#include "ArrayBuffer.h"
#include "JSObject.h"
namespace JSC {
class JSArrayBuffer : public JSNonFinalObject {
public:
typedef JSNonFinalObject Base;
static const unsigned StructureFlags = Base::StructureFlags | OverridesGetPropertyNames | OverridesGetOwnPropertySlot;
protected:
JSArrayBuffer(VM&, Structure*, PassRefPtr<ArrayBuffer>);
void finishCreation(VM&, JSGlobalObject*);
public:
JS_EXPORT_PRIVATE static JSArrayBuffer* create(VM&, Structure*, PassRefPtr<ArrayBuffer>);
ArrayBuffer* impl() const { return m_impl; }
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
JS_EXPORT_PRIVATE bool isShared() const;
ArrayBufferSharingMode sharingMode() const;
DECLARE_EXPORT_INFO;
static ArrayBuffer* toWrapped(JSValue);
protected:
static size_t estimatedSize(JSCell*);
static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
static bool deleteProperty(JSCell*, ExecState*, PropertyName);
static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
private:
ArrayBuffer* m_impl;
};
inline ArrayBuffer* toPossiblySharedArrayBuffer(JSValue value)
{
JSArrayBuffer* wrapper = jsDynamicCast<JSArrayBuffer*>(value);
if (!wrapper)
return nullptr;
return wrapper->impl();
}
inline ArrayBuffer* toUnsharedArrayBuffer(JSValue value)
{
ArrayBuffer* result = toPossiblySharedArrayBuffer(value);
if (!result || result->isShared())
return nullptr;
return result;
}
inline ArrayBuffer* JSArrayBuffer::toWrapped(JSValue value)
{
return toUnsharedArrayBuffer(value);
}
}