diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 19:18:36 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 19:18:36 (GMT) |
commit | fd0778237785840ec754f98e847a524590cbf61c (patch) | |
tree | ebf4609be11843f9657810515d47faa3873c2db8 /src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp | |
parent | 99d2c52f1068b2dd4bd16b8c1c8231beeb94a649 (diff) | |
download | uscxml-fd0778237785840ec754f98e847a524590cbf61c.zip uscxml-fd0778237785840ec754f98e847a524590cbf61c.tar.gz uscxml-fd0778237785840ec754f98e847a524590cbf61c.tar.bz2 |
More work on TypedArrays
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp | 94 |
1 files changed, 75 insertions, 19 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp index d4146fe..ce51887 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp @@ -4,7 +4,37 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Constr; +v8::Handle<v8::Value> 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<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8ArrayBuffer::byteLengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,43 +42,69 @@ v8::Handle<v8::Value> V8ArrayBuffer::byteLengthAttrGetter(v8::Local<v8::String> return v8::Integer::New(privData->nativeObj->getByteLength()); } + v8::Handle<v8::Value> V8ArrayBuffer::sliceCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in slice"); v8::Local<v8::Object> self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0)); - long localBegin = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + 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<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); + v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); - return retObj; + 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<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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<v8::Value> V8ArrayBuffer::isViewCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in isView"); v8::Local<v8::Object> self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0)); - void* localValue = v8::External::Unwrap(args[0]->ToObject()->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); + bool retVal = privData->nativeObj->isView(localValue); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling isView"); + return v8::Undefined(); } - bool V8ArrayBuffer::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } |