Commit 22d5de04 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[arraybuffer] Allow transfer of empty ArrayBuffer

With a recent change, ArrayBuffers are allowed to have nullptr as their
`Data` pointer. However, a condition in ArrayBuffer::Transfer bailed out
if Data() was nullptr. I changed the condition now, and added a test.

R=haraken@chromium.org

Bug: chromium:1027937
Change-Id: I2fe466bcfe016d850f11211f2ef8104f1f27d41f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1932791
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719113}
parent b1067492
...@@ -34,11 +34,17 @@ bool ArrayBuffer::Transfer(ArrayBufferContents& result) { ...@@ -34,11 +34,17 @@ bool ArrayBuffer::Transfer(ArrayBufferContents& result) {
DCHECK(!IsShared()); DCHECK(!IsShared());
scoped_refptr<ArrayBuffer> keep_alive(this); scoped_refptr<ArrayBuffer> keep_alive(this);
if (!contents_.Data()) { if (is_detached_) {
result.Detach(); result.Detach();
return false; return false;
} }
if (!contents_.Data()) {
// We transfer an empty ArrayBuffer, we can just allocate an empty content.
result = ArrayBufferContents();
return true;
}
bool all_views_are_detachable = true; bool all_views_are_detachable = true;
for (ArrayBufferView* i = first_view_; i; i = i->next_view_) { for (ArrayBufferView* i = first_view_; i; i = i->next_view_) {
if (!i->IsDetachable()) if (!i->IsDetachable())
......
<!DOCTYPE html>
<title>Verify media element's "src" attribute on "loadstart" event.</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
test(function(t) {
const arrayBuffer = new ArrayBuffer(0);
const { port1 } = new MessageChannel();
port1.postMessage(arrayBuffer, [ arrayBuffer ]);
}, "Calling postMessage with an empty ArrayBuffer is valid.");
</script>
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