mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:47:34 +00:00
LibWeb+LibWasm: Implement and use the "reset the Memory buffer" steps
This implements the memory object cache and its "reset on grow" semantics, as the web depends on the exact behaviour.
This commit is contained in:
parent
14fb6372c3
commit
64da05a96d
3 changed files with 55 additions and 5 deletions
|
@ -398,7 +398,12 @@ public:
|
|||
auto& data() const { return m_data; }
|
||||
auto& data() { return m_data; }
|
||||
|
||||
bool grow(size_t size_to_grow)
|
||||
enum class InhibitGrowCallback {
|
||||
No,
|
||||
Yes,
|
||||
};
|
||||
|
||||
bool grow(size_t size_to_grow, InhibitGrowCallback inhibit_callback = InhibitGrowCallback::No)
|
||||
{
|
||||
if (size_to_grow == 0)
|
||||
return true;
|
||||
|
@ -416,9 +421,17 @@ public:
|
|||
m_size = new_size;
|
||||
// The spec requires that we zero out everything on grow
|
||||
__builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow);
|
||||
|
||||
// NOTE: This exists because wasm-js-api wants to execute code after a successful grow,
|
||||
// See [this issue](https://github.com/WebAssembly/spec/issues/1635) for more details.
|
||||
if (inhibit_callback == InhibitGrowCallback::No && successful_grow_hook)
|
||||
successful_grow_hook();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Function<void()> successful_grow_hook;
|
||||
|
||||
private:
|
||||
explicit MemoryInstance(MemoryType const& type)
|
||||
: m_type(type)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue