Commit 8d511cbd authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

[wasm] Growing memory should always allocate a new JS buffer

The UpdateSharedWasmMemoryObjects function only creates a new
JSArrayBuffer when the the legths of old/new ArrayBuffer objects
are unequal, but the CHECK in the Grow() funciton assumes that a new
object is always created. Fix so that a new ArrayBuffer is always
allocated.

Bug: v8:10044, chromium:1040325
Change-Id: I66912bdc091e65a57e5b50f4ed63b0da5492dcc4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1999603Reviewed-by: 's avatarBen Smith <binji@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65742}
parent bd51a5ea
......@@ -732,12 +732,10 @@ void GlobalBackingStoreRegistry::UpdateSharedWasmMemoryObjects(
Handle<JSArrayBuffer> old_buffer(memory_object->array_buffer(), isolate);
std::shared_ptr<BackingStore> backing_store = old_buffer->GetBackingStore();
if (old_buffer->byte_length() != backing_store->byte_length()) {
Handle<JSArrayBuffer> new_buffer =
isolate->factory()->NewJSSharedArrayBuffer(std::move(backing_store));
memory_object->update_instances(isolate, new_buffer);
}
}
}
} // namespace internal
......
......@@ -344,3 +344,9 @@ let workerHelpers = assertTrue.toString() + assertIsWasmSharedMemory.toString();
assertEquals(memory.grow(1), 1);
assertInstanceof(memory.buffer, SharedArrayBuffer);
})();
(function TestSharedMemoryGrowByZero() {
const memory = new WebAssembly.Memory({
"initial": 1, "maximum": 2, "shared": true });
assertEquals(memory.grow(0), 1);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment