@@ -124,6 +124,7 @@ BackingStore::~BackingStore() {
124
124
125
125
if (is_wasm_memory_) {
126
126
DCHECK (free_on_destruct_);
127
+ DCHECK (!custom_deleter_);
127
128
TRACE_BS (" BSw:free bs=%p mem=%p (length=%zu, capacity=%zu)\n " , this ,
128
129
buffer_start_, byte_length (), byte_capacity_);
129
130
if (is_shared_) {
@@ -149,6 +150,14 @@ BackingStore::~BackingStore() {
149
150
Clear ();
150
151
return ;
151
152
}
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
+ }
152
161
if (free_on_destruct_) {
153
162
// JSArrayBuffer backing store. Deallocate through the embedder's allocator.
154
163
auto allocator = reinterpret_cast <v8::ArrayBuffer::Allocator*>(
@@ -210,7 +219,8 @@ std::unique_ptr<BackingStore> BackingStore::Allocate(
210
219
shared, // shared
211
220
false , // is_wasm_memory
212
221
true , // free_on_destruct
213
- false ); // has_guard_regions
222
+ false , // has_guard_regions
223
+ false ); // custom_deleter
214
224
215
225
TRACE_BS (" BS:alloc bs=%p mem=%p (length=%zu)\n " , result,
216
226
result->buffer_start (), byte_length);
@@ -321,7 +331,8 @@ std::unique_ptr<BackingStore> BackingStore::TryAllocateWasmMemory(
321
331
shared, // shared
322
332
true , // is_wasm_memory
323
333
true , // free_on_destruct
324
- guards); // has_guard_regions
334
+ guards, // has_guard_regions
335
+ false ); // custom_deleter
325
336
326
337
TRACE_BS (" BSw:alloc bs=%p mem=%p (length=%zu, capacity=%zu)\n " , result,
327
338
result->buffer_start (), byte_length, byte_capacity);
@@ -451,16 +462,40 @@ void BackingStore::UpdateSharedWasmMemoryObjects(Isolate* isolate) {
451
462
std::unique_ptr<BackingStore> BackingStore::WrapAllocation (
452
463
Isolate* isolate, void * allocation_base, size_t allocation_length,
453
464
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
457
473
result->type_specific_data_ .v8_api_array_buffer_allocator =
458
474
isolate->array_buffer_allocator ();
459
475
TRACE_BS (" BS:wrap bs=%p mem=%p (length=%zu)\n " , result,
460
476
result->buffer_start (), result->byte_length ());
461
477
return std::unique_ptr<BackingStore>(result);
462
478
}
463
479
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
+
464
499
std::unique_ptr<BackingStore> BackingStore::EmptyBackingStore (
465
500
SharedFlag shared) {
466
501
auto result = new BackingStore (nullptr , // start
@@ -469,7 +504,8 @@ std::unique_ptr<BackingStore> BackingStore::EmptyBackingStore(
469
504
shared, // shared
470
505
false , // is_wasm_memory
471
506
false , // free_on_destruct
472
- false ); // has_guard_regions
507
+ false , // has_guard_regions
508
+ false ); // custom_deleter
473
509
474
510
return std::unique_ptr<BackingStore>(result);
475
511
}
@@ -512,6 +548,9 @@ void GlobalBackingStoreRegistry::Register(
512
548
// then we don't have to guarantee that there is single unique
513
549
// BackingStore per buffer_start() because the destructor of
514
550
// 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 ());
515
554
return ;
516
555
}
517
556
0 commit comments