mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:37:44 +00:00
LibJS: Add some assertions and tests for TypedArray limitations
This commit is contained in:
parent
0e3ee03e2b
commit
7a71d4b887
2 changed files with 21 additions and 0 deletions
|
@ -132,7 +132,10 @@ protected:
|
|||
TypedArray(u32 array_length, Object& prototype)
|
||||
: TypedArrayBase(prototype)
|
||||
{
|
||||
ASSERT(!Checked<u32>::multiplication_would_overflow(array_length, sizeof(T)));
|
||||
m_viewed_array_buffer = ArrayBuffer::create(global_object(), array_length * sizeof(T));
|
||||
if (array_length)
|
||||
ASSERT(data() != nullptr);
|
||||
m_array_length = array_length;
|
||||
m_byte_length = m_viewed_array_buffer->byte_length();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
test("some oversized typed arrays", () => {
|
||||
expect(() => new Uint8Array(2 * 1024 * 1024 * 1024)).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid typed array length"
|
||||
);
|
||||
expect(() => new Uint16Array(2 * 1024 * 1024 * 1024)).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid typed array length"
|
||||
);
|
||||
expect(() => new Uint32Array(1024 * 1024 * 1024)).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid typed array length"
|
||||
);
|
||||
expect(() => new Uint32Array(4 * 1024 * 1024 * 1024)).toThrowWithMessage(
|
||||
RangeError,
|
||||
"Invalid typed array length"
|
||||
);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue