Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: replace NoArrayBufferZeroFillScope with v8 option #56658

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/encoding_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace encoding_binding {

using v8::ArrayBuffer;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::Isolate;
Expand Down Expand Up @@ -124,9 +125,8 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {

Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
isolate, length, BackingStoreInitializationMode::kUninitialized);

CHECK(bs);

Expand Down
14 changes: 9 additions & 5 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ namespace node {

using errors::TryCatchScope;
using v8::Array;
using v8::ArrayBuffer;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::Boolean;
using v8::Context;
using v8::CppHeap;
Expand Down Expand Up @@ -742,17 +745,18 @@ void Environment::add_refs(int64_t diff) {
}

uv_buf_t Environment::allocate_managed_buffer(const size_t suggested_size) {
NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data());
std::unique_ptr<v8::BackingStore> bs =
v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size);
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
isolate(),
suggested_size,
BackingStoreInitializationMode::kUninitialized);
uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength());
released_allocated_buffers_.emplace(buf.base, std::move(bs));
return buf;
}

std::unique_ptr<v8::BackingStore> Environment::release_managed_buffer(
std::unique_ptr<BackingStore> Environment::release_managed_buffer(
const uv_buf_t& buf) {
std::unique_ptr<v8::BackingStore> bs;
std::unique_ptr<BackingStore> bs;
if (buf.base != nullptr) {
auto it = released_allocated_buffers_.find(buf.base);
CHECK_NE(it, released_allocated_buffers_.end());
Expand Down
20 changes: 8 additions & 12 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace Buffer {
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::Context;
using v8::EscapableHandleScope;
using v8::FastApiTypedArray;
Expand Down Expand Up @@ -372,9 +373,8 @@ MaybeLocal<Object> New(Environment* env, size_t length) {

Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
isolate, length, BackingStoreInitializationMode::kUninitialized);

CHECK(bs);

Expand Down Expand Up @@ -413,18 +413,14 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
return Local<Object>();
}

Local<ArrayBuffer> ab;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
std::unique_ptr<BackingStore> bs =
ArrayBuffer::NewBackingStore(isolate, length);
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
isolate, length, BackingStoreInitializationMode::kUninitialized);

CHECK(bs);
CHECK(bs);

memcpy(bs->Data(), data, length);
memcpy(bs->Data(), data, length);

ab = ArrayBuffer::New(isolate, std::move(bs));
}
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, std::move(bs));

MaybeLocal<Object> obj =
New(env, ab, 0, ab->ByteLength())
Expand Down
32 changes: 14 additions & 18 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ using v8::Array;
using v8::ArrayBuffer;
using v8::ArrayBufferView;
using v8::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::Boolean;
using v8::Context;
using v8::EscapableHandleScope;
Expand Down Expand Up @@ -292,11 +293,10 @@ Local<Value> Http2Settings::Pack(
size_t count,
const nghttp2_settings_entry* entries) {
EscapableHandleScope scope(env->isolate());
std::unique_ptr<BackingStore> bs;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
bs = ArrayBuffer::NewBackingStore(env->isolate(), count * 6);
}
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
env->isolate(),
count * 6,
BackingStoreInitializationMode::kUninitialized);
if (nghttp2_pack_settings_payload(static_cast<uint8_t*>(bs->Data()),
bs->ByteLength(),
entries,
Expand Down Expand Up @@ -457,13 +457,11 @@ Origins::Origins(
return;
}

{
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
bs_ = ArrayBuffer::NewBackingStore(env->isolate(),
alignof(nghttp2_origin_entry) - 1 +
count_ * sizeof(nghttp2_origin_entry) +
origin_string_len);
}
bs_ = ArrayBuffer::NewBackingStore(
env->isolate(),
alignof(nghttp2_origin_entry) - 1 +
count_ * sizeof(nghttp2_origin_entry) + origin_string_len,
BackingStoreInitializationMode::kUninitialized);

// Make sure the start address is aligned appropriately for an nghttp2_nv*.
char* start = nbytes::AlignUp(static_cast<char*>(bs_->Data()),
Expand Down Expand Up @@ -2064,12 +2062,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
// happen, we concatenate the data we received with the already-stored
// pending input data, slicing off the already processed part.
size_t pending_len = stream_buf_.len - stream_buf_offset_;
std::unique_ptr<BackingStore> new_bs;
{
NoArrayBufferZeroFillScope no_zero_fill_scope(env()->isolate_data());
new_bs = ArrayBuffer::NewBackingStore(env()->isolate(),
pending_len + nread);
}
std::unique_ptr<BackingStore> new_bs = ArrayBuffer::NewBackingStore(
env()->isolate(),
pending_len + nread,
BackingStoreInitializationMode::kUninitialized);
memcpy(static_cast<char*>(new_bs->Data()),
stream_buf_.base + stream_buf_offset_,
pending_len);
Expand Down
13 changes: 7 additions & 6 deletions src/stream_base.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::BackingStore;
using v8::BackingStoreInitializationMode;
using v8::ConstructorBehavior;
using v8::Context;
using v8::DontDelete;
Expand Down Expand Up @@ -243,8 +244,8 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {

std::unique_ptr<BackingStore> bs;
if (storage_size > 0) {
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
bs = ArrayBuffer::NewBackingStore(
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
}

offset = 0;
Expand Down Expand Up @@ -398,14 +399,14 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {

if (try_write) {
// Copy partial data
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
bs = ArrayBuffer::NewBackingStore(isolate, buf.len);
bs = ArrayBuffer::NewBackingStore(
isolate, buf.len, BackingStoreInitializationMode::kUninitialized);
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
data_size = buf.len;
} else {
// Write it
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
bs = ArrayBuffer::NewBackingStore(
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
data_size = StringBytes::Write(isolate,
static_cast<char*>(bs->Data()),
storage_size,
Expand Down
Loading