This source file includes following definitions.
- instanceTemplate
- hasInstance
- derefObject
- createWrapper
- toNative
- toNativeWithTypeCheck
- toV8NoInline
#include "config.h"
#include "bindings/v8/custom/V8ArrayBufferCustom.h"
#include "bindings/v8/V8Binding.h"
#include "wtf/ArrayBuffer.h"
#include "wtf/StdLibExtras.h"
namespace WebCore {
using namespace WTF;
V8ArrayBufferDeallocationObserver* V8ArrayBufferDeallocationObserver::instanceTemplate()
{
DEFINE_STATIC_LOCAL(V8ArrayBufferDeallocationObserver, deallocationObserver, ());
return &deallocationObserver;
}
const WrapperTypeInfo V8ArrayBuffer::wrapperTypeInfo = {
gin::kEmbedderBlink,
0, V8ArrayBuffer::derefObject,
0, 0, 0, 0, 0, WrapperTypeObjectPrototype, false
};
bool V8ArrayBuffer::hasInstance(v8::Handle<v8::Value> value, v8::Isolate*)
{
return value->IsArrayBuffer();
}
void V8ArrayBuffer::derefObject(void* object)
{
static_cast<ArrayBuffer*>(object)->deref();
}
v8::Handle<v8::Object> V8ArrayBuffer::createWrapper(PassRefPtr<ArrayBuffer> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
ASSERT(impl.get());
ASSERT(!DOMDataStore::containsWrapper<V8ArrayBuffer>(impl.get(), isolate));
v8::Handle<v8::Object> wrapper = v8::ArrayBuffer::New(isolate, impl->data(), impl->byteLength());
impl->setDeallocationObserver(V8ArrayBufferDeallocationObserver::instanceTemplate());
V8DOMWrapper::associateObjectWithWrapper<V8ArrayBuffer>(impl, &wrapperTypeInfo, wrapper, isolate, WrapperConfiguration::Independent);
return wrapper;
}
ArrayBuffer* V8ArrayBuffer::toNative(v8::Handle<v8::Object> object)
{
ASSERT(object->IsArrayBuffer());
v8::Local<v8::ArrayBuffer> v8buffer = object.As<v8::ArrayBuffer>();
if (v8buffer->IsExternal()) {
RELEASE_ASSERT(toWrapperTypeInfo(object)->ginEmbedder == gin::kEmbedderBlink);
return reinterpret_cast<ArrayBuffer*>(WebCore::toNative(object));
}
v8::ArrayBuffer::Contents v8Contents = v8buffer->Externalize();
ArrayBufferContents contents(v8Contents.Data(), v8Contents.ByteLength(),
V8ArrayBufferDeallocationObserver::instanceTemplate());
RefPtr<ArrayBuffer> buffer = ArrayBuffer::create(contents);
V8DOMWrapper::associateObjectWithWrapper<V8ArrayBuffer>(buffer.release(), &wrapperTypeInfo, object, v8::Isolate::GetCurrent(), WrapperConfiguration::Dependent);
return reinterpret_cast<ArrayBuffer*>(WebCore::toNative(object));
}
ArrayBuffer* V8ArrayBuffer::toNativeWithTypeCheck(v8::Isolate* isolate, v8::Handle<v8::Value> value)
{
return V8ArrayBuffer::hasInstance(value, isolate) ? V8ArrayBuffer::toNative(v8::Handle<v8::Object>::Cast(value)) : 0;
}
template<>
v8::Handle<v8::Value> toV8NoInline(ArrayBuffer* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
{
return toV8(impl, creationContext, isolate);
}
}