Skip to content

Commit 2b6a82d

Browse files
jasnelladuh95
authored andcommitted
src: replace NoArrayBufferZeroFillScope with v8 option
NoArrayBufferZeroFillScope was added before the v8 option to create uninitialized backing stores was added. We can start moving away from it. PR-URL: #56658 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 2fb007f commit 2b6a82d

File tree

5 files changed

+41
-44
lines changed

5 files changed

+41
-44
lines changed

src/encoding_binding.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace encoding_binding {
1515

1616
using v8::ArrayBuffer;
1717
using v8::BackingStore;
18+
using v8::BackingStoreInitializationMode;
1819
using v8::Context;
1920
using v8::FunctionCallbackInfo;
2021
using v8::Isolate;
@@ -124,9 +125,8 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {
124125

125126
Local<ArrayBuffer> ab;
126127
{
127-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
128-
std::unique_ptr<BackingStore> bs =
129-
ArrayBuffer::NewBackingStore(isolate, length);
128+
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
129+
isolate, length, BackingStoreInitializationMode::kUninitialized);
130130

131131
CHECK(bs);
132132

src/env.cc

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ namespace node {
3939

4040
using errors::TryCatchScope;
4141
using v8::Array;
42+
using v8::ArrayBuffer;
43+
using v8::BackingStore;
44+
using v8::BackingStoreInitializationMode;
4245
using v8::Boolean;
4346
using v8::Context;
4447
using v8::CppHeap;
@@ -742,17 +745,18 @@ void Environment::add_refs(int64_t diff) {
742745
}
743746

744747
uv_buf_t Environment::allocate_managed_buffer(const size_t suggested_size) {
745-
NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data());
746-
std::unique_ptr<v8::BackingStore> bs =
747-
v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size);
748+
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
749+
isolate(),
750+
suggested_size,
751+
BackingStoreInitializationMode::kUninitialized);
748752
uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength());
749753
released_allocated_buffers_.emplace(buf.base, std::move(bs));
750754
return buf;
751755
}
752756

753-
std::unique_ptr<v8::BackingStore> Environment::release_managed_buffer(
757+
std::unique_ptr<BackingStore> Environment::release_managed_buffer(
754758
const uv_buf_t& buf) {
755-
std::unique_ptr<v8::BackingStore> bs;
759+
std::unique_ptr<BackingStore> bs;
756760
if (buf.base != nullptr) {
757761
auto it = released_allocated_buffers_.find(buf.base);
758762
CHECK_NE(it, released_allocated_buffers_.end());

src/node_buffer.cc

+8-12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace Buffer {
5858
using v8::ArrayBuffer;
5959
using v8::ArrayBufferView;
6060
using v8::BackingStore;
61+
using v8::BackingStoreInitializationMode;
6162
using v8::Context;
6263
using v8::EscapableHandleScope;
6364
using v8::FastApiTypedArray;
@@ -372,9 +373,8 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
372373

373374
Local<ArrayBuffer> ab;
374375
{
375-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
376-
std::unique_ptr<BackingStore> bs =
377-
ArrayBuffer::NewBackingStore(isolate, length);
376+
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
377+
isolate, length, BackingStoreInitializationMode::kUninitialized);
378378

379379
CHECK(bs);
380380

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

416-
Local<ArrayBuffer> ab;
417-
{
418-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
419-
std::unique_ptr<BackingStore> bs =
420-
ArrayBuffer::NewBackingStore(isolate, length);
416+
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
417+
isolate, length, BackingStoreInitializationMode::kUninitialized);
421418

422-
CHECK(bs);
419+
CHECK(bs);
423420

424-
memcpy(bs->Data(), data, length);
421+
memcpy(bs->Data(), data, length);
425422

426-
ab = ArrayBuffer::New(isolate, std::move(bs));
427-
}
423+
Local<ArrayBuffer> ab = ArrayBuffer::New(isolate, std::move(bs));
428424

429425
MaybeLocal<Object> obj =
430426
New(env, ab, 0, ab->ByteLength())

src/node_http2.cc

+14-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ using v8::Array;
2727
using v8::ArrayBuffer;
2828
using v8::ArrayBufferView;
2929
using v8::BackingStore;
30+
using v8::BackingStoreInitializationMode;
3031
using v8::Boolean;
3132
using v8::Context;
3233
using v8::EscapableHandleScope;
@@ -292,11 +293,10 @@ Local<Value> Http2Settings::Pack(
292293
size_t count,
293294
const nghttp2_settings_entry* entries) {
294295
EscapableHandleScope scope(env->isolate());
295-
std::unique_ptr<BackingStore> bs;
296-
{
297-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
298-
bs = ArrayBuffer::NewBackingStore(env->isolate(), count * 6);
299-
}
296+
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
297+
env->isolate(),
298+
count * 6,
299+
BackingStoreInitializationMode::kUninitialized);
300300
if (nghttp2_pack_settings_payload(static_cast<uint8_t*>(bs->Data()),
301301
bs->ByteLength(),
302302
entries,
@@ -457,13 +457,11 @@ Origins::Origins(
457457
return;
458458
}
459459

460-
{
461-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
462-
bs_ = ArrayBuffer::NewBackingStore(env->isolate(),
463-
alignof(nghttp2_origin_entry) - 1 +
464-
count_ * sizeof(nghttp2_origin_entry) +
465-
origin_string_len);
466-
}
460+
bs_ = ArrayBuffer::NewBackingStore(
461+
env->isolate(),
462+
alignof(nghttp2_origin_entry) - 1 +
463+
count_ * sizeof(nghttp2_origin_entry) + origin_string_len,
464+
BackingStoreInitializationMode::kUninitialized);
467465

468466
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
469467
char* start = nbytes::AlignUp(static_cast<char*>(bs_->Data()),
@@ -2090,12 +2088,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
20902088
// happen, we concatenate the data we received with the already-stored
20912089
// pending input data, slicing off the already processed part.
20922090
size_t pending_len = stream_buf_.len - stream_buf_offset_;
2093-
std::unique_ptr<BackingStore> new_bs;
2094-
{
2095-
NoArrayBufferZeroFillScope no_zero_fill_scope(env()->isolate_data());
2096-
new_bs = ArrayBuffer::NewBackingStore(env()->isolate(),
2097-
pending_len + nread);
2098-
}
2091+
std::unique_ptr<BackingStore> new_bs = ArrayBuffer::NewBackingStore(
2092+
env()->isolate(),
2093+
pending_len + nread,
2094+
BackingStoreInitializationMode::kUninitialized);
20992095
memcpy(static_cast<char*>(new_bs->Data()),
21002096
stream_buf_.base + stream_buf_offset_,
21012097
pending_len);

src/stream_base.cc

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace node {
1919
using v8::Array;
2020
using v8::ArrayBuffer;
2121
using v8::BackingStore;
22+
using v8::BackingStoreInitializationMode;
2223
using v8::ConstructorBehavior;
2324
using v8::Context;
2425
using v8::DontDelete;
@@ -243,8 +244,8 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
243244

244245
std::unique_ptr<BackingStore> bs;
245246
if (storage_size > 0) {
246-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
247-
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
247+
bs = ArrayBuffer::NewBackingStore(
248+
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
248249
}
249250

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

399400
if (try_write) {
400401
// Copy partial data
401-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
402-
bs = ArrayBuffer::NewBackingStore(isolate, buf.len);
402+
bs = ArrayBuffer::NewBackingStore(
403+
isolate, buf.len, BackingStoreInitializationMode::kUninitialized);
403404
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
404405
data_size = buf.len;
405406
} else {
406407
// Write it
407-
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
408-
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
408+
bs = ArrayBuffer::NewBackingStore(
409+
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
409410
data_size = StringBytes::Write(isolate,
410411
static_cast<char*>(bs->Data()),
411412
storage_size,

0 commit comments

Comments
 (0)