Commit 5cf7b3a1 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[arraybuffer] Allow nullptr backing store

I removed all uses of ArrayBufferContents that assumed that the start
of backing store is always not nullptr. Now we can also remove this
invariant altogether.

R=haraken@chromium.org

Bug: chromium:1008840
Change-Id: I479e502a986b4eb9ee3c6d56c7a99b6c677007bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1904067
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#717523}
parent 6d35f0b6
......@@ -80,7 +80,7 @@ bool ArrayBuffer::ShareContentsWith(ArrayBufferContents& result) {
DCHECK(IsShared());
scoped_refptr<ArrayBuffer> keep_alive(this);
if (!contents_.DataShared()) {
if (!contents_.BackingStore()) {
result.Detach();
return false;
}
......@@ -93,7 +93,7 @@ bool ArrayBuffer::ShareNonSharedForInternalUse(ArrayBufferContents& result) {
DCHECK(!IsShared());
scoped_refptr<ArrayBuffer> keep_alive(this);
if (!contents_.Data()) {
if (!contents_.BackingStore()) {
result.Detach();
return false;
}
......
......@@ -71,30 +71,6 @@ ArrayBufferContents::ArrayBufferContents(
}
}
ArrayBufferContents::ArrayBufferContents(
std::shared_ptr<v8::BackingStore> backing_store) {
if (!backing_store || backing_store->Data()) {
backing_store_ = std::move(backing_store);
return;
}
// ArrayBufferContents has to guarantee that Data() provides a valid pointer,
// even when DataSize() is '0'. That's why we create a new BackingStore here.
// TODO(ahaas): Remove this code here once nullptr is a valid result for
// Data().
CHECK_EQ(backing_store->ByteLength(), 0u);
void* data = AllocateMemoryOrNull(0, kDontInitialize);
CHECK_NE(data, nullptr);
DataDeleter deleter = [](void* data, size_t, void*) { FreeMemory(data); };
if (!backing_store->IsShared()) {
backing_store_ =
v8::ArrayBuffer::NewBackingStore(data, 0, deleter, nullptr);
} else {
backing_store_ =
v8::SharedArrayBuffer::NewBackingStore(data, 0, deleter, nullptr);
}
}
ArrayBufferContents::~ArrayBufferContents() = default;
void ArrayBufferContents::Detach() {
......
......@@ -65,7 +65,8 @@ class CORE_EXPORT ArrayBufferContents {
InitializationPolicy);
ArrayBufferContents(void* data, size_t length, DataDeleter deleter);
ArrayBufferContents(ArrayBufferContents&&) = default;
explicit ArrayBufferContents(std::shared_ptr<v8::BackingStore> backing_store);
explicit ArrayBufferContents(std::shared_ptr<v8::BackingStore> backing_store)
: backing_store_(std::move(backing_store)) {}
~ArrayBufferContents();
......
......@@ -80,6 +80,7 @@ v8::Local<v8::Object> DOMArrayBuffer::Wrap(
v8::Context::Scope context_scope(creation_context->CreationContext());
wrapper =
v8::ArrayBuffer::New(isolate, Buffer()->Content()->BackingStore());
wrapper->Externalize(Buffer()->Content()->BackingStore());
}
......
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