diff --git a/include/v8-array-buffer.h b/include/v8-array-buffer.h index c942ef592f..60ca18bb94 100644 --- a/include/v8-array-buffer.h +++ b/include/v8-array-buffer.h @@ -53,6 +53,15 @@ class V8_EXPORT BackingStore : public v8::internal::BackingStoreBase { */ size_t ByteLength() const; + /** + * The maximum length (in bytes) that this backing store may grow to. + * + * If this backing store was created for a resizable ArrayBuffer or a growable + * SharedArrayBuffer, it is >= ByteLength(). Otherwise it is == + * ByteLength(). + */ + size_t MaxByteLength() const; + /** * Indicates whether the backing store was created for an ArrayBuffer or * a SharedArrayBuffer. diff --git a/src/api/api.cc b/src/api/api.cc index 3b53d5db76..e51bd24479 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -4191,6 +4191,10 @@ size_t v8::BackingStore::ByteLength() const { return reinterpret_cast(this)->byte_length(); } +size_t v8::BackingStore::MaxByteLength() const { + return reinterpret_cast(this)->max_byte_length(); +} + bool v8::BackingStore::IsShared() const { return reinterpret_cast(this)->is_shared(); } diff --git a/test/cctest/test-api-array-buffer.cc b/test/cctest/test-api-array-buffer.cc index 50feb1d270..667dc1c6e3 100644 --- a/test/cctest/test-api-array-buffer.cc +++ b/test/cctest/test-api-array-buffer.cc @@ -833,6 +833,7 @@ TEST(ArrayBuffer_Resizable) { CHECK(gsab->GetBackingStore()->IsResizableByUserJavaScript()); CHECK_EQ(32, gsab->ByteLength()); CHECK_EQ(1024, gsab->MaxByteLength()); + CHECK_EQ(gsab->MaxByteLength(), gsab->GetBackingStore()->MaxByteLength()); } TEST(ArrayBuffer_FixedLength) { @@ -848,9 +849,11 @@ TEST(ArrayBuffer_FixedLength) { CHECK(!ab->GetBackingStore()->IsResizableByUserJavaScript()); CHECK_EQ(32, ab->ByteLength()); CHECK_EQ(32, ab->MaxByteLength()); + CHECK_EQ(ab->MaxByteLength(), ab->GetBackingStore()->MaxByteLength()); v8::Local sab = CompileRun("new SharedArrayBuffer(32);").As(); CHECK(!sab->GetBackingStore()->IsResizableByUserJavaScript()); CHECK_EQ(32, sab->ByteLength()); CHECK_EQ(32, sab->MaxByteLength()); + CHECK_EQ(sab->MaxByteLength(), sab->GetBackingStore()->MaxByteLength()); }