#include "V8ArrayBuffer.h" namespace Arabica { namespace DOM { v8::Persistent V8ArrayBuffer::Tmpl; v8::Persistent V8ArrayBuffer::Constr; v8::Handle V8ArrayBuffer::constructor(const v8::Arguments& args) { if (!args.IsConstructCall()) return v8::ThrowException(v8::String::New("Cannot call constructor as function")); uscxml::ArrayBuffer* localInstance = NULL; if (false) { } else if (args.Length() == 1 && args[0]->IsUint32()) { unsigned long localLength = args[0]->ToNumber()->Uint32Value(); localInstance = new uscxml::ArrayBuffer(localLength); } if (!localInstance) { throw V8Exception("Parameter mismatch while calling constructor for ArrayBuffer"); return v8::Undefined(); } v8::Handle retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); retPrivData->nativeObj = localInstance; retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); return retObj; } v8::Handle V8ArrayBuffer::byteLengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { v8::Local self = info.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); return v8::Integer::New(privData->nativeObj->getByteLength()); } v8::Handle V8ArrayBuffer::sliceCallback(const v8::Arguments& args) { v8::Local self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); if (false) { } else if (args.Length() == 2 && args[0]->IsInt32() && args[1]->IsInt32()) { long localBegin = args[0]->ToNumber()->Int32Value(); long localEnd = args[1]->ToNumber()->Int32Value(); uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); v8::Handle retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); return retObj; } else if (args.Length() == 1 && args[0]->IsInt32()) { long localBegin = args[0]->ToNumber()->Int32Value(); uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin)); v8::Handle retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); retPrivData->dom = privData->dom; retPrivData->nativeObj = retVal; retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); return retObj; } throw V8Exception("Parameter mismatch while calling slice"); return v8::Undefined(); } v8::Handle V8ArrayBuffer::isViewCallback(const v8::Arguments& args) { v8::Local self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); if (false) { } else if (args.Length() == 1 && true) { void* localValue = v8::External::Unwrap(args[0]->ToObject()->GetInternalField(0)); bool retVal = privData->nativeObj->isView(localValue); return v8::Boolean::New(retVal); } throw V8Exception("Parameter mismatch while calling isView"); return v8::Undefined(); } bool V8ArrayBuffer::hasInstance(v8::Handle value) { return getTmpl()->HasInstance(value); } } }