@@ -552,6 +552,21 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
552552 }
553553
554554 void Free (void * data, size_t ) override { free (data); }
555+
556+ void * Reallocate (void * data, size_t old_length, size_t new_length) override {
557+ #if V8_OS_AIX && _LINUX_SOURCE_COMPAT
558+ // Work around for GCC bug on AIX
559+ // See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79839
560+ void * new_data = __linux_realloc (data, new_length);
561+ #else
562+ void * new_data = realloc (data, new_length);
563+ #endif
564+ if (new_length > old_length) {
565+ memset (reinterpret_cast <uint8_t *>(new_data) + old_length, 0 ,
566+ new_length - old_length);
567+ }
568+ return new_data;
569+ }
555570};
556571
557572struct SnapshotCreatorData {
@@ -3759,6 +3774,22 @@ bool v8::BackingStore::IsShared() const {
37593774 return reinterpret_cast <const i::BackingStore*>(this )->is_shared ();
37603775}
37613776
3777+ // static
3778+ std::unique_ptr<v8::BackingStore> v8::BackingStore::Reallocate (
3779+ v8::Isolate* isolate, std::unique_ptr<v8::BackingStore> backing_store,
3780+ size_t byte_length) {
3781+ i::Isolate* i_isolate = reinterpret_cast <i::Isolate*>(isolate);
3782+ LOG_API (i_isolate, ArrayBuffer, BackingStore_Reallocate);
3783+ CHECK_LE (byte_length, i::JSArrayBuffer::kMaxByteLength );
3784+ ENTER_V8_NO_SCRIPT_NO_EXCEPTION (i_isolate);
3785+ i::BackingStore* i_backing_store =
3786+ reinterpret_cast <i::BackingStore*>(backing_store.get ());
3787+ if (!i_backing_store->Reallocate (i_isolate, byte_length)) {
3788+ i::FatalProcessOutOfMemory (i_isolate, " v8::BackingStore::Reallocate" );
3789+ }
3790+ return backing_store;
3791+ }
3792+
37623793std::shared_ptr<v8::BackingStore> v8::ArrayBuffer::GetBackingStore () {
37633794 i::Handle<i::JSArrayBuffer> self = Utils::OpenHandle (this );
37643795 std::shared_ptr<i::BackingStore> backing_store = self->GetBackingStore ();
@@ -7204,6 +7235,21 @@ void WasmModuleObjectBuilderStreaming::Finish() {}
72047235
72057236void WasmModuleObjectBuilderStreaming::Abort (MaybeLocal<Value> exception) {}
72067237
7238+ void * v8::ArrayBuffer::Allocator::Reallocate (void * data, size_t old_length,
7239+ size_t new_length) {
7240+ if (old_length == new_length) return data;
7241+ uint8_t * new_data =
7242+ reinterpret_cast <uint8_t *>(AllocateUninitialized (new_length));
7243+ if (new_data == nullptr ) return nullptr ;
7244+ size_t bytes_to_copy = std::min (old_length, new_length);
7245+ memcpy (new_data, data, bytes_to_copy);
7246+ if (new_length > bytes_to_copy) {
7247+ memset (new_data + bytes_to_copy, 0 , new_length - bytes_to_copy);
7248+ }
7249+ Free (data, old_length);
7250+ return new_data;
7251+ }
7252+
72077253// static
72087254v8::ArrayBuffer::Allocator* v8::ArrayBuffer::Allocator::NewDefaultAllocator () {
72097255 return new ArrayBufferAllocator ();
0 commit comments