diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-08-30 10:33:43 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-08-30 10:33:43 (GMT) |
commit | 99d2c52f1068b2dd4bd16b8c1c8231beeb94a649 (patch) | |
tree | c00a8d95a7d0fce9c5325297325e413d65ce7d14 /src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp | |
parent | 442204d0f510cb033cb75a542b010f4f90cbd2a3 (diff) | |
download | uscxml-99d2c52f1068b2dd4bd16b8c1c8231beeb94a649.zip uscxml-99d2c52f1068b2dd4bd16b8c1c8231beeb94a649.tar.gz uscxml-99d2c52f1068b2dd4bd16b8c1c8231beeb94a649.tar.bz2 |
Started work on ECMAScript TypedArrays
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp new file mode 100644 index 0000000..509481e --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp @@ -0,0 +1,105 @@ +#include "JSCInt8Array.h" + +namespace Arabica { +namespace DOM { + +JSClassRef JSCInt8Array::Tmpl; + +JSStaticValue JSCInt8Array::staticValues[] = { + { "length", lengthAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + + { "BYTES_PER_ELEMENT", BYTES_PER_ELEMENTConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } +}; + +JSStaticFunction JSCInt8Array::staticFunctions[] = { + { "get", getCallback, kJSPropertyAttributeDontDelete }, + { "set", setCallback, kJSPropertyAttributeDontDelete }, + { "set", setCallback, kJSPropertyAttributeDontDelete }, + { "set", setCallback, kJSPropertyAttributeDontDelete }, + { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, + { 0, 0, 0 } +}; + +JSValueRef JSCInt8Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { + struct JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(object); + + return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); +} + +JSValueRef JSCInt8Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 1); +} + +JSValueRef JSCInt8Array::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 JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); + + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + + char retVal = privData->nativeObj->get(localIndex); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; +} + +JSValueRef JSCInt8Array::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 JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); + + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; +} + +JSValueRef JSCInt8Array::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 JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); + + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + + uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCInt8Array::getTmpl(); + + struct JSCInt8Array::JSCInt8ArrayPrivate* retPrivData = new JSCInt8Array::JSCInt8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + +} + + +} +} |