diff --git a/js/public/experimental/TypedData.h b/js/public/experimental/TypedData.h index 963e9f433dcd..cdc57c40be01 100644 --- a/js/public/experimental/TypedData.h +++ b/js/public/experimental/TypedData.h @@ -309,7 +309,7 @@ extern JS_FRIEND_API uint32_t JS_GetTypedArrayLength(JSObject* obj); * be known that it would pass such a test: it is a typed array or a wrapper of * a typed array, and the unwrapping will succeed. */ -extern JS_FRIEND_API uint32_t JS_GetTypedArrayByteOffset(JSObject* obj); +extern JS_FRIEND_API size_t JS_GetTypedArrayByteOffset(JSObject* obj); /** * Return the byte length of a typed array. @@ -318,17 +318,17 @@ extern JS_FRIEND_API uint32_t JS_GetTypedArrayByteOffset(JSObject* obj); * be known that it would pass such a test: it is a typed array or a wrapper of * a typed array, and the unwrapping will succeed. */ -extern JS_FRIEND_API uint32_t JS_GetTypedArrayByteLength(JSObject* obj); +extern JS_FRIEND_API size_t JS_GetTypedArrayByteLength(JSObject* obj); /** * More generic name for JS_GetTypedArrayByteLength to cover DataViews as well */ -extern JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj); +extern JS_FRIEND_API size_t JS_GetArrayBufferViewByteLength(JSObject* obj); /** * More generic name for JS_GetTypedArrayByteOffset to cover DataViews as well */ -extern JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteOffset(JSObject* obj); +extern JS_FRIEND_API size_t JS_GetArrayBufferViewByteOffset(JSObject* obj); /* * Return a pointer to the start of the data referenced by a typed array. The diff --git a/js/src/ctypes/CTypes.cpp b/js/src/ctypes/CTypes.cpp index d0822b03d06a..84c5128f576a 100644 --- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -1259,8 +1259,8 @@ static bool ArgumentLengthError(JSContext* cx, const char* fun, return false; } -static bool ArrayLengthMismatch(JSContext* cx, unsigned expectedLength, - HandleObject arrObj, unsigned actualLength, +static bool ArrayLengthMismatch(JSContext* cx, size_t expectedLength, + HandleObject arrObj, size_t actualLength, HandleValue actual, ConversionType convType) { MOZ_ASSERT(arrObj && CType::IsCType(arrObj)); @@ -3673,13 +3673,13 @@ static bool ImplicitConvert(JSContext* cx, HandleValue val, arrObj, arrIndex); } - uint32_t sourceLength = JS_GetTypedArrayByteLength(valObj); + size_t sourceLength = JS_GetTypedArrayByteLength(valObj); size_t elementSize = CType::GetSize(baseType); size_t arraySize = elementSize * targetLength; - if (arraySize != size_t(sourceLength)) { + if (arraySize != sourceLength) { MOZ_ASSERT(!funObj); - return ArrayLengthMismatch(cx, arraySize, targetType, - size_t(sourceLength), val, convType); + return ArrayLengthMismatch(cx, arraySize, targetType, sourceLength, + val, convType); } SharedMem target = SharedMem::unshared(buffer); JS::AutoCheckCannotGC nogc; diff --git a/js/src/jsapi-tests/testLargeArrayBuffers.cpp b/js/src/jsapi-tests/testLargeArrayBuffers.cpp index d464a057faef..894a27820d28 100644 --- a/js/src/jsapi-tests/testLargeArrayBuffers.cpp +++ b/js/src/jsapi-tests/testLargeArrayBuffers.cpp @@ -40,6 +40,10 @@ BEGIN_TEST(testLargeArrayBuffers) { { RootedObject tarr(cx, JS_NewUint8Array(cx, nbytes)); CHECK(JS_IsTypedArrayObject(tarr)); + CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), 0u); + CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), nbytes); + CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), 0u); + CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), nbytes); length = 0; js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data); @@ -55,6 +59,10 @@ BEGIN_TEST(testLargeArrayBuffers) { RootedObject tarr(cx, JS_NewInt16ArrayWithBuffer(cx, buffer, 0, nbytes / 2)); CHECK(JS_IsTypedArrayObject(tarr)); + CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), 0u); + CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), nbytes); + CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), 0u); + CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), nbytes); length = 0; js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data); @@ -70,11 +78,32 @@ BEGIN_TEST(testLargeArrayBuffers) { { RootedObject dv(cx, JS_NewDataView(cx, buffer, 0, nbytes - 10)); CHECK(JS_IsArrayBufferViewObject(dv)); + CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(dv), 0u); + CHECK_EQUAL(JS_GetArrayBufferViewByteLength(dv), nbytes - 10); length = 0; js::GetArrayBufferViewLengthAndData(dv, &length, &isShared, &data); CHECK_EQUAL(length, nbytes - 10); } + + // Int8Array with large byteOffset. + { + RootedObject tarr(cx, + JS_NewInt8ArrayWithBuffer(cx, buffer, nbytes - 200, 32)); + CHECK(JS_IsTypedArrayObject(tarr)); + CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(tarr), nbytes - 200); + CHECK_EQUAL(JS_GetArrayBufferViewByteLength(tarr), 32u); + CHECK_EQUAL(JS_GetTypedArrayByteOffset(tarr), nbytes - 200); + CHECK_EQUAL(JS_GetTypedArrayByteLength(tarr), 32u); + } + + // DataView with large byteOffset. + { + RootedObject dv(cx, JS_NewDataView(cx, buffer, nbytes - 200, 32)); + CHECK(JS_IsArrayBufferViewObject(dv)); + CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(dv), nbytes - 200); + CHECK_EQUAL(JS_GetArrayBufferViewByteLength(dv), 32u); + } #endif return true; diff --git a/js/src/vm/ArrayBufferViewObject.cpp b/js/src/vm/ArrayBufferViewObject.cpp index 00dbab4ed965..2ecf0863955a 100644 --- a/js/src/vm/ArrayBufferViewObject.cpp +++ b/js/src/vm/ArrayBufferViewObject.cpp @@ -237,7 +237,7 @@ JS_FRIEND_API JSObject* JS_GetArrayBufferViewBuffer(JSContext* cx, return buffer; } -JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj) { +JS_FRIEND_API size_t JS_GetArrayBufferViewByteLength(JSObject* obj) { obj = obj->maybeUnwrapAs(); if (!obj) { return 0; @@ -245,10 +245,10 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj) { BufferSize length = obj->is() ? obj->as().byteLength() : obj->as().byteLength(); - return length.deprecatedGetUint32(); + return length.get(); } -JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteOffset(JSObject* obj) { +JS_FRIEND_API size_t JS_GetArrayBufferViewByteOffset(JSObject* obj) { obj = obj->maybeUnwrapAs(); if (!obj) { return 0; @@ -256,7 +256,7 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteOffset(JSObject* obj) { BufferSize offset = obj->is() ? obj->as().byteOffset() : obj->as().byteOffset(); - return offset.deprecatedGetUint32(); + return offset.get(); } JS_FRIEND_API JSObject* JS_GetObjectAsArrayBufferView(JSObject* obj, diff --git a/js/src/vm/TypedArrayObject.cpp b/js/src/vm/TypedArrayObject.cpp index 7ceb5f0f29e4..98db334ac762 100644 --- a/js/src/vm/TypedArrayObject.cpp +++ b/js/src/vm/TypedArrayObject.cpp @@ -2714,20 +2714,20 @@ JS_FRIEND_API uint32_t JS_GetTypedArrayLength(JSObject* obj) { return tarr->length().deprecatedGetUint32(); } -JS_FRIEND_API uint32_t JS_GetTypedArrayByteOffset(JSObject* obj) { +JS_FRIEND_API size_t JS_GetTypedArrayByteOffset(JSObject* obj) { TypedArrayObject* tarr = obj->maybeUnwrapAs(); if (!tarr) { return 0; } - return tarr->byteOffset().deprecatedGetUint32(); + return tarr->byteOffset().get(); } -JS_FRIEND_API uint32_t JS_GetTypedArrayByteLength(JSObject* obj) { +JS_FRIEND_API size_t JS_GetTypedArrayByteLength(JSObject* obj) { TypedArrayObject* tarr = obj->maybeUnwrapAs(); if (!tarr) { return 0; } - return tarr->byteLength().deprecatedGetUint32(); + return tarr->byteLength().get(); } JS_FRIEND_API bool JS_GetTypedArraySharedness(JSObject* obj) {