@@ -19584,8 +19584,10 @@ Handle<String> JSMessageObject::GetSourceLine() const {
1958419584void JSArrayBuffer::Neuter() {
1958519585 CHECK(is_neuterable());
1958619586 CHECK(is_external());
19587- set_backing_store(NULL );
19587+ set_backing_store(nullptr );
1958819588 set_byte_length(Smi::kZero);
19589+ set_allocation_base(nullptr);
19590+ set_allocation_length(0);
1958919591 set_was_neutered(true);
1959019592 // Invalidate the neutering protector.
1959119593 Isolate* const isolate = GetIsolate();
@@ -19594,10 +19596,25 @@ void JSArrayBuffer::Neuter() {
1959419596 }
1959519597}
1959619598
19599+ void JSArrayBuffer::FreeBackingStore() {
19600+ using AllocationMode = ArrayBuffer::Allocator::AllocationMode;
19601+ const size_t length = allocation_length();
19602+ const AllocationMode mode = has_guard_region() ? AllocationMode::kReservation
19603+ : AllocationMode::kNormal;
19604+ GetIsolate()->array_buffer_allocator()->Free(allocation_base(), length, mode);
19605+ }
1959719606
1959819607void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
1959919608 bool is_external, void* data, size_t allocated_length,
1960019609 SharedFlag shared) {
19610+ return Setup(array_buffer, isolate, is_external, data, allocated_length, data,
19611+ allocated_length, shared);
19612+ }
19613+
19614+ void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
19615+ bool is_external, void* allocation_base,
19616+ size_t allocation_length, void* data,
19617+ size_t byte_length, SharedFlag shared) {
1960119618 DCHECK(array_buffer->GetEmbedderFieldCount() ==
1960219619 v8::ArrayBuffer::kEmbedderFieldCount);
1960319620 for (int i = 0; i < v8::ArrayBuffer::kEmbedderFieldCount; i++) {
@@ -19608,16 +19625,19 @@ void JSArrayBuffer::Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
1960819625 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared);
1960919626 array_buffer->set_is_shared(shared == SharedFlag::kShared);
1961019627
19611- Handle<Object> byte_length =
19612- isolate->factory()->NewNumberFromSize(allocated_length );
19613- CHECK(byte_length ->IsSmi() || byte_length ->IsHeapNumber());
19614- array_buffer->set_byte_length(*byte_length );
19628+ Handle<Object> heap_byte_length =
19629+ isolate->factory()->NewNumberFromSize(byte_length );
19630+ CHECK(heap_byte_length ->IsSmi() || heap_byte_length ->IsHeapNumber());
19631+ array_buffer->set_byte_length(*heap_byte_length );
1961519632 // Initialize backing store at last to avoid handling of |JSArrayBuffers| that
1961619633 // are currently being constructed in the |ArrayBufferTracker|. The
1961719634 // registration method below handles the case of registering a buffer that has
1961819635 // already been promoted.
1961919636 array_buffer->set_backing_store(data);
1962019637
19638+ array_buffer->set_allocation_base(data);
19639+ array_buffer->set_allocation_length(allocation_length);
19640+
1962119641 if (data && !is_external) {
1962219642 isolate->heap()->RegisterNewArrayBuffer(*array_buffer);
1962319643 }
@@ -19658,8 +19678,9 @@ bool JSArrayBuffer::SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
1965819678 data = NULL;
1965919679 }
1966019680
19661- JSArrayBuffer::Setup(array_buffer, isolate, false, data, allocated_length,
19662- shared);
19681+ const bool is_external = false;
19682+ JSArrayBuffer::Setup(array_buffer, isolate, is_external, data,
19683+ allocated_length, shared);
1966319684 return true;
1966419685}
1966519686
@@ -19690,6 +19711,8 @@ Handle<JSArrayBuffer> JSTypedArray::MaterializeArrayBuffer(
1969019711 // already been promoted.
1969119712 buffer->set_backing_store(backing_store);
1969219713 isolate->heap()->RegisterNewArrayBuffer(*buffer);
19714+ buffer->set_allocation_base(backing_store);
19715+ buffer->set_allocation_length(NumberToSize(buffer->byte_length()));
1969319716 memcpy(buffer->backing_store(),
1969419717 fixed_typed_array->DataPtr(),
1969519718 fixed_typed_array->DataSize());
0 commit comments