зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
41621582c6
Коммит
72b0edc3ed
|
@ -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
|
* 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.
|
* 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.
|
* 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
|
* 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.
|
* 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
|
* 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
|
* 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
|
* 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ArrayLengthMismatch(JSContext* cx, unsigned expectedLength,
|
static bool ArrayLengthMismatch(JSContext* cx, size_t expectedLength,
|
||||||
HandleObject arrObj, unsigned actualLength,
|
HandleObject arrObj, size_t actualLength,
|
||||||
HandleValue actual, ConversionType convType) {
|
HandleValue actual, ConversionType convType) {
|
||||||
MOZ_ASSERT(arrObj && CType::IsCType(arrObj));
|
MOZ_ASSERT(arrObj && CType::IsCType(arrObj));
|
||||||
|
|
||||||
|
@ -3673,13 +3673,13 @@ static bool ImplicitConvert(JSContext* cx, HandleValue val,
|
||||||
arrObj, arrIndex);
|
arrObj, arrIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sourceLength = JS_GetTypedArrayByteLength(valObj);
|
size_t sourceLength = JS_GetTypedArrayByteLength(valObj);
|
||||||
size_t elementSize = CType::GetSize(baseType);
|
size_t elementSize = CType::GetSize(baseType);
|
||||||
size_t arraySize = elementSize * targetLength;
|
size_t arraySize = elementSize * targetLength;
|
||||||
if (arraySize != size_t(sourceLength)) {
|
if (arraySize != sourceLength) {
|
||||||
MOZ_ASSERT(!funObj);
|
MOZ_ASSERT(!funObj);
|
||||||
return ArrayLengthMismatch(cx, arraySize, targetType,
|
return ArrayLengthMismatch(cx, arraySize, targetType, sourceLength,
|
||||||
size_t(sourceLength), val, convType);
|
val, convType);
|
||||||
}
|
}
|
||||||
SharedMem<void*> target = SharedMem<void*>::unshared(buffer);
|
SharedMem<void*> target = SharedMem<void*>::unshared(buffer);
|
||||||
JS::AutoCheckCannotGC nogc;
|
JS::AutoCheckCannotGC nogc;
|
||||||
|
|
|
@ -40,6 +40,10 @@ BEGIN_TEST(testLargeArrayBuffers) {
|
||||||
{
|
{
|
||||||
RootedObject tarr(cx, JS_NewUint8Array(cx, nbytes));
|
RootedObject tarr(cx, JS_NewUint8Array(cx, nbytes));
|
||||||
CHECK(JS_IsTypedArrayObject(tarr));
|
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;
|
length = 0;
|
||||||
js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
|
js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
|
||||||
|
@ -55,6 +59,10 @@ BEGIN_TEST(testLargeArrayBuffers) {
|
||||||
RootedObject tarr(cx,
|
RootedObject tarr(cx,
|
||||||
JS_NewInt16ArrayWithBuffer(cx, buffer, 0, nbytes / 2));
|
JS_NewInt16ArrayWithBuffer(cx, buffer, 0, nbytes / 2));
|
||||||
CHECK(JS_IsTypedArrayObject(tarr));
|
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;
|
length = 0;
|
||||||
js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
|
js::GetArrayBufferViewLengthAndData(tarr, &length, &isShared, &data);
|
||||||
|
@ -70,11 +78,32 @@ BEGIN_TEST(testLargeArrayBuffers) {
|
||||||
{
|
{
|
||||||
RootedObject dv(cx, JS_NewDataView(cx, buffer, 0, nbytes - 10));
|
RootedObject dv(cx, JS_NewDataView(cx, buffer, 0, nbytes - 10));
|
||||||
CHECK(JS_IsArrayBufferViewObject(dv));
|
CHECK(JS_IsArrayBufferViewObject(dv));
|
||||||
|
CHECK_EQUAL(JS_GetArrayBufferViewByteOffset(dv), 0u);
|
||||||
|
CHECK_EQUAL(JS_GetArrayBufferViewByteLength(dv), nbytes - 10);
|
||||||
|
|
||||||
length = 0;
|
length = 0;
|
||||||
js::GetArrayBufferViewLengthAndData(dv, &length, &isShared, &data);
|
js::GetArrayBufferViewLengthAndData(dv, &length, &isShared, &data);
|
||||||
CHECK_EQUAL(length, nbytes - 10);
|
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
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -237,7 +237,7 @@ JS_FRIEND_API JSObject* JS_GetArrayBufferViewBuffer(JSContext* cx,
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj) {
|
JS_FRIEND_API size_t JS_GetArrayBufferViewByteLength(JSObject* obj) {
|
||||||
obj = obj->maybeUnwrapAs<ArrayBufferViewObject>();
|
obj = obj->maybeUnwrapAs<ArrayBufferViewObject>();
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -245,10 +245,10 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteLength(JSObject* obj) {
|
||||||
BufferSize length = obj->is<DataViewObject>()
|
BufferSize length = obj->is<DataViewObject>()
|
||||||
? obj->as<DataViewObject>().byteLength()
|
? obj->as<DataViewObject>().byteLength()
|
||||||
: obj->as<TypedArrayObject>().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>();
|
obj = obj->maybeUnwrapAs<ArrayBufferViewObject>();
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -256,7 +256,7 @@ JS_FRIEND_API uint32_t JS_GetArrayBufferViewByteOffset(JSObject* obj) {
|
||||||
BufferSize offset = obj->is<DataViewObject>()
|
BufferSize offset = obj->is<DataViewObject>()
|
||||||
? obj->as<DataViewObject>().byteOffset()
|
? obj->as<DataViewObject>().byteOffset()
|
||||||
: obj->as<TypedArrayObject>().byteOffset();
|
: obj->as<TypedArrayObject>().byteOffset();
|
||||||
return offset.deprecatedGetUint32();
|
return offset.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API JSObject* JS_GetObjectAsArrayBufferView(JSObject* obj,
|
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();
|
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>();
|
TypedArrayObject* tarr = obj->maybeUnwrapAs<TypedArrayObject>();
|
||||||
if (!tarr) {
|
if (!tarr) {
|
||||||
return 0;
|
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>();
|
TypedArrayObject* tarr = obj->maybeUnwrapAs<TypedArrayObject>();
|
||||||
if (!tarr) {
|
if (!tarr) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return tarr->byteLength().deprecatedGetUint32();
|
return tarr->byteLength().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_FRIEND_API bool JS_GetTypedArraySharedness(JSObject* obj) {
|
JS_FRIEND_API bool JS_GetTypedArraySharedness(JSObject* obj) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче