Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/aliased_buffer-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ inline void AliasedBufferBase<NativeT, V8T>::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<uint8_t*>(arr->Buffer()->Data());
uint8_t* raw = static_cast<uint8_t*>(arr->GetBuffer()->Data());
buffer_ = reinterpret_cast<NativeT*>(raw + byte_offset_);
js_array_.Reset(isolate_, arr);
index_ = nullptr;
Expand Down Expand Up @@ -146,7 +146,7 @@ template <typename NativeT, typename V8T>
requires std::is_scalar_v<NativeT>
v8::Local<v8::ArrayBuffer> AliasedBufferBase<NativeT, V8T>::GetArrayBuffer()
const {
return GetJSArray()->Buffer();
return GetJSArray()->GetBuffer().template As<v8::ArrayBuffer>();
}

template <typename NativeT, typename V8T>
Expand Down
10 changes: 7 additions & 3 deletions src/compile_cache.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "compile_cache.h"
#include <span>
#include <string>
#include "debug_utils-inl.h"
#include "env-inl.h"
Expand Down Expand Up @@ -336,10 +337,13 @@ ScriptCompiler::CachedData* SerializeCodeCache(Local<Module> mod) {
// with the baseline tier so far.
ScriptCompiler::CachedData* SerializeCodeCache(Local<WasmModuleObject> mod) {
v8::OwnedBuffer code = mod->GetCompiledModule().Serialize();
if (code.size == 0) return nullptr;
if (code.empty()) return nullptr;
std::span<const uint8_t> 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<int>(code.size),
buffer,
static_cast<int>(span.size()),
ScriptCompiler::CachedData::BufferOwned);
}

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ MaybeLocal<Value> ToWebCryptoJobResult(Environment* env, Local<Value> value) {
}

if (Buffer::HasInstance(value)) {
return value.As<ArrayBufferView>()->Buffer();
return value.As<ArrayBufferView>()->GetBuffer();
}

CHECK(value->IsBoolean() || (value->IsObject() && !value->IsArray() &&
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/crypto_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ class ArrayBufferOrViewContents final {
auto view = buf.As<v8::ArrayBufferView>();
offset_ = view->ByteOffset();
length_ = view->ByteLength();
data_ = view->Buffer()->Data();
data_ = view->GetBuffer()->Data();
} else if (buf->IsArrayBuffer()) {
auto ab = buf.As<v8::ArrayBuffer>();
offset_ = 0;
Expand Down
9 changes: 6 additions & 3 deletions src/dataqueue/queue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace node {

using v8::ArrayBuffer;
using v8::ArrayBufferBase;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::Local;
Expand Down Expand Up @@ -1163,13 +1165,14 @@ std::unique_ptr<DataQueue::Entry> 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<ArrayBufferBase> 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<Value>()));
USE(buffer.As<ArrayBuffer>()->Detach(Local<Value>()));
return CreateInMemoryEntryFromBackingStore(std::move(store), offset, length);
}

Expand Down
5 changes: 3 additions & 2 deletions src/encoding_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace node {
namespace encoding_binding {

using v8::ArrayBuffer;
using v8::ArrayBufferBase;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::BackingStoreOnFailureMode;
Expand Down Expand Up @@ -206,7 +207,7 @@ void BindingData::EncodeInto(const FunctionCallbackInfo<Value>& args) {
Local<String> source = args[0].As<String>();

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

// Handle detached buffers - return {read: 0, written: 0}
if (buf->Data() == nullptr) {
Expand Down Expand Up @@ -434,7 +435,7 @@ void BindingData::DecodeUTF8(const FunctionCallbackInfo<Value>& args) {

if (args[0]->IsArrayBufferView()) {
Local<v8::ArrayBufferView> view = args[0].As<v8::ArrayBufferView>();
isShared = view->Buffer()->IsSharedArrayBuffer();
isShared = view->GetBuffer()->IsSharedArrayBuffer();
}

ArrayBufferViewContents<char> buffer(args[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/ffi/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -793,15 +793,15 @@ void GetRawPointer(const FunctionCallbackInfo<Value>& args) {
store = args[0].As<SharedArrayBuffer>()->GetBackingStore();
} else if (args[0]->IsArrayBufferView()) {
Local<ArrayBufferView> view = args[0].As<ArrayBufferView>();
if (view->Buffer()->WasDetached()) {
if (view->GetBuffer()->WasDetached()) {
THROW_ERR_INVALID_ARG_VALUE(
env, "ArrayBufferView is backed by a detached ArrayBuffer");
return;
}
// 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(
Expand Down
6 changes: 3 additions & 3 deletions src/ffi/fast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ uintptr_t PointerFromValue(v8::Local<v8::Value> value) {
// ArrayBuffer and SharedArrayBuffer point at the start of their store.
if (value->IsArrayBufferView()) {
v8::Local<v8::ArrayBufferView> view = value.As<v8::ArrayBufferView>();
void* data = view->Buffer()->Data();
void* data = view->GetBuffer()->Data();
return reinterpret_cast<uintptr_t>(static_cast<char*>(data) +
view->ByteOffset());
}
Expand Down Expand Up @@ -247,7 +247,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
constexpr uintptr_t kInvalidBuffer = std::numeric_limits<uintptr_t>::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;
Expand All @@ -259,7 +259,7 @@ extern "C" uintptr_t node_ffi_fast_buffer_data(v8::Local<v8::Value> value,
// lifetimes match the generic path.
if (value->IsArrayBufferView()) {
v8::Local<v8::ArrayBufferView> view = value.As<v8::ArrayBufferView>();
if (view->Buffer()->WasDetached()) {
if (view->GetBuffer()->WasDetached()) {
THROW_ERR_INVALID_ARG_VALUE(
isolate,
"Argument %u is an ArrayBufferView backed by a detached "
Expand Down
5 changes: 3 additions & 2 deletions src/ffi/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,16 @@ Maybe<FFIArgumentCategory> ToFFIArgument(Environment* env,
// invalidating that backing store during the active FFI call is
// unsupported and dangerous.
Local<ArrayBufferView> view = arg.As<ArrayBufferView>();
if (view->Buffer()->WasDetached()) {
if (view->GetBuffer()->WasDetached()) {
THROW_ERR_INVALID_ARG_VALUE(
env,
"Argument %u is an ArrayBufferView backed by a detached "
"ArrayBuffer",
index);
return {};
}
std::shared_ptr<BackingStore> store = view->Buffer()->GetBackingStore();
std::shared_ptr<BackingStore> store =
view->GetBuffer()->GetBackingStore();

if (!store) {
THROW_ERR_INVALID_ARG_VALUE(
Expand Down
2 changes: 1 addition & 1 deletion src/heap_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ HeapProfiler::HeapSnapshotOptions GetHeapSnapshotOptions(
CHECK(options_value->IsUint8Array());
Local<Uint8Array> arr = options_value.As<Uint8Array>();
uint8_t* options =
static_cast<uint8_t*>(arr->Buffer()->Data()) + arr->ByteOffset();
static_cast<uint8_t*>(arr->GetBuffer()->Data()) + arr->ByteOffset();
HeapProfiler::HeapSnapshotOptions result;
result.snapshot_mode = options[0]
? HeapProfiler::HeapSnapshotMode::kExposeInternals
Expand Down
6 changes: 3 additions & 3 deletions src/histogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3122,7 +3122,7 @@ void HistogramImpl::GetQrde(const FunctionCallbackInfo<Value>& args) {
Local<Float64Array> input = args[0].As<Float64Array>();
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<const double*>(
static_cast<const char*>(backing->Data()) + input->ByteOffset());
std::vector<double> probabilities(data, data + input->Length());
Expand Down Expand Up @@ -3206,7 +3206,7 @@ void HistogramImpl::DoImport(const FunctionCallbackInfo<Value>& args) {
return;
}
Local<Uint8Array> input = args[0].As<Uint8Array>();
auto backing = input->Buffer()->GetBackingStore();
auto backing = input->GetBuffer()->GetBackingStore();
const uint8_t* data =
static_cast<const uint8_t*>(backing->Data()) + input->ByteOffset();
size_t len = input->ByteLength();
Expand Down Expand Up @@ -3279,7 +3279,7 @@ void HistogramImpl::GetPercentilesAt(const FunctionCallbackInfo<Value>& args) {
CHECK(args[1]->IsFloat64Array());
Local<Float64Array> input = args[1].As<Float64Array>();
size_t length = input->Length();
auto backing = input->Buffer()->GetBackingStore();
auto backing = input->GetBuffer()->GetBackingStore();
double* percentiles = reinterpret_cast<double*>(
static_cast<char*>(backing->Data()) + input->ByteOffset());

Expand Down
12 changes: 6 additions & 6 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3392,11 +3392,11 @@ napi_status NAPI_CDECL napi_get_typedarray_info(napi_env env,
*length = array->Length();
}

v8::Local<v8::ArrayBuffer> buffer;
v8::Local<v8::ArrayBufferBase> 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) {
Expand Down Expand Up @@ -3481,11 +3481,11 @@ napi_status NAPI_CDECL napi_get_dataview_info(napi_env env,
*byte_length = array->ByteLength();
}

v8::Local<v8::ArrayBuffer> buffer;
v8::Local<v8::ArrayBufferBase> 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void ModuleWrap::New(const FunctionCallbackInfo<Value>& args) {
CHECK(!can_use_builtin_cache); // We don't use this option internally.
Local<ArrayBufferView> cached_data_buf = args[5].As<ArrayBufferView>();
uint8_t* data =
static_cast<uint8_t*>(cached_data_buf->Buffer()->Data());
static_cast<uint8_t*>(cached_data_buf->GetBuffer()->Data());
user_cached_data =
new ScriptCompiler::CachedData(data + cached_data_buf->ByteOffset(),
cached_data_buf->ByteLength());
Expand Down
9 changes: 5 additions & 4 deletions src/node_blob.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace node {

using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferBase;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
Expand Down Expand Up @@ -77,7 +78,7 @@ void Concat(const FunctionCallbackInfo<Value>& args) {
} else {
CHECK(val->IsArrayBufferView());
auto view = val.As<ArrayBufferView>();
views.push_back(View{view->Buffer()->GetBackingStore(),
views.push_back(View{view->GetBuffer()->GetBackingStore(),
view->ByteLength(),
view->ByteOffset()});
total += view->ByteLength();
Expand Down Expand Up @@ -206,13 +207,13 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
Local<Value> entry = sources[i].Get(isolate);

auto entryFromArrayBuffer =
[isolate](Local<ArrayBuffer> buf,
[isolate](Local<ArrayBufferBase> buf,
size_t byte_length,
size_t byte_offset =
0) mutable -> std::unique_ptr<DataQueue::Entry> {
if (buf->IsDetachable()) {
std::shared_ptr<BackingStore> store = buf->GetBackingStore();
if (buf->Detach(Local<Value>()).IsNothing()) {
if (buf.As<ArrayBuffer>()->Detach(Local<Value>()).IsNothing()) {
return nullptr;
}
return DataQueue::CreateInMemoryEntryFromBackingStore(
Expand Down Expand Up @@ -245,7 +246,7 @@ void Blob::New(const FunctionCallbackInfo<Value>& args) {
} else if (entry->IsArrayBufferView()) {
Local<ArrayBufferView> view = entry.As<ArrayBufferView>();
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)) {
Expand Down
11 changes: 6 additions & 5 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace node {
namespace Buffer {

using v8::ArrayBuffer;
using v8::ArrayBufferBase;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
Expand Down Expand Up @@ -265,7 +266,7 @@ bool HasInstance(Local<Object> obj) {
char* Data(Local<Value> val) {
CHECK(val->IsArrayBufferView());
Local<ArrayBufferView> ui = val.As<ArrayBufferView>();
return static_cast<char*>(ui->Buffer()->Data()) + ui->ByteOffset();
return static_cast<char*>(ui->GetBuffer()->Data()) + ui->ByteOffset();
}


Expand Down Expand Up @@ -592,7 +593,7 @@ void StringSlice(const FunctionCallbackInfo<Value>& args) {
size_t length = end - start;

std::unique_ptr<char[]> data_copy;
if (view->Buffer()->IsSharedArrayBuffer()) {
if (view->GetBuffer()->IsSharedArrayBuffer()) {
data_copy = std::make_unique_for_overwrite<char[]>(length);
memcpy(data_copy.get(), data_ptr + start, length);
data_ptr = data_copy.get();
Expand All @@ -617,8 +618,8 @@ size_t CopyImpl(Local<Value> source_obj,
Local<ArrayBufferView> source = source_obj.As<ArrayBufferView>();
Local<ArrayBufferView> target = target_obj.As<ArrayBufferView>();

Local<ArrayBuffer> source_ab = source->Buffer();
Local<ArrayBuffer> target_ab = target->Buffer();
Local<ArrayBufferBase> source_ab = source->GetBuffer();
Local<ArrayBufferBase> target_ab = target->GetBuffer();

const size_t source_offset = source->ByteOffset() + source_start;
const size_t target_offset = target->ByteOffset() + target_start;
Expand Down Expand Up @@ -1509,7 +1510,7 @@ static bool MaskArgs(Local<Value> source_obj,
uint32_t mask) {
CHECK(destination_obj->IsArrayBufferView());
Local<ArrayBufferView> destination = destination_obj.As<ArrayBufferView>();
Local<ArrayBuffer> destination_ab = destination->Buffer();
Local<ArrayBufferBase> destination_ab = destination->GetBuffer();
if (destination_ab->IsImmutable()) return false;
if (length == 0) return true;
const size_t destination_length = destination->ByteLength();
Expand Down
4 changes: 2 additions & 2 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ void ContextifyScript::New(const FunctionCallbackInfo<Value>& args) {

ScriptCompiler::CachedData* cached_data = nullptr;
if (!cached_data_buf.IsEmpty()) {
uint8_t* data = static_cast<uint8_t*>(cached_data_buf->Buffer()->Data());
uint8_t* data = static_cast<uint8_t*>(cached_data_buf->GetBuffer()->Data());
cached_data = new ScriptCompiler::CachedData(
data + cached_data_buf->ByteOffset(), cached_data_buf->ByteLength());
}
Expand Down Expand Up @@ -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<uint8_t*>(cached_data_buf->Buffer()->Data());
uint8_t* data = static_cast<uint8_t*>(cached_data_buf->GetBuffer()->Data());
cached_data = new ScriptCompiler::CachedData(
data + cached_data_buf->ByteOffset(), cached_data_buf->ByteLength());
}
Expand Down
2 changes: 1 addition & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading
Loading