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/JavaScriptCore/dom/JSCFloat64Array.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/JavaScriptCore/dom/JSCFloat64Array.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp | 229 |
1 files changed, 183 insertions, 46 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp index 06ca510..2bf524c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCFloat64Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCFloat64Array::staticValues[] = { JSStaticFunction JSCFloat64Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCFloat64Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Float64Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl())) { + + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float64Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float64Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Float64Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Float64Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Float64Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCFloat64Array::getTmpl(); + + struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCFloat64Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCFloat64Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObj return JSValueMakeNumber(ctx, 8); } + JSValueRef JSCFloat64Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - double retVal = privData->nativeObj->get(localIndex); + double retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat64Array::setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 2) { - std::string errorMsg = "Wrong number of arguments in set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl())) { + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat64Array::subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 2) { - std::string errorMsg = "Wrong number of arguments in subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCFloat64Array::getTmpl(); + uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCFloat64Array::getTmpl(); - struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } |