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::BackingStore;
|
||||
using v8::BackingStoreInitializationMode;
|
||||
using v8::Context;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Isolate;
|
||||
@ -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);
|
||||
|
||||
|
14
src/env.cc
14
src/env.cc
@ -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;
|
||||
@ -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());
|
||||
|
@ -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;
|
||||
@ -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);
|
||||
|
||||
@ -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())
|
||||
|
@ -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;
|
||||
@ -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,
|
||||
@ -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()),
|
||||
@ -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
|
||||
// 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);
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user