Remove AllocationKind from array buffer handling

With the new v8 interface for externalizing array buffer contents, we
no longer need to store the kind or allocation_base/size on the blink
side. Hence, this change removes those fields completely.

Furthermore, gin now also uses the custom deleter based interface.

Change-Id: Ifa1a1900e83e7f9fab859672edc8fe54ad7e647e
Reviewed-on: https://chromium-review.googlesource.com/1235937
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Jochen Eisinger <[email protected]>
Commit-Queue: Stephan Herhut <[email protected]>
Cr-Commit-Position: refs/heads/master@{#593613}
diff --git a/gin/array_buffer.cc b/gin/array_buffer.cc
index f84934bf..a02797e 100644
--- a/gin/array_buffer.cc
+++ b/gin/array_buffer.cc
@@ -83,6 +83,7 @@
 
  private:
   friend class base::RefCounted<Private>;
+  using DataDeleter = void (*)(void* data, size_t length, void* info);
 
   Private(v8::Isolate* isolate, v8::Local<v8::ArrayBuffer> array);
   ~Private();
@@ -95,9 +96,8 @@
   v8::Isolate* isolate_;
   void* buffer_;
   size_t length_;
-  void* allocation_base_;
-  size_t allocation_length_;
-  v8::ArrayBuffer::Allocator::AllocationMode allocation_mode_;
+  DataDeleter deleter_;
+  void* deleter_data_;
 };
 
 scoped_refptr<ArrayBuffer::Private> ArrayBuffer::Private::From(
@@ -118,18 +118,10 @@
   // Take ownership of the array buffer.
   CHECK(!array->IsExternal());
   v8::ArrayBuffer::Contents contents = array->Externalize();
-  // We shouldn't receive large page-allocated array buffers.
-  CHECK_NE(v8::ArrayBuffer::Allocator::AllocationMode::kReservation,
-           contents.AllocationMode());
   buffer_ = contents.Data();
   length_ = contents.ByteLength();
-  allocation_base_ = contents.AllocationBase();
-  allocation_length_ = contents.AllocationLength();
-
-  DCHECK(reinterpret_cast<uintptr_t>(allocation_base_) <=
-         reinterpret_cast<uintptr_t>(buffer_));
-  DCHECK(reinterpret_cast<uintptr_t>(buffer_) + length_ <=
-         reinterpret_cast<uintptr_t>(allocation_base_) + allocation_length_);
+  deleter_ = contents.Deleter();
+  deleter_data_ = contents.DeleterData();
 
   array->SetAlignedPointerInInternalField(kWrapperInfoIndex,
                                           &g_array_buffer_wrapper_info);
@@ -141,8 +133,7 @@
 }
 
 ArrayBuffer::Private::~Private() {
-  PerIsolateData::From(isolate_)->allocator()->Free(allocation_base_,
-                                                    allocation_length_);
+  deleter_(buffer_, length_, deleter_data_);
 }
 
 void ArrayBuffer::Private::FirstWeakCallback(