Skip to content

Commit 8323ce1

Browse files
joyeecheungbackes
authored andcommitted
src: migrate off deprecated V8 15.8 APIs
Migrate ArrayBufferView::Buffer() and WasmMemoryObject::Buffer() calls to GetBuffer() (returning Local<ArrayBufferBase>), RegExp::Exec() to RegExp::ExecV2(), and OwnedBuffer::buffer/size to OwnedBuffer::as_span() in preparation for advancing these V8 15.8 deprecations to V8_DEPRECATED. Refs: https://crrev.com/c/8714721 Co-Authored-By: Clemens Backes <post@clemens-backes.de> Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 4e592d4 commit 8323ce1

35 files changed

Lines changed: 104 additions & 86 deletions

‎benchmark/napi/function_args/binding.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <assert.h>
44

55
using v8::Array;
6-
using v8::ArrayBuffer;
6+
using v8::ArrayBufferBase;
77
using v8::ArrayBufferView;
88
using v8::BackingStore;
99
using v8::Context;
@@ -104,7 +104,7 @@ void CallWithTypedarray(const FunctionCallbackInfo<Value>& args) {
104104
const size_t byte_length = view->ByteLength();
105105
assert(byte_length > 0);
106106
assert(view->HasBuffer());
107-
Local<ArrayBuffer> buffer = view->Buffer();
107+
Local<ArrayBufferBase> buffer = view->GetBuffer();
108108
std::shared_ptr<BackingStore> bs = buffer->GetBackingStore();
109109
const uint32_t* data = reinterpret_cast<uint32_t*>(
110110
static_cast<uint8_t*>(bs->Data()) + byte_offset);

‎src/aliased_buffer-inl.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ inline void AliasedBufferBase<NativeT, V8T>::Deserialize(
9797
// be removed when we expand the snapshot support.
9898
DCHECK_EQ(count_, arr->Length());
9999
DCHECK_EQ(byte_offset_, arr->ByteOffset());
100-
uint8_t* raw = static_cast<uint8_t*>(arr->Buffer()->Data());
100+
uint8_t* raw = static_cast<uint8_t*>(arr->GetBuffer()->Data());
101101
buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_);
102102
js_array_.Reset(isolate_, arr);
103103
index_ = nullptr;
@@ -146,7 +146,7 @@ template <typename NativeT, typename V8T>
146146
requires std::is_scalar_v<NativeT>
147147
v8::Local<v8::ArrayBuffer> AliasedBufferBase<NativeT, V8T>::GetArrayBuffer()
148148
const {
149-
return GetJSArray()->Buffer();
149+
return GetJSArray()->GetBuffer().template As<v8::ArrayBuffer>();
150150
}
151151

152152
template <typename NativeT, typename V8T>

‎src/compile_cache.cc‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "compile_cache.h"
2+
#include <span>
23
#include <string>
34
#include "debug_utils-inl.h"
45
#include "env-inl.h"
@@ -336,10 +337,13 @@ ScriptCompiler::CachedData* SerializeCodeCache(Local<Module> mod) {
336337
// with the baseline tier so far.
337338
ScriptCompiler::CachedData* SerializeCodeCache(Local<WasmModuleObject> mod) {
338339
v8::OwnedBuffer code = mod->GetCompiledModule().Serialize();
339-
if (code.size == 0) return nullptr;
340+
if (code.empty()) return nullptr;
341+
std::span<const uint8_t> span = code.as_span();
342+
uint8_t* buffer = new uint8_t[span.size()];
343+
memcpy(buffer, span.data(), span.size());
340344
return new ScriptCompiler::CachedData(
341-
code.buffer.release(),
342-
static_cast<int>(code.size),
345+
buffer,
346+
static_cast<int>(span.size()),
343347
ScriptCompiler::CachedData::BufferOwned);
344348
}
345349

‎src/crypto/crypto_random.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace crypto {
3333
namespace {
3434
bool IsImmutableBufferSource(Local<Value> buffer) {
3535
if (buffer->IsArrayBufferView()) {
36-
return buffer.As<ArrayBufferView>()->Buffer()->IsImmutable();
36+
return buffer.As<ArrayBufferView>()->GetBuffer()->IsImmutable();
3737
}
3838
return buffer->IsArrayBuffer() && buffer.As<ArrayBuffer>()->IsImmutable();
3939
}

‎src/crypto/crypto_util.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ MaybeLocal<Value> ToWebCryptoJobResult(Environment* env, Local<Value> value) {
10941094
}
10951095

10961096
if (Buffer::HasInstance(value)) {
1097-
return value.As<ArrayBufferView>()->Buffer();
1097+
return value.As<ArrayBufferView>()->GetBuffer();
10981098
}
10991099

11001100
CHECK(value->IsBoolean() || (value->IsObject() && !value->IsArray() &&

‎src/crypto/crypto_util.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ class ArrayBufferOrViewContents final {
709709
auto view = buf.As<v8::ArrayBufferView>();
710710
offset_ = view->ByteOffset();
711711
length_ = view->ByteLength();
712-
data_ = view->Buffer()->Data();
712+
data_ = view->GetBuffer()->Data();
713713
} else if (buf->IsArrayBuffer()) {
714714
auto ab = buf.As<v8::ArrayBuffer>();
715715
offset_ = 0;

‎src/dataqueue/queue.cc‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace node {
2222

23+
using v8::ArrayBuffer;
24+
using v8::ArrayBufferBase;
2325
using v8::ArrayBufferView;
2426
using v8::BackingStore;
2527
using v8::Local;
@@ -1163,13 +1165,14 @@ std::unique_ptr<DataQueue::Entry> DataQueue::CreateInMemoryEntryFromView(
11631165
// the underlying buffer, something else could modify the buffer while we're
11641166
// holding the reference, which means we cannot guarantee that reads will be
11651167
// idempotent.
1166-
if (!view->Buffer()->IsDetachable()) {
1168+
Local<ArrayBufferBase> buffer = view->GetBuffer();
1169+
if (!buffer->IsDetachable()) {
11671170
return nullptr;
11681171
}
1169-
auto store = view->Buffer()->GetBackingStore();
1172+
auto store = buffer->GetBackingStore();
11701173
auto offset = view->ByteOffset();
11711174
auto length = view->ByteLength();
1172-
USE(view->Buffer()->Detach(Local<Value>()));
1175+
USE(buffer.As<ArrayBuffer>()->Detach(Local<Value>()));
11731176
return CreateInMemoryEntryFromBackingStore(std::move(store), offset, length);
11741177
}
11751178

‎src/encoding_binding.cc‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace node {
1515
namespace encoding_binding {
1616

1717
using v8::ArrayBuffer;
18+
using v8::ArrayBufferBase;
1819
using v8::BackingStore;
1920
using v8::BackingStoreInitializationMode;
2021
using v8::BackingStoreOnFailureMode;
@@ -197,7 +198,7 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) {
197198
Local<String> source = args[0].As<String>();
198199

199200
Local<Uint8Array> dest = args[1].As<Uint8Array>();
200-
Local<ArrayBuffer> buf = dest->Buffer();
201+
Local<ArrayBufferBase> buf = dest->GetBuffer();
201202

202203
// Handle detached buffers - return {read: 0, written: 0}
203204
if (buf->Data() == nullptr) {
@@ -425,7 +426,7 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {
425426

426427
if (args[0]->IsArrayBufferView()) {
427428
Local<v8::ArrayBufferView> view = args[0].As<v8::ArrayBufferView>();
428-
isShared = view->Buffer()->IsSharedArrayBuffer();
429+
isShared = view->GetBuffer()->IsSharedArrayBuffer();
429430
}
430431

431432
ArrayBufferViewContents<char> buffer(args[0]);

‎src/ffi/data.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,15 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) {
793793
store = args[0].As<SharedArrayBuffer>()->GetBackingStore();
794794
} else if (args[0]->IsArrayBufferView()) {
795795
Local<ArrayBufferView> view = args[0].As<ArrayBufferView>();
796-
if (view->Buffer()->WasDetached()) {
796+
if (view->GetBuffer()->WasDetached()) {
797797
THROW_ERR_INVALID_ARG_VALUE(
798798
env, "ArrayBufferView is backed by a detached ArrayBuffer");
799799
return;
800800
}
801801
// Access the store here to ensure that it exists. Small typed arrays
802802
// may not have a store until this point and can instead be stored
803803
// entirely in-heap.
804-
store = view->Buffer()->GetBackingStore();
804+
store = view->GetBuffer()->GetBackingStore();
805805
offset = view->ByteOffset();
806806
} else {
807807
THROW_ERR_INVALID_ARG_TYPE(

‎src/ffi/fast.cc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ uintptr_t PointerFromValue(v8::Local<v8::Value> value) {
125125
// ArrayBuffer and SharedArrayBuffer point at the start of their store.
126126
if (value->IsArrayBufferView()) {
127127
v8::Local<v8::ArrayBufferView> view = value.As<v8::ArrayBufferView>();
128-
void* data = view->Buffer()->Data();
128+
void* data = view->GetBuffer()->Data();
129129
return reinterpret_cast<uintptr_t>(static_cast<char*>(data) +
130130
view->ByteOffset());
131131
}
@@ -247,7 +247,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
247247
constexpr uintptr_t kInvalidBuffer = std::numeric_limits<uintptr_t>::max();
248248
// The trampoline always passes the FastApiCallbackOptions declared in the
249249
// CFunctionInfo. No HandleScope is active during a Fast API call, and both
250-
// ArrayBufferView::Buffer() and the error paths below create handles, so
250+
// ArrayBufferView::GetBuffer() and the error paths below create handles, so
251251
// open one for the whole helper. Otherwise every call leaks handles into
252252
// the caller's scope.
253253
v8::Isolate* isolate = options->isolate;
@@ -259,7 +259,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
259259
// lifetimes match the generic path.
260260
if (value->IsArrayBufferView()) {
261261
v8::Local<v8::ArrayBufferView> view = value.As<v8::ArrayBufferView>();
262-
if (view->Buffer()->WasDetached()) {
262+
if (view->GetBuffer()->WasDetached()) {
263263
THROW_ERR_INVALID_ARG_VALUE(
264264
isolate,
265265
"Argument %u is an ArrayBufferView backed by a detached "

0 commit comments

Comments
 (0)