зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1225040 - generalize jsapi-tests for SAB. r=arai
--HG-- extra : rebase_source : cb9fcbed7c7f28a8a3f22e71273f4fd0d18ff82d extra : amend_source : d42d5d61e2a4476f8fa59dd111b72ecfe08a54e7
This commit is contained in:
Родитель
78aa2c6f8d
Коммит
d1f95ce1ab
|
@ -39,23 +39,37 @@ BEGIN_TEST(testTypedArrays)
|
|||
bool isShared;
|
||||
CHECK_EQUAL(JS_GetArrayBufferByteLength(buffer), nbytes);
|
||||
memset(JS_GetArrayBufferData(buffer, &isShared, nogc), 1, nbytes);
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK(!isShared); // Because ArrayBuffer
|
||||
}
|
||||
|
||||
ok = ok &&
|
||||
TestArrayFromBuffer<JS_NewInt8ArrayWithBuffer, JS_NewInt8ArrayFromArray, int8_t, JS_GetInt8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ArrayWithBuffer, JS_NewUint8ArrayFromArray, uint8_t, JS_GetUint8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ClampedArrayWithBuffer, JS_NewUint8ClampedArrayFromArray, uint8_t, JS_GetUint8ClampedArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt16ArrayWithBuffer, JS_NewInt16ArrayFromArray, int16_t, JS_GetInt16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint16ArrayWithBuffer, JS_NewUint16ArrayFromArray, uint16_t, JS_GetUint16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt32ArrayWithBuffer, JS_NewInt32ArrayFromArray, int32_t, JS_GetInt32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint32ArrayWithBuffer, JS_NewUint32ArrayFromArray, uint32_t, JS_GetUint32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat32ArrayWithBuffer, JS_NewFloat32ArrayFromArray, float, JS_GetFloat32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat64ArrayWithBuffer, JS_NewFloat64ArrayFromArray, double, JS_GetFloat64ArrayData>(cx);
|
||||
TestArrayFromBuffer<JS_NewInt8ArrayWithBuffer, JS_NewInt8ArrayFromArray, int8_t, false, JS_GetInt8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ArrayWithBuffer, JS_NewUint8ArrayFromArray, uint8_t, false, JS_GetUint8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ClampedArrayWithBuffer, JS_NewUint8ClampedArrayFromArray, uint8_t, false, JS_GetUint8ClampedArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt16ArrayWithBuffer, JS_NewInt16ArrayFromArray, int16_t, false, JS_GetInt16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint16ArrayWithBuffer, JS_NewUint16ArrayFromArray, uint16_t, false, JS_GetUint16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt32ArrayWithBuffer, JS_NewInt32ArrayFromArray, int32_t, false, JS_GetInt32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint32ArrayWithBuffer, JS_NewUint32ArrayFromArray, uint32_t, false, JS_GetUint32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat32ArrayWithBuffer, JS_NewFloat32ArrayFromArray, float, false, JS_GetFloat32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat64ArrayWithBuffer, JS_NewFloat64ArrayFromArray, double, false, JS_GetFloat64ArrayData>(cx);
|
||||
|
||||
ok = ok &&
|
||||
TestArrayFromBuffer<JS_NewInt8ArrayWithBuffer, JS_NewInt8ArrayFromArray, int8_t, true, JS_GetInt8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ArrayWithBuffer, JS_NewUint8ArrayFromArray, uint8_t, true, JS_GetUint8ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint8ClampedArrayWithBuffer, JS_NewUint8ClampedArrayFromArray, uint8_t, true, JS_GetUint8ClampedArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt16ArrayWithBuffer, JS_NewInt16ArrayFromArray, int16_t, true, JS_GetInt16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint16ArrayWithBuffer, JS_NewUint16ArrayFromArray, uint16_t, true, JS_GetUint16ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewInt32ArrayWithBuffer, JS_NewInt32ArrayFromArray, int32_t, true, JS_GetInt32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewUint32ArrayWithBuffer, JS_NewUint32ArrayFromArray, uint32_t, true, JS_GetUint32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat32ArrayWithBuffer, JS_NewFloat32ArrayFromArray, float, true, JS_GetFloat32ArrayData>(cx) &&
|
||||
TestArrayFromBuffer<JS_NewFloat64ArrayWithBuffer, JS_NewFloat64ArrayFromArray, double, true, JS_GetFloat64ArrayData>(cx);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Shared memory can only be mapped by a TypedArray by creating the
|
||||
// TypedArray with a SharedArrayBuffer explicitly, so no tests here.
|
||||
|
||||
template<JSObject* Create(JSContext*, uint32_t),
|
||||
typename Element,
|
||||
Element* GetData(JSObject*, bool* isShared, const JS::AutoCheckCannotGC&)>
|
||||
|
@ -82,7 +96,7 @@ TestPlainTypedArray(JSContext* cx)
|
|||
Element* data;
|
||||
bool isShared;
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK(!isShared); // Because ArrayBuffer
|
||||
*data = 13;
|
||||
}
|
||||
RootedValue v(cx);
|
||||
|
@ -95,18 +109,22 @@ TestPlainTypedArray(JSContext* cx)
|
|||
template<JSObject* CreateWithBuffer(JSContext*, JS::HandleObject, uint32_t, int32_t),
|
||||
JSObject* CreateFromArray(JSContext*, JS::HandleObject),
|
||||
typename Element,
|
||||
bool Shared,
|
||||
Element* GetData(JSObject*, bool*, const JS::AutoCheckCannotGC&)>
|
||||
bool
|
||||
TestArrayFromBuffer(JSContext* cx)
|
||||
{
|
||||
size_t elts = 8;
|
||||
size_t nbytes = elts * sizeof(Element);
|
||||
RootedObject buffer(cx, JS_NewArrayBuffer(cx, nbytes));
|
||||
RootedObject buffer(cx, Shared ? JS_NewSharedArrayBuffer(cx, nbytes)
|
||||
: JS_NewArrayBuffer(cx, nbytes));
|
||||
{
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
bool isShared;
|
||||
memset(JS_GetArrayBufferData(buffer, &isShared, nogc), 1, nbytes);
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
void* data = Shared ? JS_GetSharedArrayBufferData(buffer, &isShared, nogc)
|
||||
: JS_GetArrayBufferData(buffer, &isShared, nogc);
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
memset(data, 1, nbytes);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -121,18 +139,22 @@ TestArrayFromBuffer(JSContext* cx)
|
|||
{
|
||||
bool isShared;
|
||||
CHECK_EQUAL(JS_GetArrayBufferViewBuffer(cx, array, &isShared), (JSObject*) buffer);
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
}
|
||||
|
||||
{
|
||||
JS::AutoCheckCannotGC nogc;
|
||||
Element* data;
|
||||
bool isShared;
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
CHECK_EQUAL((void*) data, (void*) JS_GetArrayBufferData(buffer, &isShared, nogc));
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
|
||||
CHECK_EQUAL(*reinterpret_cast<uint8_t*>(JS_GetArrayBufferData(buffer, &isShared, nogc)), 1u);
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
|
||||
CHECK_EQUAL((void*) data,
|
||||
Shared ? (void*) JS_GetSharedArrayBufferData(buffer, &isShared, nogc)
|
||||
: (void*) JS_GetArrayBufferData(buffer, &isShared, nogc));
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
|
||||
CHECK_EQUAL(*reinterpret_cast<uint8_t*>(data), 1u);
|
||||
}
|
||||
|
||||
|
@ -159,7 +181,7 @@ TestArrayFromBuffer(JSContext* cx)
|
|||
Element* data;
|
||||
bool isShared;
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[0]));
|
||||
}
|
||||
|
||||
|
@ -174,7 +196,7 @@ TestArrayFromBuffer(JSContext* cx)
|
|||
Element* data;
|
||||
bool isShared;
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[elts / 2]));
|
||||
}
|
||||
|
||||
|
@ -189,7 +211,7 @@ TestArrayFromBuffer(JSContext* cx)
|
|||
Element* data;
|
||||
bool isShared;
|
||||
CHECK(data = GetData(array, &isShared, nogc));
|
||||
MOZ_ASSERT(!isShared); // Because ArrayBuffer
|
||||
CHECK_EQUAL(Shared, isShared);
|
||||
CHECK_EQUAL(long(v.toInt32()), long(reinterpret_cast<Element*>(data)[elts - 1]));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче