mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 17:40:27 +00:00
LibJS: Make TypedArray::data() return a Span<T>
This inserts bounds checking assertions whenever we're reading/writing a typed array from JS.
This commit is contained in:
parent
a65f178ce8
commit
df8f074cf6
Notes:
sideshowbarker
2024-07-18 22:03:21 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/df8f074cf61
1 changed files with 10 additions and 3 deletions
|
@ -50,7 +50,7 @@ public:
|
|||
virtual size_t element_size() const = 0;
|
||||
|
||||
protected:
|
||||
TypedArrayBase(Object& prototype)
|
||||
explicit TypedArrayBase(Object& prototype)
|
||||
: Object(prototype)
|
||||
{
|
||||
}
|
||||
|
@ -116,7 +116,14 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
T* data() const { return reinterpret_cast<T*>(m_viewed_array_buffer->buffer().data()); }
|
||||
Span<const T> data() const
|
||||
{
|
||||
return { reinterpret_cast<const T*>(m_viewed_array_buffer->buffer().data()), m_array_length };
|
||||
}
|
||||
Span<T> data()
|
||||
{
|
||||
return { reinterpret_cast<T*>(m_viewed_array_buffer->buffer().data()), m_array_length };
|
||||
}
|
||||
|
||||
virtual size_t element_size() const override { return sizeof(T); };
|
||||
|
||||
|
@ -127,7 +134,7 @@ protected:
|
|||
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);
|
||||
ASSERT(!data().is_null());
|
||||
m_array_length = array_length;
|
||||
m_byte_length = m_viewed_array_buffer->byte_length();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue