diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-06-11 00:59:24 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-11 13:38:25 +0100 |
commit | f5a978c1aa7a7086e613c7fb90772be5eee511a5 (patch) | |
tree | 2e04695b08085c7e7f1682da5ba280b1905fecd4 /Userland | |
parent | a64089092fa894161442599675843dfa757b98f4 (diff) | |
download | serenity-f5a978c1aa7a7086e613c7fb90772be5eee511a5.zip |
LibWeb: Set a detach key for ArrayBuffers returned from WASM
As required by the specification:
`Set buffer.[[ArrayBufferDetachKey]] to "WebAssembly.Memory".`
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ArrayBuffer.h | 4 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp | 4 |
3 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp index 52356cc8c5..0f5419c9f4 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.cpp @@ -37,4 +37,10 @@ ArrayBuffer::~ArrayBuffer() { } +void ArrayBuffer::visit_edges(Cell::Visitor& visitor) +{ + Object::visit_edges(visitor); + visitor.visit(m_detach_key); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h index 1fd2e6798f..82e886fbcf 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h +++ b/Userland/Libraries/LibJS/Runtime/ArrayBuffer.h @@ -28,10 +28,14 @@ public: const ByteBuffer& buffer() const { return buffer_impl(); } Value detach_key() const { return m_detach_key; } + void set_detach_key(Value detach_key) { m_detach_key = detach_key; } + void detach_buffer() { m_buffer = Empty {}; } bool is_detached() const { return m_buffer.has<Empty>(); } private: + virtual void visit_edges(Visitor&) override; + ByteBuffer& buffer_impl() { ByteBuffer* ptr { nullptr }; diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index b4bd033dc4..c071b9d705 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -441,7 +441,9 @@ JS_DEFINE_NATIVE_GETTER(WebAssemblyMemoryObject::buffer) if (!memory) return JS::js_undefined(); - return JS::ArrayBuffer::create(global_object, &memory->data()); + auto array_buffer = JS::ArrayBuffer::create(global_object, &memory->data()); + array_buffer->set_detach_key(JS::js_string(vm, "WebAssembly.Memory")); + return array_buffer; } } |