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/V8Uint8Array.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/V8Uint8Array.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp | 178 |
1 files changed, 152 insertions, 26 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp index cc13bf0..b2eafe5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Uint8Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Uint8Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Uint8Array::Constr; +v8::Handle<v8::Value> V8Uint8Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Uint8Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0])) { + + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + localInstance = new uscxml::Uint8Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Uint8Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Uint8Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Uint8Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Uint8Array::lengthAttrGetter(v8::Local<v8::String> prope return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Uint8Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->get(localIndex); + unsigned char retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned char localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + unsigned char localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0])) { + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Uint8Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Uint8Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Uint8Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } |