@@ -124,6 +124,7 @@ BackingStore::~BackingStore() {
124124
125125 if (is_wasm_memory_) {
126126 DCHECK (free_on_destruct_);
127+ DCHECK (!custom_deleter_);
127128 TRACE_BS (" BSw:free bs=%p mem=%p (length=%zu, capacity=%zu)\n " , this ,
128129 buffer_start_, byte_length (), byte_capacity_);
129130 if (is_shared_) {
@@ -149,6 +150,14 @@ BackingStore::~BackingStore() {
149150 Clear ();
150151 return ;
151152 }
153+ if (custom_deleter_) {
154+ DCHECK (free_on_destruct_);
155+ TRACE_BS (" BS:custome deleter bs=%p mem=%p (length=%zu, capacity=%zu)\n " ,
156+ this , buffer_start_, byte_length (), byte_capacity_);
157+ type_specific_data_.deleter (buffer_start_, byte_length_, deleter_data_);
158+ Clear ();
159+ return ;
160+ }
152161 if (free_on_destruct_) {
153162 // JSArrayBuffer backing store. Deallocate through the embedder's allocator.
154163 auto allocator = reinterpret_cast <v8::ArrayBuffer::Allocator*>(
@@ -210,7 +219,8 @@ std::unique_ptr<BackingStore> BackingStore::Allocate(
210219 shared, // shared
211220 false , // is_wasm_memory
212221 true , // free_on_destruct
213- false ); // has_guard_regions
222+ false , // has_guard_regions
223+ false ); // custom_deleter
214224
215225 TRACE_BS (" BS:alloc bs=%p mem=%p (length=%zu)\n " , result,
216226 result->buffer_start (), byte_length);
@@ -321,7 +331,8 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateWasmMemory(
321331 shared, // shared
322332 true , // is_wasm_memory
323333 true , // free_on_destruct
324- guards); // has_guard_regions
334+ guards, // has_guard_regions
335+ false ); // custom_deleter
325336
326337 TRACE_BS (" BSw:alloc bs=%p mem=%p (length=%zu, capacity=%zu)\n " , result,
327338 result->buffer_start (), byte_length, byte_capacity);
@@ -451,16 +462,40 @@ void BackingStore::UpdateSharedWasmMemoryObjects(Isolate* isolate) {
451462std::unique_ptr<BackingStore> BackingStore::WrapAllocation (
452463 Isolate* isolate, void * allocation_base, size_t allocation_length,
453464 SharedFlag shared, bool free_on_destruct) {
454- auto result =
455- new BackingStore (allocation_base, allocation_length, allocation_length,
456- shared, false , free_on_destruct, false );
465+ auto result = new BackingStore (allocation_base, // start
466+ allocation_length, // length
467+ allocation_length, // capacity
468+ shared, // shared
469+ false , // is_wasm_memory
470+ free_on_destruct, // free_on_destruct
471+ false , // has_guard_regions
472+ false ); // custom_deleter
457473 result->type_specific_data_ .v8_api_array_buffer_allocator =
458474 isolate->array_buffer_allocator ();
459475 TRACE_BS (" BS:wrap bs=%p mem=%p (length=%zu)\n " , result,
460476 result->buffer_start (), result->byte_length ());
461477 return std::unique_ptr<BackingStore>(result);
462478}
463479
480+ std::unique_ptr<BackingStore> BackingStore::WrapAllocation (
481+ void * allocation_base, size_t allocation_length,
482+ v8::BackingStoreDeleterCallback deleter, void * deleter_data,
483+ SharedFlag shared) {
484+ auto result = new BackingStore (allocation_base, // start
485+ allocation_length, // length
486+ allocation_length, // capacity
487+ shared, // shared
488+ false , // is_wasm_memory
489+ true , // free_on_destruct
490+ false , // has_guard_regions
491+ true ); // custom_deleter
492+ result->type_specific_data_ .deleter = deleter;
493+ result->deleter_data_ = deleter_data;
494+ TRACE_BS (" BS:wrap bs=%p mem=%p (length=%zu)\n " , result,
495+ result->buffer_start (), result->byte_length ());
496+ return std::unique_ptr<BackingStore>(result);
497+ }
498+
464499std::unique_ptr<BackingStore> BackingStore::EmptyBackingStore (
465500 SharedFlag shared) {
466501 auto result = new BackingStore (nullptr , // start
@@ -469,7 +504,8 @@ std::unique_ptr<BackingStore> BackingStore::EmptyBackingStore(
469504 shared, // shared
470505 false , // is_wasm_memory
471506 false , // free_on_destruct
472- false ); // has_guard_regions
507+ false , // has_guard_regions
508+ false ); // custom_deleter
473509
474510 return std::unique_ptr<BackingStore>(result);
475511}
@@ -512,6 +548,9 @@ void GlobalBackingStoreRegistry::Register(
512548 // then we don't have to guarantee that there is single unique
513549 // BackingStore per buffer_start() because the destructor of
514550 // of the BackingStore will be a no-op in that case.
551+
552+ // All WASM memory has to be registered.
553+ CHECK (!backing_store->is_wasm_memory ());
515554 return ;
516555 }
517556
0 commit comments