Bug 1674777 part 4 - Change some JSAPI byteLength and byteOffset accessors to return size_t instead of uint32_t. r=sfink

Of these four, only JS_GetTypedArrayByteLength is used outside jsapi-tests.

Differential Revision: https://phabricator.services.mozilla.com/D103277
This commit is contained in:
Jan de Mooij 2021-01-28 16:11:52 +00:00
Родитель 41621582c6
Коммит 72b0edc3ed
5 изменённых файлов: 47 добавлений и 18 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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<void*> target = SharedMem<void*>::unshared(buffer);
JS::AutoCheckCannotGC nogc;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<ArrayBufferViewObject>();
if (!obj) {
return 0;
@ -245,10 +245,10 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj) {
BufferSize length = obj->is<DataViewObject>()
? obj->as<DataViewObject>().byteLength()
: obj->as<TypedArrayObject>().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<ArrayBufferViewObject>();
if (!obj) {
return 0;
@ -256,7 +256,7 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteOffset(JSObject* obj) {
BufferSize offset = obj->is<DataViewObject>()
? obj->as<DataViewObject>().byteOffset()
: obj->as<TypedArrayObject>().byteOffset();
return offset.deprecatedGetUint32();
return offset.get();
}
JS_FRIEND_API JSObject* JS_GetObjectAsArrayBufferView(JSObject* obj,

Просмотреть файл

@ -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<TypedArrayObject>();
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<TypedArrayObject>();
if (!tarr) {
return 0;
}
return tarr->byteLength().deprecatedGetUint32();
return tarr->byteLength().get();
}
JS_FRIEND_API bool JS_GetTypedArraySharedness(JSObject* obj) {