summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-09-02 12:38:13 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-09-02 12:38:13 (GMT)
commita874a181add7b292e52140f8c753f663a4cb5a87 (patch)
tree1b8958ba2abceef58901b3f90f1f05b44321deab /src/uscxml/plugins/datamodel/ecmascript
parent9caba3540b4d64a5277040f43bdaabde7ba227a0 (diff)
downloaduscxml-a874a181add7b292e52140f8c753f663a4cb5a87.zip
uscxml-a874a181add7b292e52140f8c753f663a4cb5a87.tar.gz
uscxml-a874a181add7b292e52140f8c753f663a4cb5a87.tar.bz2
Optional 2nd argument for TypedArray.subarray and more tests
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp15
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp44
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/TypedArray.h62
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp17
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp17
20 files changed, 358 insertions, 36 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp
index 8b2c8ef..32f7929 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCFloat32Array::subarrayCallback(JSContextRef ctx, JSObjectRef funct
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCFloat32Array::getTmpl();
+
+ struct JSCFloat32Array::JSCFloat32ArrayPrivate* retPrivData = new JSCFloat32Array::JSCFloat32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp
index 2bf524c..ee9743d 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCFloat64Array::subarrayCallback(JSContextRef ctx, JSObjectRef funct
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCFloat64Array::getTmpl();
+
+ struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp
index f0ca42a..2dbcce8 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCInt16Array::subarrayCallback(JSContextRef ctx, JSObjectRef functio
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCInt16Array::getTmpl();
+
+ struct JSCInt16Array::JSCInt16ArrayPrivate* retPrivData = new JSCInt16Array::JSCInt16ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
index b10fa96..3e10dfe 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCInt32Array::subarrayCallback(JSContextRef ctx, JSObjectRef functio
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart));
+ 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;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp
index 00c717c..0cb1cb8 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCInt8Array::subarrayCallback(JSContextRef ctx, JSObjectRef function
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart));
+ 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;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp
index 3ea7177..3c5a588 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCUint16Array::subarrayCallback(JSContextRef ctx, JSObjectRef functi
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCUint16Array::getTmpl();
+
+ struct JSCUint16Array::JSCUint16ArrayPrivate* retPrivData = new JSCUint16Array::JSCUint16ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp
index f259940..28dde30 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCUint32Array::subarrayCallback(JSContextRef ctx, JSObjectRef functi
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCUint32Array::getTmpl();
+
+ struct JSCUint32Array::JSCUint32ArrayPrivate* retPrivData = new JSCUint32Array::JSCUint32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp
index b828182..5698b40 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCUint8Array::subarrayCallback(JSContextRef ctx, JSObjectRef functio
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCUint8Array::getTmpl();
+
+ struct JSCUint8Array::JSCUint8ArrayPrivate* retPrivData = new JSCUint8Array::JSCUint8ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp
index df5de18..d0263ed 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp
@@ -230,6 +230,21 @@ JSValueRef JSCUint8ClampedArray::subarrayCallback(JSContextRef ctx, JSObjectRef
return retObj;
+ } else if (argumentCount == 1 &&
+ JSValueIsNumber(ctx, arguments[0])) {
+ long localStart = (long)JSValueToNumber(ctx, arguments[0], exception);
+
+ uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart));
+ JSClassRef retClass = JSCUint8ClampedArray::getTmpl();
+
+ struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate* retPrivData = new JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData);
+
+ return retObj;
+
}
JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray");
diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp
index e52dfd3..aa15353 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp
@@ -4,9 +4,13 @@
#define DATAVIEW_TYPED_GET(type) \
type retVal;\
+if (index + _start + sizeof(type) > _buffer->_size)\
+ return 0;\
memcpy(&retVal, _buffer->_data + (_start + index), sizeof(type));
#define DATAVIEW_TYPED_SET(type) \
+if (index + _start + sizeof(type) > _buffer->_size)\
+ return;\
memcpy(_buffer->_data + (_start + index), &value, sizeof(type));
namespace uscxml {
@@ -75,15 +79,21 @@ ArrayBuffer ArrayBufferView::getBuffer() {
return ArrayBuffer(_buffer);
}
-DataView::DataView(ArrayBuffer* buffer, unsigned long start, unsigned long length) {
- _start = start;
- _end = start + length;
+DataView::DataView(ArrayBuffer* buffer, unsigned long byteOffset, unsigned long byteLength) {
+ _start = byteOffset;
+ if (_start > buffer->_buffer->_size)
+ return;
+ _end = _start + byteLength;
+ if (_end > buffer->_buffer->_size)
+ return;
_buffer = buffer->_buffer;
}
-DataView::DataView(ArrayBuffer* buffer , unsigned long start) {
- _start = start;
+DataView::DataView(ArrayBuffer* buffer , unsigned long byteOffset) {
+ _start = byteOffset;
_end = buffer->_buffer->_size;
+ if (_start > buffer->_buffer->_size)
+ return;
_buffer = buffer->_buffer;
}
@@ -105,17 +115,17 @@ unsigned long DataView::getLength() {
return _end - _start;
}
-char DataView::getInt8(unsigned long index) {
+int8_t DataView::getInt8(unsigned long index) {
DATAVIEW_TYPED_GET(int8_t);
return retVal;
}
-unsigned char DataView::getUint8(unsigned long index) {
+uint8_t DataView::getUint8(unsigned long index) {
DATAVIEW_TYPED_GET(uint8_t);
return retVal;
}
-short DataView::getInt16(unsigned long index, bool littleEndian) {
+int16_t DataView::getInt16(unsigned long index, bool littleEndian) {
DATAVIEW_TYPED_GET(int16_t);
#ifdef BOOST_LITTLE_ENDIAN
if (littleEndian)
@@ -128,7 +138,7 @@ short DataView::getInt16(unsigned long index, bool littleEndian) {
#endif
}
-unsigned short DataView::getUint16(unsigned long index, bool littleEndian) {
+uint16_t DataView::getUint16(unsigned long index, bool littleEndian) {
DATAVIEW_TYPED_GET(uint16_t);
#ifdef BOOST_LITTLE_ENDIAN
if (littleEndian)
@@ -141,7 +151,7 @@ unsigned short DataView::getUint16(unsigned long index, bool littleEndian) {
#endif
}
-long DataView::getInt32(unsigned long index, bool littleEndian) {
+int32_t DataView::getInt32(unsigned long index, bool littleEndian) {
DATAVIEW_TYPED_GET(int32_t);
#ifdef BOOST_LITTLE_ENDIAN
if (littleEndian)
@@ -154,7 +164,7 @@ long DataView::getInt32(unsigned long index, bool littleEndian) {
#endif
}
-unsigned long DataView::getUint32(unsigned long index, bool littleEndian) {
+uint32_t DataView::getUint32(unsigned long index, bool littleEndian) {
DATAVIEW_TYPED_GET(uint32_t);
#ifdef BOOST_LITTLE_ENDIAN
if (littleEndian)
@@ -193,15 +203,15 @@ double DataView::getFloat64(unsigned long index, bool littleEndian) {
#endif
}
-void DataView::setInt8(long index, char value) {
+void DataView::setInt8(long index, int8_t value) {
DATAVIEW_TYPED_SET(int8_t);
}
-void DataView::setUint8(long index, unsigned char value) {
+void DataView::setUint8(long index, uint8_t value) {
DATAVIEW_TYPED_SET(uint8_t);
}
-void DataView::setInt16(long index, short value, bool littleEndian) {
+void DataView::setInt16(long index, int16_t value, bool littleEndian) {
#ifdef BOOST_LITTLE_ENDIAN
if (!littleEndian)
value = byte_swap<little_endian, big_endian>(value);
@@ -212,7 +222,7 @@ void DataView::setInt16(long index, short value, bool littleEndian) {
DATAVIEW_TYPED_SET(int16_t);
}
-void DataView::setUint16(long index, unsigned short value, bool littleEndian) {
+void DataView::setUint16(long index, uint16_t value, bool littleEndian) {
#ifdef BOOST_LITTLE_ENDIAN
if (!littleEndian)
value = byte_swap<little_endian, big_endian>(value);
@@ -223,7 +233,7 @@ void DataView::setUint16(long index, unsigned short value, bool littleEndian) {
DATAVIEW_TYPED_SET(uint16_t);
}
-void DataView::setInt32(long index, long value, bool littleEndian) {
+void DataView::setInt32(long index, int32_t value, bool littleEndian) {
#ifdef BOOST_LITTLE_ENDIAN
if (!littleEndian)
value = byte_swap<little_endian, big_endian>(value);
@@ -234,7 +244,7 @@ void DataView::setInt32(long index, long value, bool littleEndian) {
DATAVIEW_TYPED_SET(int32_t);
}
-void DataView::setUint32(long index, unsigned long value, bool littleEndian) {
+void DataView::setUint32(long index, uint32_t value, bool littleEndian) {
#ifdef BOOST_LITTLE_ENDIAN
if (!littleEndian)
value = byte_swap<little_endian, big_endian>(value);
diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h
index e238d15..37b38a7 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h
+++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h
@@ -113,6 +113,19 @@ protected:
class DataView : ArrayBufferView {
public:
+ /**
+ * Create a new DataView object using the passed ArrayBuffer for its storage.
+ * Optional byteOffset and byteLength can be used to limit the section of the
+ * buffer referenced. The byteOffset indicates the offset in bytes from the
+ * start of the ArrayBuffer, and the byteLength is the number of bytes from the
+ * offset that this DataView will reference. If both byteOffset and byteLength
+ * are omitted, the DataView spans the entire ArrayBuffer range. If the
+ * byteLength is omitted, the DataView extends from the given byteOffset until
+ * the end of the ArrayBuffer.
+ * If the given byteOffset and byteLength references an area beyond the end of
+ * the ArrayBuffer an exception is raised.
+ */
+
DataView(ArrayBuffer*, unsigned long, unsigned long);
DataView(ArrayBuffer*, unsigned long);
DataView(ArrayBuffer*);
@@ -132,12 +145,12 @@ public:
* beyond the end of the view.
*/
- char getInt8(unsigned long);
- unsigned char getUint8(unsigned long);
- short getInt16(unsigned long, bool = false);
- unsigned short getUint16(unsigned long, bool = false);
- long getInt32(unsigned long, bool = false);
- unsigned long getUint32(unsigned long, bool = false);
+ int8_t getInt8(unsigned long);
+ uint8_t getUint8(unsigned long);
+ int16_t getInt16(unsigned long, bool = false);
+ uint16_t getUint16(unsigned long, bool = false);
+ int32_t getInt32(unsigned long, bool = false);
+ uint32_t getUint32(unsigned long, bool = false);
float getFloat32(unsigned long, bool = false);
double getFloat64(unsigned long, bool = false);
@@ -153,12 +166,12 @@ public:
* beyond the end of the view.
*/
- void setInt8(long, char);
- void setUint8(long, unsigned char);
- void setInt16(long, short, bool = false);
- void setUint16(long, unsigned short, bool = false);
- void setInt32(long, long, bool = false);
- void setUint32(long, unsigned long, bool = false);
+ void setInt8(long, int8_t);
+ void setUint8(long, uint8_t);
+ void setInt16(long, int16_t, bool = false);
+ void setUint16(long, uint16_t, bool = false);
+ void setInt32(long, int32_t, bool = false);
+ void setUint32(long, uint32_t, bool = false);
void setFloat32(long, float, bool = false);
void setFloat64(long, double, bool = false);
@@ -291,11 +304,13 @@ public:
void set(TypedArray<T, S>* value, unsigned long offset) {
if (!_buffer)
return;
- if (offset * sizeof(S) + value->_buffer->_size > _buffer->_size)
+ if (offset * sizeof(S) + value->getByteLength() > _buffer->_size)
return;
+ unsigned long otherOffset = value->_start * sizeof(S);
+
// will this work if we use the same buffer?
- memcpy(_buffer->_data + (_start + offset) * sizeof(S), &value->_buffer->_data, value->_buffer->_size);
+ memcpy(_buffer->_data + (_start + offset) * sizeof(S), value->_buffer->_data + otherOffset, value->getByteLength());
}
void set(TypedArray<T, S>* value) {
@@ -321,7 +336,7 @@ public:
return;
if (sizeof(T) == sizeof(S)) {
- memcpy(_buffer->_data + offset, (void*)&data[0], data.size());
+ memcpy(_buffer->_data + offset, (void*)&data[0], data.size() * sizeof(S));
} else {
S* buffer = (S*)malloc(data.size() * sizeof(S));
typename std::vector<T>::const_iterator dataIter = data.begin();
@@ -331,7 +346,7 @@ public:
dataIter++;
i++;
}
- memcpy(_buffer->_data + offset, buffer, data.size());
+ memcpy(_buffer->_data + offset, buffer, data.size() * sizeof(S));
free (buffer);
}
}
@@ -356,13 +371,22 @@ public:
TypedArray* subarray(long begin, long end) {
if (!_buffer)
return NULL;
- unsigned int realBegin = (begin + _buffer->_size) % _buffer->_size;
- unsigned int realEnd = (end + _buffer->_size) % _buffer->_size;
+ unsigned int length = getLength();
+ unsigned int realBegin = (begin + length) % length;
+ unsigned int realEnd = (end + length) % length;
+ if (realEnd == 0)
+ realEnd = length;
if (realEnd < realBegin)
return NULL;
- return new TypedArray<T, S>(_buffer, realBegin, realEnd);
+ return new TypedArray<T, S>(_buffer, realBegin * sizeof(S), realEnd - realBegin);
+ }
+
+ TypedArray* subarray(long begin) {
+ if (!_buffer)
+ return NULL;
+ return subarray(begin, getLength());
}
unsigned long getLength() {
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp
index 1fe74e6..2e314b4 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Float32Array::subarrayCallback(const v8::Arguments& args
retObj.MakeWeak(0, V8Float32Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Float32Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Float32Array::V8Float32ArrayPrivate* retPrivData = new V8Float32Array::V8Float32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Float32Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp
index 92d468d..a08fdc9 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Float64Array::subarrayCallback(const v8::Arguments& args
retObj.MakeWeak(0, V8Float64Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Float64Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Float64Array::V8Float64ArrayPrivate* retPrivData = new V8Float64Array::V8Float64ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Float64Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp
index d8f63f2..44eebb7 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Int16Array::subarrayCallback(const v8::Arguments& args)
retObj.MakeWeak(0, V8Int16Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Int16Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Int16Array::V8Int16ArrayPrivate* retPrivData = new V8Int16Array::V8Int16ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Int16Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp
index 5c2d130..7eeaef0 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Int32Array::subarrayCallback(const v8::Arguments& args)
retObj.MakeWeak(0, V8Int32Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Int32Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Int32Array::V8Int32ArrayPrivate* retPrivData = new V8Int32Array::V8Int32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Int32Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp
index d78be76..f9b5fdb 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Int8Array::subarrayCallback(const v8::Arguments& args) {
retObj.MakeWeak(0, V8Int8Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Int8Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Int8Array::V8Int8ArrayPrivate* retPrivData = new V8Int8Array::V8Int8ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Int8Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp
index 4c84081..f39c4ac 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Uint16Array::subarrayCallback(const v8::Arguments& args)
retObj.MakeWeak(0, V8Uint16Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Uint16Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Uint16Array::V8Uint16ArrayPrivate* retPrivData = new V8Uint16Array::V8Uint16ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Uint16Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp
index da3fdc2..4054d5e 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Uint32Array::subarrayCallback(const v8::Arguments& args)
retObj.MakeWeak(0, V8Uint32Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Uint32Array::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Uint32Array::V8Uint32ArrayPrivate* retPrivData = new V8Uint32Array::V8Uint32ArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Uint32Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp
index b2eafe5..9d387b6 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Uint8Array::subarrayCallback(const v8::Arguments& args)
retObj.MakeWeak(0, V8Uint8Array::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart));
+ 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;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Uint8Array::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp
index 206b755..be470fa 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp
@@ -185,6 +185,23 @@ v8::Handle<v8::Value> V8Uint8ClampedArray::subarrayCallback(const v8::Arguments&
retObj.MakeWeak(0, V8Uint8ClampedArray::jsDestructor);
return retObj;
+ } else if (args.Length() == 1 &&
+ args[0]->IsInt32()) {
+ long localStart = args[0]->ToNumber()->Int32Value();
+
+ uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart));
+ v8::Handle<v8::Function> retCtor = V8Uint8ClampedArray::getTmpl()->GetFunction();
+ v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance());
+
+ struct V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate* retPrivData = new V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate();
+ retPrivData->dom = privData->dom;
+ retPrivData->nativeObj = retVal;
+
+ retObj->SetInternalField(0, V8DOM::toExternal(retPrivData));
+
+ retObj.MakeWeak(0, V8Uint8ClampedArray::jsDestructor);
+ return retObj;
+
}
throw V8Exception("Parameter mismatch while calling subarray");
return v8::Undefined();