From 20167900fb1d3e1fb725cdf820483b45fe011cf7 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 23 Nov 2026 11:36:54 -0500 Subject: [PATCH 1/3] src: migrate off ArrayBufferView::Buffer() V8 16.0 removes `ArrayBufferView::Buffer()`. Use `GetBuffer()` instead, which is already available in V8 15.8. Refs: https://crrev.com/c/8794471 Co-Authored-By: Clemens Backes Co-Authored-By: Joyee Cheung Signed-off-by: Chengzhong Wu --- src/aliased_buffer-inl.h | 8 ++++++-- src/crypto/crypto_random.cc | 2 +- src/crypto/crypto_util.cc | 2 +- src/crypto/crypto_util.h | 2 +- src/dataqueue/queue.cc | 12 +++++++++--- src/encoding_binding.cc | 5 +++-- src/ffi/data.cc | 4 ++-- src/ffi/fast.cc | 4 ++-- src/ffi/types.cc | 5 +++-- src/heap_utils.cc | 2 +- src/histogram.cc | 6 +++--- src/js_native_api_v8.cc | 12 ++++++------ src/module_wrap.cc | 2 +- src/node_blob.cc | 12 ++++++++---- src/node_buffer.cc | 13 +++++++------ src/node_contextify.cc | 4 ++-- src/node_file.cc | 2 +- src/node_internals.h | 4 ++-- src/node_ipc_serdes.cc | 9 +++++---- src/node_os.cc | 4 ++-- src/node_process_methods.cc | 14 +++++++------- src/node_sqlite.cc | 2 +- src/node_wasi.cc | 6 +++--- src/node_wasm_web_api.cc | 2 +- src/node_zlib.cc | 4 ++-- src/quic/data.cc | 4 ++-- src/quic/streams.cc | 13 +++++++++---- src/stream_base.cc | 4 ++-- src/util-inl.h | 4 ++-- src/util.h | 2 +- test/addons/openssl-binding/binding.cc | 4 ++-- test/addons/zlib-binding/binding.cc | 2 +- test/cctest/test_environment.cc | 4 ++-- test/cctest/test_node_ipc_serdes.cc | 2 +- 34 files changed, 102 insertions(+), 79 deletions(-) diff --git a/src/aliased_buffer-inl.h b/src/aliased_buffer-inl.h index 5cb36e707ce2..f3390fc367af 100644 --- a/src/aliased_buffer-inl.h +++ b/src/aliased_buffer-inl.h @@ -97,7 +97,7 @@ inline void AliasedBufferBase::Deserialize( // be removed when we expand the snapshot support. DCHECK_EQ(count_, arr->Length()); DCHECK_EQ(byte_offset_, arr->ByteOffset()); - uint8_t* raw = static_cast(arr->Buffer()->Data()); + uint8_t* raw = static_cast(arr->GetBuffer()->Data()); buffer_ = reinterpret_cast(raw + byte_offset_); js_array_.Reset(isolate_, arr); index_ = nullptr; @@ -146,7 +146,11 @@ template requires std::is_scalar_v v8::Local AliasedBufferBase::GetArrayBuffer() const { - return GetJSArray()->Buffer(); + // The JS array is always created over an ArrayBuffer allocated by + // AliasedBufferBase itself, never over a SharedArrayBuffer. + v8::Local buffer = GetJSArray()->GetBuffer(); + DCHECK(buffer->IsArrayBuffer()); + return buffer.As(); } template diff --git a/src/crypto/crypto_random.cc b/src/crypto/crypto_random.cc index 79c52a7d08c1..9dd3722a9458 100644 --- a/src/crypto/crypto_random.cc +++ b/src/crypto/crypto_random.cc @@ -33,7 +33,7 @@ namespace crypto { namespace { bool IsImmutableBufferSource(Local buffer) { if (buffer->IsArrayBufferView()) { - return buffer.As()->Buffer()->IsImmutable(); + return buffer.As()->GetBuffer()->IsImmutable(); } return buffer->IsArrayBuffer() && buffer.As()->IsImmutable(); } diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc index b8aa47adda4e..839b648a7a01 100644 --- a/src/crypto/crypto_util.cc +++ b/src/crypto/crypto_util.cc @@ -1093,7 +1093,7 @@ MaybeLocal ToWebCryptoJobResult(Environment* env, Local value) { } if (Buffer::HasInstance(value)) { - return value.As()->Buffer(); + return value.As()->GetBuffer(); } CHECK(value->IsBoolean() || (value->IsObject() && !value->IsArray() && diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index f39ae6feff70..c91724729a63 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -718,7 +718,7 @@ class ArrayBufferOrViewContents final { auto view = buf.As(); offset_ = view->ByteOffset(); length_ = view->ByteLength(); - data_ = view->Buffer()->Data(); + data_ = view->GetBuffer()->Data(); } else if (buf->IsArrayBuffer()) { auto ab = buf.As(); offset_ = 0; diff --git a/src/dataqueue/queue.cc b/src/dataqueue/queue.cc index 96a7956b8749..ee00523bc4a3 100644 --- a/src/dataqueue/queue.cc +++ b/src/dataqueue/queue.cc @@ -20,6 +20,8 @@ namespace node { +using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::Local; @@ -1163,13 +1165,17 @@ std::unique_ptr DataQueue::CreateInMemoryEntryFromView( // the underlying buffer, something else could modify the buffer while we're // holding the reference, which means we cannot guarantee that reads will be // idempotent. - if (!view->Buffer()->IsDetachable()) { + Local buffer = view->GetBuffer(); + if (!buffer->IsDetachable()) { return nullptr; } - auto store = view->Buffer()->GetBackingStore(); + auto store = buffer->GetBackingStore(); auto offset = view->ByteOffset(); auto length = view->ByteLength(); - USE(view->Buffer()->Detach(Local())); + // A SharedArrayBuffer is never detachable, assuming this is an ArrayBuffer + // is safe. + DCHECK(buffer->IsArrayBuffer()); + USE(buffer.As()->Detach(Local())); return CreateInMemoryEntryFromBackingStore(std::move(store), offset, length); } diff --git a/src/encoding_binding.cc b/src/encoding_binding.cc index 5b8f8f0bcdc2..72fbaf21dab3 100644 --- a/src/encoding_binding.cc +++ b/src/encoding_binding.cc @@ -15,6 +15,7 @@ namespace node { namespace encoding_binding { using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::BackingStore; using v8::BackingStoreInitializationMode; using v8::BackingStoreOnFailureMode; @@ -197,7 +198,7 @@ void BindingData::EncodeInto(const FunctionCallbackInfo& args) { Local source = args[0].As(); Local dest = args[1].As(); - Local buf = dest->Buffer(); + Local buf = dest->GetBuffer(); // Handle detached buffers - return {read: 0, written: 0} if (buf->Data() == nullptr) { @@ -425,7 +426,7 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo& args) { if (args[0]->IsArrayBufferView()) { Local view = args[0].As(); - isShared = view->Buffer()->IsSharedArrayBuffer(); + isShared = view->GetBuffer()->IsSharedArrayBuffer(); } ArrayBufferViewContents buffer(args[0]); diff --git a/src/ffi/data.cc b/src/ffi/data.cc index ca3315d43a35..cf729414b748 100644 --- a/src/ffi/data.cc +++ b/src/ffi/data.cc @@ -793,7 +793,7 @@ void GetRawPointer(const FunctionCallbackInfo& args) { store = args[0].As()->GetBackingStore(); } else if (args[0]->IsArrayBufferView()) { Local view = args[0].As(); - if (view->Buffer()->WasDetached()) { + if (view->GetBuffer()->WasDetached()) { THROW_ERR_INVALID_ARG_VALUE( env, "ArrayBufferView is backed by a detached ArrayBuffer"); return; @@ -801,7 +801,7 @@ void GetRawPointer(const FunctionCallbackInfo& args) { // Access the store here to ensure that it exists. Small typed arrays // may not have a store until this point and can instead be stored // entirely in-heap. - store = view->Buffer()->GetBackingStore(); + store = view->GetBuffer()->GetBackingStore(); offset = view->ByteOffset(); } else { THROW_ERR_INVALID_ARG_TYPE( diff --git a/src/ffi/fast.cc b/src/ffi/fast.cc index aaba55e07ba6..f7d829a9c2a6 100644 --- a/src/ffi/fast.cc +++ b/src/ffi/fast.cc @@ -125,7 +125,7 @@ uintptr_t PointerFromValue(v8::Local value) { // ArrayBuffer and SharedArrayBuffer point at the start of their store. if (value->IsArrayBufferView()) { v8::Local view = value.As(); - void* data = view->Buffer()->Data(); + void* data = view->GetBuffer()->Data(); return reinterpret_cast(static_cast(data) + view->ByteOffset()); } @@ -259,7 +259,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local value, // lifetimes match the generic path. if (value->IsArrayBufferView()) { v8::Local view = value.As(); - if (view->Buffer()->WasDetached()) { + if (view->GetBuffer()->WasDetached()) { THROW_ERR_INVALID_ARG_VALUE( isolate, "Argument %u is an ArrayBufferView backed by a detached " diff --git a/src/ffi/types.cc b/src/ffi/types.cc index 971ca8b6adbb..89adf93c24ea 100644 --- a/src/ffi/types.cc +++ b/src/ffi/types.cc @@ -717,7 +717,7 @@ Maybe ToFFIArgument(Environment* env, // invalidating that backing store during the active FFI call is // unsupported and dangerous. Local view = arg.As(); - if (view->Buffer()->WasDetached()) { + if (view->GetBuffer()->WasDetached()) { THROW_ERR_INVALID_ARG_VALUE( env, "Argument %u is an ArrayBufferView backed by a detached " @@ -725,7 +725,8 @@ Maybe ToFFIArgument(Environment* env, index); return {}; } - std::shared_ptr store = view->Buffer()->GetBackingStore(); + std::shared_ptr store = + view->GetBuffer()->GetBackingStore(); if (!store) { THROW_ERR_INVALID_ARG_VALUE( diff --git a/src/heap_utils.cc b/src/heap_utils.cc index 72c1a73aa6c0..fa9a9463d7e6 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -429,7 +429,7 @@ HeapProfiler::HeapSnapshotOptions GetHeapSnapshotOptions( CHECK(options_value->IsUint8Array()); Local arr = options_value.As(); uint8_t* options = - static_cast(arr->Buffer()->Data()) + arr->ByteOffset(); + static_cast(arr->GetBuffer()->Data()) + arr->ByteOffset(); HeapProfiler::HeapSnapshotOptions result; result.snapshot_mode = options[0] ? HeapProfiler::HeapSnapshotMode::kExposeInternals diff --git a/src/histogram.cc b/src/histogram.cc index 2b91bb7f6a6f..72afcee99a63 100644 --- a/src/histogram.cc +++ b/src/histogram.cc @@ -3122,7 +3122,7 @@ void HistogramImpl::GetQrde(const FunctionCallbackInfo& args) { Local input = args[0].As(); CHECK_GE(input->Length(), 2); CHECK_LE(input->Length(), 1001); - auto backing = input->Buffer()->GetBackingStore(); + auto backing = input->GetBuffer()->GetBackingStore(); const double* data = reinterpret_cast( static_cast(backing->Data()) + input->ByteOffset()); std::vector probabilities(data, data + input->Length()); @@ -3206,7 +3206,7 @@ void HistogramImpl::DoImport(const FunctionCallbackInfo& args) { return; } Local input = args[0].As(); - auto backing = input->Buffer()->GetBackingStore(); + auto backing = input->GetBuffer()->GetBackingStore(); const uint8_t* data = static_cast(backing->Data()) + input->ByteOffset(); size_t len = input->ByteLength(); @@ -3279,7 +3279,7 @@ void HistogramImpl::GetPercentilesAt(const FunctionCallbackInfo& args) { CHECK(args[1]->IsFloat64Array()); Local input = args[1].As(); size_t length = input->Length(); - auto backing = input->Buffer()->GetBackingStore(); + auto backing = input->GetBuffer()->GetBackingStore(); double* percentiles = reinterpret_cast( static_cast(backing->Data()) + input->ByteOffset()); diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 863b0f9e3ae1..bb9cd0c6d1bf 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -3394,11 +3394,11 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env, *length = array->Length(); } - v8::Local buffer; + v8::Local buffer; if (data != nullptr || arraybuffer != nullptr) { - // Calling Buffer() may have the side effect of allocating the buffer, + // Calling GetBuffer() may have the side effect of allocating the buffer, // so only do this when it’s needed. - buffer = array->Buffer(); + buffer = array->GetBuffer(); } if (data != nullptr) { @@ -3483,11 +3483,11 @@ napi_status NAPI_CDECL napi_get_dataview_info(napi_env env, *byte_length = array->ByteLength(); } - v8::Local buffer; + v8::Local buffer; if (data != nullptr || arraybuffer != nullptr) { - // Calling Buffer() may have the side effect of allocating the buffer, + // Calling GetBuffer() may have the side effect of allocating the buffer, // so only do this when it’s needed. - buffer = array->Buffer(); + buffer = array->GetBuffer(); } if (data != nullptr) { diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 4b881209c39f..96c83f37f577 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -359,7 +359,7 @@ void ModuleWrap::New(const FunctionCallbackInfo& args) { CHECK(!can_use_builtin_cache); // We don't use this option internally. Local cached_data_buf = args[5].As(); uint8_t* data = - static_cast(cached_data_buf->Buffer()->Data()); + static_cast(cached_data_buf->GetBuffer()->Data()); user_cached_data = new ScriptCompiler::CachedData(data + cached_data_buf->ByteOffset(), cached_data_buf->ByteLength()); diff --git a/src/node_blob.cc b/src/node_blob.cc index bdc10ab2ad79..64c8a6668a10 100644 --- a/src/node_blob.cc +++ b/src/node_blob.cc @@ -19,6 +19,7 @@ namespace node { using v8::Array; using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::BackingStoreInitializationMode; @@ -77,7 +78,7 @@ void Concat(const FunctionCallbackInfo& args) { } else { CHECK(val->IsArrayBufferView()); auto view = val.As(); - views.push_back(View{view->Buffer()->GetBackingStore(), + views.push_back(View{view->GetBuffer()->GetBackingStore(), view->ByteLength(), view->ByteOffset()}); total += view->ByteLength(); @@ -206,13 +207,16 @@ void Blob::New(const FunctionCallbackInfo& args) { Local entry = sources[i].Get(isolate); auto entryFromArrayBuffer = - [isolate](Local buf, + [isolate](Local buf, size_t byte_length, size_t byte_offset = 0) mutable -> std::unique_ptr { if (buf->IsDetachable()) { std::shared_ptr store = buf->GetBackingStore(); - if (buf->Detach(Local()).IsNothing()) { + // A SharedArrayBuffer is never detachable, assuming this is an + // ArrayBuffer is safe. + DCHECK(buf->IsArrayBuffer()); + if (buf.As()->Detach(Local()).IsNothing()) { return nullptr; } return DataQueue::CreateInMemoryEntryFromBackingStore( @@ -245,7 +249,7 @@ void Blob::New(const FunctionCallbackInfo& args) { } else if (entry->IsArrayBufferView()) { Local view = entry.As(); auto ret = entryFromArrayBuffer( - view->Buffer(), view->ByteLength(), view->ByteOffset()); + view->GetBuffer(), view->ByteLength(), view->ByteOffset()); if (!ret) return; entries[i] = std::move(ret); } else if (Blob::HasInstance(env, entry)) { diff --git a/src/node_buffer.cc b/src/node_buffer.cc index e7accbbe8d3f..ecc1363a528a 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -56,6 +56,7 @@ namespace node { namespace Buffer { using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::BackingStoreInitializationMode; @@ -257,7 +258,7 @@ bool HasInstance(Local obj) { char* Data(Local val) { CHECK(val->IsArrayBufferView()); Local ui = val.As(); - return static_cast(ui->Buffer()->Data()) + ui->ByteOffset(); + return static_cast(ui->GetBuffer()->Data()) + ui->ByteOffset(); } @@ -281,7 +282,7 @@ size_t Length(Local obj) { MaybeLocal New(Environment* env, - Local ab, + Local ab, size_t byte_offset, size_t length) { CHECK(!env->buffer_prototype_object().IsEmpty()); @@ -584,7 +585,7 @@ void StringSlice(const FunctionCallbackInfo& args) { size_t length = end - start; std::unique_ptr data_copy; - if (view->Buffer()->IsSharedArrayBuffer()) { + if (view->GetBuffer()->IsSharedArrayBuffer()) { data_copy = std::make_unique_for_overwrite(length); memcpy(data_copy.get(), data_ptr + start, length); data_ptr = data_copy.get(); @@ -609,8 +610,8 @@ size_t CopyImpl(Local source_obj, Local source = source_obj.As(); Local target = target_obj.As(); - Local source_ab = source->Buffer(); - Local target_ab = target->Buffer(); + Local source_ab = source->GetBuffer(); + Local target_ab = target->GetBuffer(); const size_t source_offset = source->ByteOffset() + source_start; const size_t target_offset = target->ByteOffset() + target_start; @@ -1502,7 +1503,7 @@ static bool MaskArgs(Local source_obj, uint32_t mask) { CHECK(destination_obj->IsArrayBufferView()); Local destination = destination_obj.As(); - Local destination_ab = destination->Buffer(); + Local destination_ab = destination->GetBuffer(); if (destination_ab->IsImmutable()) return false; if (length == 0) return true; const size_t destination_length = destination->ByteLength(); diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 989ce5d6750c..fc5891cf30d8 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -1025,7 +1025,7 @@ void ContextifyScript::New(const FunctionCallbackInfo& args) { ScriptCompiler::CachedData* cached_data = nullptr; if (!cached_data_buf.IsEmpty()) { - uint8_t* data = static_cast(cached_data_buf->Buffer()->Data()); + uint8_t* data = static_cast(cached_data_buf->GetBuffer()->Data()); cached_data = new ScriptCompiler::CachedData( data + cached_data_buf->ByteOffset(), cached_data_buf->ByteLength()); } @@ -1436,7 +1436,7 @@ void ContextifyFunction::CompileFunction( // Read cache from cached data buffer ScriptCompiler::CachedData* cached_data = nullptr; if (!cached_data_buf.IsEmpty()) { - uint8_t* data = static_cast(cached_data_buf->Buffer()->Data()); + uint8_t* data = static_cast(cached_data_buf->GetBuffer()->Data()); cached_data = new ScriptCompiler::CachedData( data + cached_data_buf->ByteOffset(), cached_data_buf->ByteLength()); } diff --git a/src/node_file.cc b/src/node_file.cc index e4db8be02321..44cc0f0ebcc4 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3960,7 +3960,7 @@ class WriteFileJob final : public AsyncWrap, public ThreadPoolWork { // detached or collected meanwhile; a resizable buffer can still have its // pages decommitted by a shrink, so its contents are copied instead. length_ = view->ByteLength(); - backing_store_ = view->Buffer()->GetBackingStore(); + backing_store_ = view->GetBuffer()->GetBackingStore(); if (backing_store_->IsResizableByUserJavaScript()) { copy_.reset(new char[length_]); memcpy(copy_.get(), diff --git a/src/node_internals.h b/src/node_internals.h index 282c5fb533cf..5b08da7831b9 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -190,9 +190,9 @@ v8::MaybeLocal New(Environment* env, v8::MaybeLocal New(Environment* env, char* data, size_t length); -// Creates a Buffer instance over an existing ArrayBuffer. +// Creates a Buffer instance over an existing ArrayBuffer or SharedArrayBuffer. v8::MaybeLocal New(Environment* env, - v8::Local ab, + v8::Local ab, size_t byte_offset, size_t length); // Construct a Buffer from a MaybeStackBuffer (and also its subclasses like diff --git a/src/node_ipc_serdes.cc b/src/node_ipc_serdes.cc index 05d5ae7ccffe..7d444814d8ca 100644 --- a/src/node_ipc_serdes.cc +++ b/src/node_ipc_serdes.cc @@ -20,6 +20,7 @@ namespace node { using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::BigInt64Array; @@ -103,7 +104,7 @@ static size_t BytesPerElement(uint32_t type_index) { static MaybeLocal MakeView(Environment* env, uint32_t type_index, - Local ab, + Local ab, size_t byte_offset, size_t byte_length) { const size_t length = byte_length / BytesPerElement(type_index); @@ -240,7 +241,7 @@ class IPCSerializerDelegate : public ValueSerializer::Delegate { class IPCDeserializerDelegate : public ValueDeserializer::Delegate { public: - IPCDeserializerDelegate(Environment* env, Local ab) + IPCDeserializerDelegate(Environment* env, Local ab) : env_(env), ab_(ab) {} void set_deserializer(ValueDeserializer* deserializer) { @@ -298,7 +299,7 @@ class IPCDeserializerDelegate : public ValueDeserializer::Delegate { private: Environment* env_; - Local ab_; + Local ab_; ValueDeserializer* deserializer_ = nullptr; }; @@ -346,7 +347,7 @@ static void Deserialize(const FunctionCallbackInfo& args) { CHECK(args[0]->IsArrayBufferView()); Local view = args[0].As(); - Local ab = view->Buffer(); + Local ab = view->GetBuffer(); const size_t byte_offset = view->ByteOffset(); const size_t byte_length = view->ByteLength(); const uint8_t* data = static_cast(ab->Data()) + byte_offset; diff --git a/src/node_os.cc b/src/node_os.cc index 4c7ebde4644f..ff73f7edecfa 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -40,7 +40,7 @@ namespace node { namespace os { using v8::Array; -using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::Boolean; using v8::Context; using v8::Float64Array; @@ -186,7 +186,7 @@ static void GetLoadAvg(const FunctionCallbackInfo& args) { CHECK(args[0]->IsFloat64Array()); Local array = args[0].As(); CHECK_EQ(array->Length(), 3); - Local ab = array->Buffer(); + Local ab = array->GetBuffer(); double* loadavg = static_cast(ab->Data()); uv_loadavg(loadavg); } diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 2db5e3678b52..7b915305f6af 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -40,7 +40,7 @@ typedef int mode_t; namespace node { using v8::Array; -using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::CFunction; using v8::Context; using v8::Float64Array; @@ -100,7 +100,7 @@ static void Chdir(const FunctionCallbackInfo& args) { } } -inline Local get_fields_array_buffer( +inline Local get_fields_array_buffer( const FunctionCallbackInfo& args, size_t index, size_t array_length) { @@ -108,7 +108,7 @@ inline Local get_fields_array_buffer( Local arr = args[index].As(); CHECK_EQ(arr->Length(), array_length); CHECK_EQ(arr->ByteOffset(), 0); - return arr->Buffer(); + return arr->GetBuffer(); } // CPUUsage use libuv's uv_getrusage() this-process resource usage accessor, @@ -126,7 +126,7 @@ static void CPUUsage(const FunctionCallbackInfo& args) { return env->ThrowUVException(err, "uv_getrusage"); // Get the double array pointer from the Float64Array argument. - Local ab = get_fields_array_buffer(args, 0, 2); + Local ab = get_fields_array_buffer(args, 0, 2); double* fields = static_cast(ab->Data()); // Set the Float64Array elements to be user / system values in microseconds. @@ -149,7 +149,7 @@ static void ThreadCPUUsage(const FunctionCallbackInfo& args) { if (err) return env->ThrowUVException(err, "uv_getrusage_thread"); // Get the double array pointer from the Float64Array argument. - Local ab = get_fields_array_buffer(args, 0, 2); + Local ab = get_fields_array_buffer(args, 0, 2); double* fields = static_cast(ab->Data()); // Set the Float64Array elements to be user / system values in microseconds. @@ -231,7 +231,7 @@ static void MemoryUsage(const FunctionCallbackInfo& args) { env->isolate_data()->node_allocator(); // Get the double array pointer from the Float64Array argument. - Local ab = get_fields_array_buffer(args, 0, 5); + Local ab = get_fields_array_buffer(args, 0, 5); double* fields = static_cast(ab->Data()); size_t rss; @@ -370,7 +370,7 @@ static void ResourceUsage(const FunctionCallbackInfo& args) { if (err) return env->ThrowUVException(err, "uv_getrusage"); - Local ab = get_fields_array_buffer(args, 0, 16); + Local ab = get_fields_array_buffer(args, 0, 16); double* fields = static_cast(ab->Data()); fields[0] = MICROS_PER_SEC * rusage.ru_utime.tv_sec + rusage.ru_utime.tv_usec; diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 2f4050cb8c16..c297b64d3cdf 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -1891,7 +1891,7 @@ std::optional ValidateDatabasePath(Environment* env, size_t byteOffset = buffer->ByteOffset(); size_t byteLength = buffer->ByteLength(); auto data = - static_cast(buffer->Buffer()->Data()) + byteOffset; + static_cast(buffer->GetBuffer()->Data()) + byteOffset; if (std::find(data, data + byteLength, 0) == data + byteLength) { return std::string(reinterpret_cast(data), byteLength); } diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 844221b88983..daa85ef9af31 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -27,7 +27,7 @@ inline void Debug(const WASI& wasi, Args&&... args) { } while (0) using v8::Array; -using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::BigInt; using v8::CFunction; using v8::Context; @@ -282,7 +282,7 @@ R WASI::WasiFunction::FastCallback( THROW_ERR_WASI_NOT_STARTED(isolate); return EinvalError(); } - Local ab = wasi->memory_.Get(isolate)->Buffer(); + Local ab = wasi->memory_.Get(isolate)->GetBuffer(); size_t mem_size = ab->ByteLength(); char* mem_data = static_cast(ab->Data()); CHECK_NOT_NULL(mem_data); @@ -408,7 +408,7 @@ void WASI::WasiFunction::SlowCallback( } Local memory = PersistentToLocal::Strong(wasi->memory_); - Local ab = memory->Buffer(); + Local ab = memory->GetBuffer(); size_t mem_size = ab->ByteLength(); char* mem_data = static_cast(ab->Data()); CHECK_NOT_NULL(mem_data); diff --git a/src/node_wasm_web_api.cc b/src/node_wasm_web_api.cc index d977793eb136..e372849e57fa 100644 --- a/src/node_wasm_web_api.cc +++ b/src/node_wasm_web_api.cc @@ -107,7 +107,7 @@ void WasmStreamingObject::Push(const FunctionCallbackInfo& args) { if (chunk->IsArrayBufferView()) [[likely]] { Local view = chunk.As(); - bytes = view->Buffer()->Data(); + bytes = view->GetBuffer()->Data(); offset = view->ByteOffset(); size = view->ByteLength(); } else if (chunk->IsArrayBuffer()) [[likely]] { diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 72947b8b7839..cce6997be2f4 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -58,7 +58,7 @@ namespace node { -using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::CFunction; using v8::Context; using v8::Function; @@ -836,7 +836,7 @@ class ZlibStream final : public CompressionStream { CHECK(args[4]->IsUint32Array()); Local array = args[4].As(); CHECK_GE(array->Length(), 2); - Local ab = array->Buffer(); + Local ab = array->GetBuffer(); uint32_t* write_result = static_cast(ab->Data()); CHECK(args[5]->IsFunction()); diff --git a/src/quic/data.cc b/src/quic/data.cc index 0de12774516a..b080e52d08be 100644 --- a/src/quic/data.cc +++ b/src/quic/data.cc @@ -130,7 +130,7 @@ Maybe Store::From(Local view) { } if (length > 0) { memcpy(dest->Data(), - static_cast(view->Buffer()->Data()) + offset, + static_cast(view->GetBuffer()->Data()) + offset, length); } return Just(Store(std::move(dest), length, 0)); @@ -156,7 +156,7 @@ Store Store::CopyFrom(Local buffer) { Store Store::CopyFrom(Local view) { Isolate* isolate = Isolate::GetCurrent(); - auto backing = view->Buffer()->GetBackingStore(); + auto backing = view->GetBuffer()->GetBackingStore(); auto length = view->ByteLength(); auto offset = view->ByteOffset(); auto dest = ArrayBuffer::NewBackingStore( diff --git a/src/quic/streams.cc b/src/quic/streams.cc index f29bab507a40..1951a7d3e1e3 100644 --- a/src/quic/streams.cc +++ b/src/quic/streams.cc @@ -20,6 +20,7 @@ namespace node { using v8::Array; using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::BackingStoreInitializationMode; @@ -278,7 +279,10 @@ namespace { // QUIC API. // Returns nullptr on zero length or allocation failure. std::unique_ptr CreateEntryFromBuffer( - Environment* env, Local buffer, size_t offset, size_t length) { + Environment* env, + Local buffer, + size_t offset, + size_t length) { if (length == 0) return nullptr; JS_TRY_ALLOCATE_BACKING_OR_RETURN(env, copy, length, nullptr); memcpy(copy->Data(), @@ -329,7 +333,8 @@ Maybe> Stream::GetDataQueueFromSource( auto offset = view->ByteOffset(); auto length = view->ByteLength(); if (length > 0) { - auto entry = CreateEntryFromBuffer(env, view->Buffer(), offset, length); + auto entry = + CreateEntryFromBuffer(env, view->GetBuffer(), offset, length); if (!entry) { return Nothing>(); } @@ -1368,8 +1373,8 @@ void Stream::WriteStreamData(const FunctionCallbackInfo& args) { auto view = value.As(); auto length = view->ByteLength(); if (length == 0) return true; - auto entry = - CreateEntryFromBuffer(env, view->Buffer(), view->ByteOffset(), length); + auto entry = CreateEntryFromBuffer( + env, view->GetBuffer(), view->ByteOffset(), length); if (!entry) { return false; } diff --git a/src/stream_base.cc b/src/stream_base.cc index fb16da9b5a9f..e5ce7a587cbf 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -805,7 +805,7 @@ void CustomBufferJSListener::SetBuffer(Local object, Local view) { // Keep the view's lifetime tied to the wrapper without a strong global root. object->SetInternalField(StreamBase::kUserBufferField, view); - backing_store_ = view->Buffer()->GetBackingStore(); + backing_store_ = view->GetBuffer()->GetBackingStore(); } uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) { @@ -826,7 +826,7 @@ uv_buf_t CustomBufferJSListener::OnStreamAlloc(size_t suggested_size) { const auto contents = view->GetContents({}); // An attached empty backing store can also have a null data pointer. if (contents.data() != nullptr || (backing_store_->MaxByteLength() == 0 && - !view->Buffer()->WasDetached())) { + !view->GetBuffer()->WasDetached())) { buffer_ = uv_buf_init(reinterpret_cast(contents.data()), contents.size()); return buffer_; diff --git a/src/util-inl.h b/src/util-inl.h index cecc03be2c7d..e61e56fb31a0 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -615,10 +615,10 @@ ArrayBufferViewContents::ArrayBufferViewContents( template requires(sizeof(T) == 1) void ArrayBufferViewContents::Read(v8::Local abv) { - was_detached_ = abv->Buffer()->WasDetached(); + was_detached_ = abv->GetBuffer()->WasDetached(); length_ = abv->ByteLength(); if (length_ > sizeof(stack_storage_) || abv->HasBuffer()) { - auto buf_data = abv->Buffer()->Data(); + auto buf_data = abv->GetBuffer()->Data(); data_ = buf_data != nullptr ? static_cast(buf_data) + abv->ByteOffset() : stack_storage_; } else { diff --git a/src/util.h b/src/util.h index 6cb2d5e8900e..15dc1dcaebd7 100644 --- a/src/util.h +++ b/src/util.h @@ -695,7 +695,7 @@ class BufferValue : public MaybeStackBuffer { const size_t name##_offset = name->ByteOffset(); \ const size_t name##_length = name->ByteLength(); \ char* const name##_data = \ - static_cast(name->Buffer()->Data()) + name##_offset; \ + static_cast(name->GetBuffer()->Data()) + name##_offset; \ if (name##_length > 0) CHECK_NE(name##_data, nullptr); // Use this when a variable or parameter is unused in order to explicitly diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index 6c85f9140977..a27152c96863 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -12,7 +12,7 @@ inline void RandomBytes(const v8::FunctionCallbackInfo& info) { auto byte_offset = view->ByteOffset(); auto byte_length = view->ByteLength(); assert(view->HasBuffer()); - auto buffer = view->Buffer(); + auto buffer = view->GetBuffer(); auto contents = buffer->GetBackingStore(); auto data = static_cast(contents->Data()) + byte_offset; assert(RAND_poll()); @@ -26,7 +26,7 @@ inline void Hash(const v8::FunctionCallbackInfo& info) { auto byte_offset = view->ByteOffset(); auto len = view->ByteLength(); assert(view->HasBuffer()); - auto buffer = view->Buffer(); + auto buffer = view->GetBuffer(); auto contents = buffer->GetBackingStore(); auto data = static_cast(contents->Data()) + byte_offset; unsigned char md[MD5_DIGEST_LENGTH]; diff --git a/test/addons/zlib-binding/binding.cc b/test/addons/zlib-binding/binding.cc index 859b54564b63..3eb61422163a 100644 --- a/test/addons/zlib-binding/binding.cc +++ b/test/addons/zlib-binding/binding.cc @@ -11,7 +11,7 @@ inline void CompressBytes(const v8::FunctionCallbackInfo& info) { auto byte_offset = view->ByteOffset(); auto byte_length = view->ByteLength(); assert(view->HasBuffer()); - auto buffer = view->Buffer(); + auto buffer = view->GetBuffer(); auto contents = buffer->GetBackingStore(); auto data = static_cast(contents->Data()) + byte_offset; diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index cec49dac9169..c4b546ad9119 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -755,7 +755,7 @@ TEST_F(EnvironmentTest, BufferWithFreeCallbackIsDetached) { int callback_calls = 0; - v8::Local ab; + v8::Local ab; { Env env {handle_scope, argv}; v8::Local buf_obj = node::Buffer::New( @@ -768,7 +768,7 @@ TEST_F(EnvironmentTest, BufferWithFreeCallbackIsDetached) { }, &callback_calls).ToLocalChecked(); CHECK(buf_obj->IsUint8Array()); - ab = buf_obj.As()->Buffer(); + ab = buf_obj.As()->GetBuffer(); CHECK_EQ(ab->ByteLength(), sizeof(hello)); } diff --git a/test/cctest/test_node_ipc_serdes.cc b/test/cctest/test_node_ipc_serdes.cc index 6b2d9854a6d0..0b837bb90e3f 100644 --- a/test/cctest/test_node_ipc_serdes.cc +++ b/test/cctest/test_node_ipc_serdes.cc @@ -69,7 +69,7 @@ v8::Local RoundTrip(v8::Local context, EXPECT_EQ(payload_length, buf->ByteLength() - 4); v8::Local payload = v8::Uint8Array::New( - buf->Buffer(), buf->ByteOffset() + 4, buf->ByteLength() - 4); + buf->GetBuffer(), buf->ByteOffset() + 4, buf->ByteLength() - 4); return deserialize->Call(context, v8::Undefined(isolate), 1, &payload) .ToLocalChecked(); } From 0f70c2d2eee1851ef00e0c73f972ada318547e0f Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 23 Nov 2026 11:43:17 -0500 Subject: [PATCH 2/3] fixup! src: migrate off ArrayBufferView::Buffer() Signed-off-by: Chengzhong Wu --- src/node_buffer.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/node_buffer.cc b/src/node_buffer.cc index ecc1363a528a..6c2321d5f1b0 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -280,7 +280,6 @@ size_t Length(Local obj) { return ui->ByteLength(); } - MaybeLocal New(Environment* env, Local ab, size_t byte_offset, From 9db058a508e88c247f57ae13ee47bf2831cf68f6 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Mon, 23 Nov 2026 15:21:53 -0500 Subject: [PATCH 3/3] fixup! src: migrate off ArrayBufferView::Buffer() Signed-off-by: Chengzhong Wu --- benchmark/napi/function_args/binding.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/napi/function_args/binding.cc b/benchmark/napi/function_args/binding.cc index 5cdca8bd3578..9174c61f2c33 100644 --- a/benchmark/napi/function_args/binding.cc +++ b/benchmark/napi/function_args/binding.cc @@ -3,7 +3,7 @@ #include using v8::Array; -using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::Context; @@ -104,7 +104,7 @@ void CallWithTypedarray(const FunctionCallbackInfo& args) { const size_t byte_length = view->ByteLength(); assert(byte_length > 0); assert(view->HasBuffer()); - Local buffer = view->Buffer(); + Local buffer = view->GetBuffer(); std::shared_ptr bs = buffer->GetBackingStore(); const uint32_t* data = reinterpret_cast( static_cast(bs->Data()) + byte_offset);