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: https://github.com/nodejs/node/pull/56658 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
b11ee4cad3
commit
869ea331f3
@ -15,6 +15,7 @@ namespace encoding_binding {
|
|||||||
|
|
||||||
using v8::ArrayBuffer;
|
using v8::ArrayBuffer;
|
||||||
using v8::BackingStore;
|
using v8::BackingStore;
|
||||||
|
using v8::BackingStoreInitializationMode;
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::FunctionCallbackInfo;
|
using v8::FunctionCallbackInfo;
|
||||||
using v8::Isolate;
|
using v8::Isolate;
|
||||||
@ -124,9 +125,8 @@ void BindingData::EncodeUtf8String(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
Local<ArrayBuffer> ab;
|
Local<ArrayBuffer> ab;
|
||||||
{
|
{
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
|
||||||
std::unique_ptr<BackingStore> bs =
|
isolate, length, BackingStoreInitializationMode::kUninitialized);
|
||||||
ArrayBuffer::NewBackingStore(isolate, length);
|
|
||||||
|
|
||||||
CHECK(bs);
|
CHECK(bs);
|
||||||
|
|
||||||
|
14
src/env.cc
14
src/env.cc
@ -39,6 +39,9 @@ namespace node {
|
|||||||
|
|
||||||
using errors::TryCatchScope;
|
using errors::TryCatchScope;
|
||||||
using v8::Array;
|
using v8::Array;
|
||||||
|
using v8::ArrayBuffer;
|
||||||
|
using v8::BackingStore;
|
||||||
|
using v8::BackingStoreInitializationMode;
|
||||||
using v8::Boolean;
|
using v8::Boolean;
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::CppHeap;
|
using v8::CppHeap;
|
||||||
@ -742,17 +745,18 @@ void Environment::add_refs(int64_t diff) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uv_buf_t Environment::allocate_managed_buffer(const size_t suggested_size) {
|
uv_buf_t Environment::allocate_managed_buffer(const size_t suggested_size) {
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(isolate_data());
|
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
|
||||||
std::unique_ptr<v8::BackingStore> bs =
|
isolate(),
|
||||||
v8::ArrayBuffer::NewBackingStore(isolate(), suggested_size);
|
suggested_size,
|
||||||
|
BackingStoreInitializationMode::kUninitialized);
|
||||||
uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength());
|
uv_buf_t buf = uv_buf_init(static_cast<char*>(bs->Data()), bs->ByteLength());
|
||||||
released_allocated_buffers_.emplace(buf.base, std::move(bs));
|
released_allocated_buffers_.emplace(buf.base, std::move(bs));
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<v8::BackingStore> Environment::release_managed_buffer(
|
std::unique_ptr<BackingStore> Environment::release_managed_buffer(
|
||||||
const uv_buf_t& buf) {
|
const uv_buf_t& buf) {
|
||||||
std::unique_ptr<v8::BackingStore> bs;
|
std::unique_ptr<BackingStore> bs;
|
||||||
if (buf.base != nullptr) {
|
if (buf.base != nullptr) {
|
||||||
auto it = released_allocated_buffers_.find(buf.base);
|
auto it = released_allocated_buffers_.find(buf.base);
|
||||||
CHECK_NE(it, released_allocated_buffers_.end());
|
CHECK_NE(it, released_allocated_buffers_.end());
|
||||||
|
@ -58,6 +58,7 @@ namespace Buffer {
|
|||||||
using v8::ArrayBuffer;
|
using v8::ArrayBuffer;
|
||||||
using v8::ArrayBufferView;
|
using v8::ArrayBufferView;
|
||||||
using v8::BackingStore;
|
using v8::BackingStore;
|
||||||
|
using v8::BackingStoreInitializationMode;
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::EscapableHandleScope;
|
using v8::EscapableHandleScope;
|
||||||
using v8::FastApiTypedArray;
|
using v8::FastApiTypedArray;
|
||||||
@ -372,9 +373,8 @@ MaybeLocal<Object> New(Environment* env, size_t length) {
|
|||||||
|
|
||||||
Local<ArrayBuffer> ab;
|
Local<ArrayBuffer> ab;
|
||||||
{
|
{
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
|
||||||
std::unique_ptr<BackingStore> bs =
|
isolate, length, BackingStoreInitializationMode::kUninitialized);
|
||||||
ArrayBuffer::NewBackingStore(isolate, length);
|
|
||||||
|
|
||||||
CHECK(bs);
|
CHECK(bs);
|
||||||
|
|
||||||
@ -413,18 +413,14 @@ MaybeLocal<Object> Copy(Environment* env, const char* data, size_t length) {
|
|||||||
return Local<Object>();
|
return Local<Object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Local<ArrayBuffer> ab;
|
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
|
||||||
{
|
isolate, length, BackingStoreInitializationMode::kUninitialized);
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
|
||||||
std::unique_ptr<BackingStore> bs =
|
|
||||||
ArrayBuffer::NewBackingStore(isolate, length);
|
|
||||||
|
|
||||||
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 =
|
MaybeLocal<Object> obj =
|
||||||
New(env, ab, 0, ab->ByteLength())
|
New(env, ab, 0, ab->ByteLength())
|
||||||
|
@ -27,6 +27,7 @@ using v8::Array;
|
|||||||
using v8::ArrayBuffer;
|
using v8::ArrayBuffer;
|
||||||
using v8::ArrayBufferView;
|
using v8::ArrayBufferView;
|
||||||
using v8::BackingStore;
|
using v8::BackingStore;
|
||||||
|
using v8::BackingStoreInitializationMode;
|
||||||
using v8::Boolean;
|
using v8::Boolean;
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::EscapableHandleScope;
|
using v8::EscapableHandleScope;
|
||||||
@ -292,11 +293,10 @@ Local<Value> Http2Settings::Pack(
|
|||||||
size_t count,
|
size_t count,
|
||||||
const nghttp2_settings_entry* entries) {
|
const nghttp2_settings_entry* entries) {
|
||||||
EscapableHandleScope scope(env->isolate());
|
EscapableHandleScope scope(env->isolate());
|
||||||
std::unique_ptr<BackingStore> bs;
|
std::unique_ptr<BackingStore> bs = ArrayBuffer::NewBackingStore(
|
||||||
{
|
env->isolate(),
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
count * 6,
|
||||||
bs = ArrayBuffer::NewBackingStore(env->isolate(), count * 6);
|
BackingStoreInitializationMode::kUninitialized);
|
||||||
}
|
|
||||||
if (nghttp2_pack_settings_payload(static_cast<uint8_t*>(bs->Data()),
|
if (nghttp2_pack_settings_payload(static_cast<uint8_t*>(bs->Data()),
|
||||||
bs->ByteLength(),
|
bs->ByteLength(),
|
||||||
entries,
|
entries,
|
||||||
@ -457,13 +457,11 @@ Origins::Origins(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
bs_ = ArrayBuffer::NewBackingStore(
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
env->isolate(),
|
||||||
bs_ = ArrayBuffer::NewBackingStore(env->isolate(),
|
alignof(nghttp2_origin_entry) - 1 +
|
||||||
alignof(nghttp2_origin_entry) - 1 +
|
count_ * sizeof(nghttp2_origin_entry) + origin_string_len,
|
||||||
count_ * sizeof(nghttp2_origin_entry) +
|
BackingStoreInitializationMode::kUninitialized);
|
||||||
origin_string_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
|
// Make sure the start address is aligned appropriately for an nghttp2_nv*.
|
||||||
char* start = nbytes::AlignUp(static_cast<char*>(bs_->Data()),
|
char* start = nbytes::AlignUp(static_cast<char*>(bs_->Data()),
|
||||||
@ -2090,12 +2088,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) {
|
|||||||
// happen, we concatenate the data we received with the already-stored
|
// happen, we concatenate the data we received with the already-stored
|
||||||
// pending input data, slicing off the already processed part.
|
// pending input data, slicing off the already processed part.
|
||||||
size_t pending_len = stream_buf_.len - stream_buf_offset_;
|
size_t pending_len = stream_buf_.len - stream_buf_offset_;
|
||||||
std::unique_ptr<BackingStore> new_bs;
|
std::unique_ptr<BackingStore> new_bs = ArrayBuffer::NewBackingStore(
|
||||||
{
|
env()->isolate(),
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env()->isolate_data());
|
pending_len + nread,
|
||||||
new_bs = ArrayBuffer::NewBackingStore(env()->isolate(),
|
BackingStoreInitializationMode::kUninitialized);
|
||||||
pending_len + nread);
|
|
||||||
}
|
|
||||||
memcpy(static_cast<char*>(new_bs->Data()),
|
memcpy(static_cast<char*>(new_bs->Data()),
|
||||||
stream_buf_.base + stream_buf_offset_,
|
stream_buf_.base + stream_buf_offset_,
|
||||||
pending_len);
|
pending_len);
|
||||||
|
@ -19,6 +19,7 @@ namespace node {
|
|||||||
using v8::Array;
|
using v8::Array;
|
||||||
using v8::ArrayBuffer;
|
using v8::ArrayBuffer;
|
||||||
using v8::BackingStore;
|
using v8::BackingStore;
|
||||||
|
using v8::BackingStoreInitializationMode;
|
||||||
using v8::ConstructorBehavior;
|
using v8::ConstructorBehavior;
|
||||||
using v8::Context;
|
using v8::Context;
|
||||||
using v8::DontDelete;
|
using v8::DontDelete;
|
||||||
@ -243,8 +244,8 @@ int StreamBase::Writev(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
std::unique_ptr<BackingStore> bs;
|
std::unique_ptr<BackingStore> bs;
|
||||||
if (storage_size > 0) {
|
if (storage_size > 0) {
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
bs = ArrayBuffer::NewBackingStore(
|
||||||
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
|
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
@ -398,14 +399,14 @@ int StreamBase::WriteString(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
if (try_write) {
|
if (try_write) {
|
||||||
// Copy partial data
|
// Copy partial data
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
bs = ArrayBuffer::NewBackingStore(
|
||||||
bs = ArrayBuffer::NewBackingStore(isolate, buf.len);
|
isolate, buf.len, BackingStoreInitializationMode::kUninitialized);
|
||||||
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
|
memcpy(static_cast<char*>(bs->Data()), buf.base, buf.len);
|
||||||
data_size = buf.len;
|
data_size = buf.len;
|
||||||
} else {
|
} else {
|
||||||
// Write it
|
// Write it
|
||||||
NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data());
|
bs = ArrayBuffer::NewBackingStore(
|
||||||
bs = ArrayBuffer::NewBackingStore(isolate, storage_size);
|
isolate, storage_size, BackingStoreInitializationMode::kUninitialized);
|
||||||
data_size = StringBytes::Write(isolate,
|
data_size = StringBytes::Write(isolate,
|
||||||
static_cast<char*>(bs->Data()),
|
static_cast<char*>(bs->Data()),
|
||||||
storage_size,
|
storage_size,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user