diff options
23 files changed, 529 insertions, 45 deletions
@@ -7,6 +7,8 @@ There are still a few rough edges though, especially with the plugins and custom * <b>Datamodels</b> * Full [ECMAScript datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/ecmascript) using Google's v8 (and JavaScriptCore on MacOSX and iOS) + * Simplified support for [Web Storage](http://www.w3.org/TR/2013/REC-webstorage-20130730/) in document.localStorage + * Support for binary data via [TypedArrays](https://www.khronos.org/registry/typedarray/specs/latest/) (will not throw exceptions yet) * Full [NULL datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/null) with required <tt>In</tt> predicate * Early [Prolog datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/prolog/swi) using SWI prolog * Rudimentary support for [XPath datamodel](https://github.com/tklab-tud/uscxml/tree/master/src/uscxml/plugins/datamodel/xpath) diff --git a/contrib/dom/idl/TypedArray.idl b/contrib/dom/idl/TypedArray.idl index 341003b..cf65df6 100644 --- a/contrib/dom/idl/TypedArray.idl +++ b/contrib/dom/idl/TypedArray.idl @@ -45,7 +45,7 @@ interface Int8Array : ArrayBufferView { setter void set(unsigned long index, byte value); void set(Int8Array array, optional unsigned long offset); void set(byte[] array, optional unsigned long offset); - Int8Array subarray(long start, long end); + Int8Array subarray(long start, optional long end); }; Int8Array implements ArrayBufferView; @@ -70,7 +70,7 @@ interface Uint8Array : ArrayBufferView{ setter void set(unsigned long index, octet value); void set(Uint8Array array, optional unsigned long offset); void set(octet[] array, optional unsigned long offset); - Uint8Array subarray(long start, long end); + Uint8Array subarray(long start, optional long end); }; Uint8Array implements ArrayBufferView; @@ -93,7 +93,7 @@ interface Uint8ClampedArray : ArrayBufferView { setter void set(unsigned long index, [Clamp] octet value); void set(Uint8ClampedArray array, optional unsigned long offset); void set(octet[] array, optional unsigned long offset); - Uint8ClampedArray subarray(long start, long end); + Uint8ClampedArray subarray(long start, optional long end); }; Uint8ClampedArray implements ArrayBufferView; @@ -116,7 +116,7 @@ interface Int16Array : ArrayBufferView { setter void set(unsigned long index, short value); void set(Int16Array array, optional unsigned long offset); void set(short[] array, optional unsigned long offset); - Int16Array subarray(long start, long end); + Int16Array subarray(long start, optional long end); }; Int16Array implements ArrayBufferView; @@ -139,7 +139,7 @@ interface Uint16Array : ArrayBufferView { setter void set(unsigned long index, unsigned short value); void set(Uint16Array array, optional unsigned long offset); void set(unsigned short[] array, optional unsigned long offset); - Uint16Array subarray(long start, long end); + Uint16Array subarray(long start, optional long end); }; Uint16Array implements ArrayBufferView; @@ -162,7 +162,7 @@ interface Int32Array : ArrayBufferView { setter void set(unsigned long index, long value); void set(Int32Array array, optional unsigned long offset); void set(long[] array, optional unsigned long offset); - Int32Array subarray(long start, long end); + Int32Array subarray(long start, optional long end); }; Int32Array implements ArrayBufferView; @@ -185,7 +185,7 @@ interface Uint32Array : ArrayBufferView { setter void set(unsigned long index, unsigned long value); void set(Uint32Array array, optional unsigned long offset); void set(unsigned long[] array, optional unsigned long offset); - Uint32Array subarray(long start, long end); + Uint32Array subarray(long start, optional long end); }; Uint32Array implements ArrayBufferView; @@ -208,7 +208,7 @@ interface Float32Array : ArrayBufferView { setter void set(unsigned long index, float value); void set(Float32Array array, optional unsigned long offset); void set(float[] array, optional unsigned long offset); - Float32Array subarray(long start, long end); + Float32Array subarray(long start, optional long end); }; Float32Array implements ArrayBufferView; @@ -231,7 +231,7 @@ interface Float64Array : ArrayBufferView { setter void set(unsigned long index, double value); void set(Float64Array array, optional unsigned long offset); void set(double[] array, optional unsigned long offset); - Float64Array subarray(long start, long end); + Float64Array subarray(long start, optional long end); }; Float64Array implements ArrayBufferView; 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(); diff --git a/test/src/test-datamodel.cpp b/test/src/test-datamodel.cpp index 98ee9c3..452d2b9 100644 --- a/test/src/test-datamodel.cpp +++ b/test/src/test-datamodel.cpp @@ -249,6 +249,166 @@ int main(int argc, char** argv) { } + // TypedArray setting + { + dm.evalAsBool("var a = new Int32Array([1, 2, 3, 4, 5]);"); + dm.evalAsBool("var b = new Int32Array(5);"); + dm.evalAsBool("b.set(a);"); + assert(dm.evalAsBool("checkArray(b, [1, 2, 3, 4, 5]);")); + + dm.evalAsBool("b.set(new Int32Array([99, 98]), 2);"); + assert(dm.evalAsBool("checkArray(b, [1, 2, 99, 98, 5]);")); + + dm.evalAsBool("b.set(new Int32Array([99, 98, 97]), 2);"); + assert(dm.evalAsBool("checkArray(b, [1, 2, 99, 98, 97]);")); + + // ab = [ 0, 1, 2, 3, 4, 5, 6, 7 ] + // a1 = [ ^, ^, ^, ^, ^, ^, ^, ^ ] + // a2 = [ ^, ^, ^, ^ ] + dm.evalAsBool("var ab = new ArrayBuffer(8);"); + dm.evalAsBool("var a1 = new Uint8Array(ab);"); + dm.evalAsBool("for (var i = 0; i < a1.length; i += 1) { a1.set(i, i); }"); + dm.evalAsBool("var a2 = new Uint8Array(ab, 4);"); + dm.evalAsBool("a1.set(a2, 2);"); + assert(dm.evalAsBool("checkArray(a1, [0, 1, 4, 5, 6, 7, 6, 7]);")); + assert(dm.evalAsBool("checkArray(a2, [6, 7, 6, 7]);")); + + } + + // TypedArray.subarray + { + dm.evalAsBool("var a = new Int32Array([1, 2, 3, 4, 5]);"); + assert(dm.evalAsBool("checkArray(a.subarray(3), [4, 5]);")); + assert(dm.evalAsBool("checkArray(a.subarray(1, 3), [2, 3]);")); + assert(dm.evalAsBool("checkArray(a.subarray(-3), [3, 4, 5]);")); + assert(dm.evalAsBool("checkArray(a.subarray(-3, -1), [3, 4]);")); +// assert(dm.evalAsBool("checkArray(a.subarray(3, 2), []);")); +// assert(dm.evalAsBool("checkArray(a.subarray(-2, -3), []);")); +// assert(dm.evalAsBool("checkArray(a.subarray(4, 1), []);")); +// assert(dm.evalAsBool("checkArray(a.subarray(-1, -4), []);")); + + } + + // DataView constructors + { + dm.evalAsBool("var d = new DataView(new ArrayBuffer(8));"); + + dm.evalAsBool("d.setUint32(0, 0x12345678);"); + assert(dm.evalAsBool("d.getUint32(0), 0x12345678;")); + + dm.evalAsBool("d.setUint32(0, 0x12345678, true);"); + assert(dm.evalAsBool("d.getUint32(0, true), 0x12345678;")); + + dm.evalAsBool("d.setUint32(0, 0x12345678, true);"); + assert(dm.evalAsBool("d.getUint32(0), 0x78563412;")); + + dm.evalAsBool("d.setUint32(0, 0x12345678);"); + assert(dm.evalAsBool("d.getUint32(0, true), 0x78563412;")); + +// assertThrows('no arguments', TypeError, function() { return new DataView(); }); +// assertThrows('non-ArrayBuffer argument', TypeError, function() { return new DataView([]); }); +// assertThrows('non-ArrayBuffer argument', TypeError, function() { return new DataView("bogus"); }); + + } + + // DataView accessors + { + dm.evalAsBool("var u = new Uint8Array(8), d = new DataView(u.buffer);"); + assert(dm.evalAsBool("checkArray(u, [0, 0, 0, 0, 0, 0, 0, 0]);")); + + dm.evalAsBool("d.setUint8(0, 255);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0, 0, 0, 0, 0, 0, 0]);")); + + dm.evalAsBool("d.setInt8(1, -1);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0xff, 0, 0, 0, 0, 0, 0]);")); + + dm.evalAsBool("d.setUint16(2, 0x1234);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0xff, 0x12, 0x34, 0, 0, 0, 0]);")); + + dm.evalAsBool("d.setInt16(4, -1);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0xff, 0x12, 0x34, 0xff, 0xff, 0, 0]);")); + + dm.evalAsBool("d.setUint32(1, 0x12345678);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0x12, 0x34, 0x56, 0x78, 0xff, 0, 0]);")); + + dm.evalAsBool("d.setInt32(4, -2023406815);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0x12, 0x34, 0x56, 0x87, 0x65, 0x43, 0x21]);")); + + dm.evalAsBool("d.setFloat32(2, 1.2E+38);"); + assert(dm.evalAsBool("checkArray(u, [0xff, 0x12, 0x7e, 0xb4, 0x8e, 0x52, 0x43, 0x21]);")); + + dm.evalAsBool("d.setFloat64(0, -1.2345678E+301);"); + assert(dm.evalAsBool("checkArray(u, [0xfe, 0x72, 0x6f, 0x51, 0x5f, 0x61, 0x77, 0xe5]);")); + + dm.evalAsBool("u.set([0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87]);"); + assert(dm.evalAsBool("d.getUint8(0) == 128;")); + assert(dm.evalAsBool("d.getInt8(1) == -127;")); + assert(dm.evalAsBool("d.getUint16(2) == 33411;")); + assert(dm.evalAsBool("d.getInt16(3) == -31868;")); + assert(dm.evalAsBool("d.getUint32(4) == 2223343239;")); + assert(dm.evalAsBool("d.getInt32(2) == -2105310075;")); + assert(dm.evalAsBool("d.getFloat32(2) == -1.932478247535851e-37;")); + assert(dm.evalAsBool("d.getFloat64(0) == -3.116851295377095e-306;")); + + } + + // DataView endian + { + dm.evalAsBool("var rawbuf = (new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7])).buffer;"); + dm.evalAsBool("var d;"); + + dm.evalAsBool("d = new DataView(rawbuf);"); + assert(dm.evalAsBool("d.byteLength == 8;")); + assert(dm.evalAsBool("d.byteOffset == 0;")); +// assertThrows('bounds for buffer', DOMException, d.getUint8.bind(d), -2); // Chrome bug for index -1? +// assertThrows('bounds for buffer', DOMException, d.getUint8.bind(d), 8); +// assertThrows('bounds for buffer', DOMException, d.setUint8.bind(d), -2, 0); +// assertThrows('bounds for buffer', DOMException, d.setUint8.bind(d), 8, 0); + + dm.evalAsBool("d = new DataView(rawbuf, 2);"); + assert(dm.evalAsBool("d.byteLength == 6;")); + assert(dm.evalAsBool("d.byteOffset == 2;")); + assert(dm.evalAsBool("d.getUint8(5) == 7;")); +// assertThrows('bounds for buffer, byteOffset', DOMException, d.getUint8.bind(d), -2); +// assertThrows('bounds for buffer, byteOffset', DOMException, d.getUint8.bind(d), 6); +// assertThrows('bounds for buffer, byteOffset', DOMException, d.setUint8.bind(d), -2, 0); +// assertThrows('bounds for buffer, byteOffset', DOMException, d.setUint8.bind(d), 6, 0); + + dm.evalAsBool("d = new DataView(rawbuf, 8);"); + assert(dm.evalAsBool("d.byteLength == 0;")); + +// assertThrows('invalid byteOffset', DOMException, function() { return new DataView(rawbuf, -1); }); +// assertThrows('invalid byteOffset', DOMException, function() { return new DataView(rawbuf, 9); }); +// assertThrows('invalid byteOffset', DOMException, function() { return new DataView(rawbuf, -1); }); + + dm.evalAsBool("d = new DataView(rawbuf, 2, 4);"); + assert(dm.evalAsBool("d.byteLength == 4;")); + assert(dm.evalAsBool("d.byteOffset == 2;")); + assert(dm.evalAsBool("d.getUint8(3) == 5;")); +// assertThrows('bounds for buffer, byteOffset, length', DOMException, function() { return d.getUint8(-2); }); +// assertThrows('bounds for buffer, byteOffset, length', DOMException, d.getUint8.bind(d), 4); +// assertThrows('bounds for buffer, byteOffset, length', DOMException, d.setUint8.bind(d), -2, 0); +// assertThrows('bounds for buffer, byteOffset, length', DOMException, d.setUint8.bind(d), 4, 0); + +// assertThrows('invalid byteOffset+length', DOMException, function() { return new DataView(rawbuf, 0, 9); }); +// assertThrows('invalid byteOffset+length', DOMException, function() { return new DataView(rawbuf, 8, 1); }); +// assertThrows('invalid byteOffset+length', DOMException, function() { return new DataView(rawbuf, 9, -1); }); + + } + + // Typed Array getters/setters + { + + dm.evalAsBool("var bytes = new Uint8Array([1, 2, 3, 4]);"); + dm.evalAsBool("var uint32s = new Uint32Array(bytes.buffer);"); + + assert(dm.evalAsBool("bytes[1] == 2;")); + dm.evalAsBool("uint32s[0] = 0xffffffff;"); + assert(dm.evalAsBool("bytes[1] == 0xff;")); + + } + + // string replacement { std::string content = "$"; int rplc = dm.replaceExpressions(content); |