summaryrefslogtreecommitdiff
path: root/chromium/v8/src/objects/js-array-buffer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/v8/src/objects/js-array-buffer.cc')
-rw-r--r--chromium/v8/src/objects/js-array-buffer.cc29
1 files changed, 19 insertions, 10 deletions
diff --git a/chromium/v8/src/objects/js-array-buffer.cc b/chromium/v8/src/objects/js-array-buffer.cc
index 917a055b466..fd9f3133a5f 100644
--- a/chromium/v8/src/objects/js-array-buffer.cc
+++ b/chromium/v8/src/objects/js-array-buffer.cc
@@ -55,9 +55,8 @@ void JSArrayBuffer::Setup(SharedFlag shared, ResizableFlag resizable,
SetEmbedderField(i, Smi::zero());
}
set_extension(nullptr);
- AllocateExternalPointerEntries(GetIsolate());
if (!backing_store) {
- set_backing_store(GetIsolate(), nullptr);
+ set_backing_store(nullptr);
set_byte_length(0);
set_max_byte_length(0);
} else {
@@ -77,24 +76,23 @@ void JSArrayBuffer::Attach(std::shared_ptr<BackingStore> backing_store) {
!backing_store->is_wasm_memory() && !backing_store->is_resizable(),
backing_store->byte_length() == backing_store->max_byte_length());
DCHECK(!was_detached());
- Isolate* isolate = GetIsolate();
- set_backing_store(isolate, backing_store->buffer_start());
+ set_backing_store(backing_store->buffer_start());
if (is_shared() && is_resizable()) {
// GSABs need to read their byte_length from the BackingStore. Maintain the
// invariant that their byte_length field is always 0.
set_byte_length(0);
} else {
+ CHECK_LE(backing_store->byte_length(), kMaxByteLength);
set_byte_length(backing_store->byte_length());
}
set_max_byte_length(backing_store->max_byte_length());
if (backing_store->is_wasm_memory()) set_is_detachable(false);
if (!backing_store->free_on_destruct()) set_is_external(true);
- Heap* heap = isolate->heap();
ArrayBufferExtension* extension = EnsureExtension();
size_t bytes = backing_store->PerIsolateAccountingLength();
extension->set_accounting_length(bytes);
extension->set_backing_store(std::move(backing_store));
- heap->AppendArrayBufferExtension(*this, extension);
+ GetIsolate()->heap()->AppendArrayBufferExtension(*this, extension);
}
void JSArrayBuffer::Detach(bool force_for_wasm_memory) {
@@ -123,14 +121,25 @@ void JSArrayBuffer::Detach(bool force_for_wasm_memory) {
DCHECK(!is_shared());
DCHECK(!is_asmjs_memory());
- set_backing_store(isolate, nullptr);
+ set_backing_store(nullptr);
set_byte_length(0);
set_was_detached(true);
}
-std::shared_ptr<BackingStore> JSArrayBuffer::GetBackingStore() {
- if (!extension()) return nullptr;
- return extension()->backing_store();
+std::shared_ptr<BackingStore> JSArrayBuffer::GetBackingStore() const {
+ if (!extension()) return nullptr;
+ return extension()->backing_store();
+}
+
+size_t JSArrayBuffer::GetByteLength() const {
+ if V8_UNLIKELY (is_shared() && is_resizable()) {
+ // Invariant: byte_length for GSAB is 0 (it needs to be read from the
+ // BackingStore).
+ DCHECK_EQ(0, byte_length());
+
+ return GetBackingStore()->byte_length(std::memory_order_seq_cst);
+ }
+ return byte_length();
}
ArrayBufferExtension* JSArrayBuffer::EnsureExtension() {