diff --git a/src/aliased_buffer-inl.h b/src/aliased_buffer-inl.h index 5cb36e707ce2..ea1bcdb4e52d 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,7 @@ template requires std::is_scalar_v v8::Local AliasedBufferBase::GetArrayBuffer() const { - return GetJSArray()->Buffer(); + return GetJSArray()->GetBuffer().template As(); } template diff --git a/src/compile_cache.cc b/src/compile_cache.cc index bab24256e06e..af73c5a59d65 100644 --- a/src/compile_cache.cc +++ b/src/compile_cache.cc @@ -1,4 +1,5 @@ #include "compile_cache.h" +#include #include #include "debug_utils-inl.h" #include "env-inl.h" @@ -336,10 +337,13 @@ ScriptCompiler::CachedData* SerializeCodeCache(Local mod) { // with the baseline tier so far. ScriptCompiler::CachedData* SerializeCodeCache(Local mod) { v8::OwnedBuffer code = mod->GetCompiledModule().Serialize(); - if (code.size == 0) return nullptr; + if (code.empty()) return nullptr; + std::span span = code.as_span(); + uint8_t* buffer = new uint8_t[span.size()]; + memcpy(buffer, span.data(), span.size()); return new ScriptCompiler::CachedData( - code.buffer.release(), - static_cast(code.size), + buffer, + static_cast(span.size()), ScriptCompiler::CachedData::BufferOwned); } diff --git a/src/crypto/crypto_util.cc b/src/crypto/crypto_util.cc index 783620c1210b..6574d313a370 100644 --- a/src/crypto/crypto_util.cc +++ b/src/crypto/crypto_util.cc @@ -1105,7 +1105,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 d299bc7f55b5..12b9fff23aa7 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -705,7 +705,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..44e62077740b 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,14 @@ 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())); + 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 8a445088b54a..2b8bf2b1005a 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; @@ -206,7 +207,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) { @@ -434,7 +435,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..c55fe173cd5f 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()); } @@ -247,7 +247,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local value, constexpr uintptr_t kInvalidBuffer = std::numeric_limits::max(); // The trampoline always passes the FastApiCallbackOptions declared in the // CFunctionInfo. No HandleScope is active during a Fast API call, and both - // ArrayBufferView::Buffer() and the error paths below create handles, so + // ArrayBufferView::GetBuffer() and the error paths below create handles, so // open one for the whole helper. Otherwise every call leaks handles into // the caller's scope. v8::Isolate* isolate = options->isolate; @@ -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 5a910e63a3e3..46451f619d59 100644 --- a/src/ffi/types.cc +++ b/src/ffi/types.cc @@ -714,7 +714,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 " @@ -722,7 +722,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 6efe2d6985cc..4104ac2a16dd 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 59f80e66d69e..4c7ca3d3b402 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -3392,11 +3392,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) { @@ -3481,11 +3481,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 ae1ea3ec1bbc..c066c3400ea3 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -358,7 +358,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 ab4267fb81f0..c155c93dce94 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,13 @@ 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()) { + if (buf.As()->Detach(Local()).IsNothing()) { return nullptr; } return DataQueue::CreateInMemoryEntryFromBackingStore( @@ -245,7 +246,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 5b85ca2a9dad..cc4bd2ec30b6 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -64,6 +64,7 @@ namespace node { namespace Buffer { using v8::ArrayBuffer; +using v8::ArrayBufferBase; using v8::ArrayBufferView; using v8::BackingStore; using v8::BackingStoreInitializationMode; @@ -265,7 +266,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(); } @@ -592,7 +593,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(); @@ -617,8 +618,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; @@ -1509,7 +1510,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 e07ccecb5229..2db8f1047f93 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -1024,7 +1024,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()); } @@ -1435,7 +1435,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 1fe7891b31f3..4e8393c904cb 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -3984,7 +3984,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_ipc_serdes.cc b/src/node_ipc_serdes.cc index 05d5ae7ccffe..6a1d17ea4358 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; @@ -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) { @@ -286,8 +287,9 @@ class IPCDeserializerDelegate : public ValueDeserializer::Delegate { // Reuse the backing ArrayBuffer when the data is suitably aligned, // otherwise copy into a fresh aligned buffer. Mirrors _readHostObject() // in lib/v8.js. - if (offset_in_ab % bytes_per_element == 0) { - return MakeView(env_, type_index, ab_, offset_in_ab, byte_length); + if (ab_->IsArrayBuffer() && offset_in_ab % bytes_per_element == 0) { + return MakeView( + env_, type_index, ab_.As(), offset_in_ab, byte_length); } std::shared_ptr store = ArrayBuffer::NewBackingStore(isolate, byte_length); @@ -298,7 +300,7 @@ class IPCDeserializerDelegate : public ValueDeserializer::Delegate { private: Environment* env_; - Local ab_; + Local ab_; ValueDeserializer* deserializer_ = nullptr; }; @@ -346,7 +348,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 b002c863a1ff..4f54bc1b244c 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; @@ -194,7 +194,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 d316b8eeb0e3..2e18b4ea506b 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -42,7 +42,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; @@ -102,7 +102,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) { @@ -110,7 +110,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(); } #ifndef __Fuchsia__ @@ -129,7 +129,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. @@ -153,7 +153,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. @@ -235,7 +235,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; @@ -375,7 +375,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 2bf67b97689f..8b5fe01ac06b 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -1853,7 +1853,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_url_pattern.cc b/src/node_url_pattern.cc index 63f01d58170f..6b488d9512c3 100644 --- a/src/node_url_pattern.cc +++ b/src/node_url_pattern.cc @@ -108,13 +108,13 @@ bool URLPatternRegexProvider::regex_match(std::string_view input, .ToLocal(&local_input)) { return false; } - Local result_object; + Local result_object; if (!pattern.Get(isolate) - ->Exec(env->context(), local_input) + ->ExecV2(env->context(), local_input) .ToLocal(&result_object)) { return false; } - // RegExp::Exec returns null if there is no match. + // RegExp::ExecV2 returns null if there is no match. return !result_object->IsNull(); } @@ -129,9 +129,9 @@ URLPatternRegexProvider::regex_search(std::string_view input, .ToLocal(&local_input)) { return std::nullopt; } - Local exec_result_object; + Local exec_result_object; auto pattern = global_pattern.Get(isolate); - if (!pattern->Exec(env->context(), local_input) + if (!pattern->ExecV2(env->context(), local_input) .ToLocal(&exec_result_object) || exec_result_object->IsNull()) { return std::nullopt; 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 c87703800fd0..e9a7b3c27223 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 36867390b0f3..f36948987e65 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 0a2af12d366a..6eb8dfd85931 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; @@ -277,7 +278,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(), @@ -328,7 +332,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>(); } @@ -1364,8 +1369,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/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 38c8a94f8309..60e8a4fbf56b 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -756,7 +756,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( @@ -769,7 +769,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(); }