summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-08-30 10:33:43 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-08-30 10:33:43 (GMT)
commit99d2c52f1068b2dd4bd16b8c1c8231beeb94a649 (patch)
treec00a8d95a7d0fce9c5325297325e413d65ce7d14 /src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
parent442204d0f510cb033cb75a542b010f4f90cbd2a3 (diff)
downloaduscxml-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/JSCInt32Array.cpp')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
new file mode 100644
index 0000000..09d8f76
--- /dev/null
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
@@ -0,0 +1,105 @@
+#include "JSCInt32Array.h"
+
+namespace Arabica {
+namespace DOM {
+
+JSClassRef JSCInt32Array::Tmpl;
+
+JSStaticValue JSCInt32Array::staticValues[] = {
+ { "length", lengthAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+
+ { "BYTES_PER_ELEMENT", BYTES_PER_ELEMENTConstGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+ { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSCInt32Array::staticFunctions[] = {
+ { "get", getCallback, kJSPropertyAttributeDontDelete },
+ { "set", setCallback, kJSPropertyAttributeDontDelete },
+ { "set", setCallback, kJSPropertyAttributeDontDelete },
+ { "set", setCallback, kJSPropertyAttributeDontDelete },
+ { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete },
+ { 0, 0, 0 }
+};
+
+JSValueRef JSCInt32Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
+ struct JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(object);
+
+ return JSValueMakeNumber(ctx, privData->nativeObj->getLength());
+}
+
+JSValueRef JSCInt32Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) {
+ return JSValueMakeNumber(ctx, 4);
+}
+
+JSValueRef JSCInt32Array::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 JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj);
+
+ unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception);
+
+ long retVal = privData->nativeObj->get(localIndex);
+
+ JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal);
+ return jscRetVal;
+}
+
+JSValueRef JSCInt32Array::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 JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj);
+
+ unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception);
+ long localValue = (long)JSValueToNumber(ctx, arguments[1], exception);
+
+ privData->nativeObj->set(localIndex, localValue);
+
+ JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
+ return jscRetVal;
+}
+
+JSValueRef JSCInt32Array::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 JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj);
+
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+ long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception);
+
+ uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart, localEnd));
+ JSClassRef retClass = JSCInt32Array::getTmpl();
+
+ struct JSCInt32Array::JSCInt32ArrayPrivate* retPrivData = new JSCInt32Array::JSCInt32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
+}
+
+
+}
+}