diff --git a/src/api/callback.cc b/src/api/callback.cc index c1ec67ae657f32..7e4e7284e029c4 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -12,6 +12,7 @@ using v8::Function; using v8::HandleScope; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Object; using v8::String; @@ -215,14 +216,14 @@ MaybeLocal InternalMakeCallback(Environment* env, Local context = env->context(); if (use_async_hooks_trampoline) { - MaybeStackBuffer, 16> args(3 + argc); + LocalVector args(env->isolate(), 3 + argc); args[0] = v8::Number::New(env->isolate(), asyncContext.async_id); args[1] = resource; args[2] = callback; for (int i = 0; i < argc; i++) { args[i + 3] = argv[i]; } - ret = hook_cb->Call(context, recv, args.length(), &args[0]); + ret = hook_cb->Call(context, recv, args.size(), args.data()); } else { ret = callback->Call(context, recv, argc, argv); } diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index c4510bdf63b276..d5093b76109033 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -68,6 +68,7 @@ using v8::Isolate; using v8::Just; using v8::JustVoid; using v8::Local; +using v8::LocalVector; using v8::Maybe; using v8::Nothing; using v8::Null; @@ -193,11 +194,11 @@ Local AddrTTLToArray( Environment* env, const T* addrttls, size_t naddrttls) { - MaybeStackBuffer, 8> ttls(naddrttls); + LocalVector ttls(env->isolate(), naddrttls); for (size_t i = 0; i < naddrttls; i++) ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl); - return Array::New(env->isolate(), ttls.out(), naddrttls); + return Array::New(env->isolate(), ttls.data(), ttls.size()); } int ParseGeneralReply( diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 6a967702b22df0..387c871f4ff4e5 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -34,6 +34,7 @@ using v8::Context; using v8::EscapableHandleScope; using v8::Integer; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Object; using v8::String; @@ -387,7 +388,7 @@ MaybeLocal GetClientHelloCiphers( const unsigned char* buf; size_t len = SSL_client_hello_get0_ciphers(ssl.get(), &buf); size_t count = len / 2; - MaybeStackBuffer, 16> ciphers(count); + LocalVector ciphers(env->isolate(), count); int j = 0; for (size_t n = 0; n < len; n += 2) { const SSL_CIPHER* cipher = SSL_CIPHER_find(ssl.get(), buf); @@ -409,8 +410,8 @@ MaybeLocal GetClientHelloCiphers( } ciphers[j++] = obj; } - Local ret = Array::New(env->isolate(), ciphers.out(), count); - return scope.Escape(ret); + return scope.Escape( + Array::New(env->isolate(), ciphers.data(), ciphers.size())); } diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index 714efca9d8a0bb..52c03e33bace80 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -52,6 +52,7 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Null; using v8::Object; @@ -1869,7 +1870,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo& args) { SSL* ssl = w->ssl_.get(); int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, nullptr); - MaybeStackBuffer, 16> ret_arr(nsig); + LocalVector ret_arr(env->isolate(), nsig); for (int i = 0; i < nsig; i++) { int hash_nid; @@ -1937,7 +1938,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo& args) { } args.GetReturnValue().Set( - Array::New(env->isolate(), ret_arr.out(), ret_arr.length())); + Array::New(env->isolate(), ret_arr.data(), ret_arr.size())); } void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo& args) { diff --git a/src/crypto/crypto_util.h b/src/crypto/crypto_util.h index 922e77091d7217..ae82db24c68a47 100644 --- a/src/crypto/crypto_util.h +++ b/src/crypto/crypto_util.h @@ -547,7 +547,8 @@ void ThrowCryptoError(Environment* env, class CipherPushContext { public: - inline explicit CipherPushContext(Environment* env) : env_(env) {} + inline explicit CipherPushContext(Environment* env) + : list_(env->isolate()), env_(env) {} inline void push_back(const char* str) { list_.emplace_back(OneByteString(env_->isolate(), str)); @@ -558,7 +559,7 @@ class CipherPushContext { } private: - std::vector> list_; + v8::LocalVector list_; Environment* env_; }; diff --git a/src/crypto/crypto_x509.cc b/src/crypto/crypto_x509.cc index 9b9bb7be9a8dac..3534380939d5a4 100644 --- a/src/crypto/crypto_x509.cc +++ b/src/crypto/crypto_x509.cc @@ -29,6 +29,7 @@ using v8::FunctionTemplate; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::NewStringType; using v8::Object; @@ -265,7 +266,7 @@ MaybeLocal GetKeyUsage(Environment* env, const ncrypto::X509View& cert) { X509_get_ext_d2i(cert.get(), NID_ext_key_usage, nullptr, nullptr))); if (eku) { const int count = sk_ASN1_OBJECT_num(eku.get()); - MaybeStackBuffer, 16> ext_key_usage(count); + LocalVector ext_key_usage(env->isolate(), count); char buf[256]; int j = 0; @@ -276,7 +277,8 @@ MaybeLocal GetKeyUsage(Environment* env, const ncrypto::X509View& cert) { } } - return Array::New(env->isolate(), ext_key_usage.out(), count); + return Array::New( + env->isolate(), ext_key_usage.data(), ext_key_usage.size()); } return Undefined(env->isolate()); diff --git a/src/js_stream.cc b/src/js_stream.cc index 55cbdf5bf2b0a3..f7881a83961193 100644 --- a/src/js_stream.cc +++ b/src/js_stream.cc @@ -19,6 +19,7 @@ using v8::HandleScope; using v8::Int32; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::Object; using v8::TryCatch; using v8::Value; @@ -117,16 +118,15 @@ int JSStream::DoWrite(WriteWrap* w, HandleScope scope(env()->isolate()); Context::Scope context_scope(env()->context()); - MaybeStackBuffer, 16> bufs_arr(count); + LocalVector bufs_arr(env()->isolate(), count); for (size_t i = 0; i < count; i++) { bufs_arr[i] = Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocalChecked(); } Local argv[] = { - w->object(), - Array::New(env()->isolate(), bufs_arr.out(), count) - }; + w->object(), + Array::New(env()->isolate(), bufs_arr.data(), bufs_arr.size())}; TryCatchScope try_catch(env()); Local value; diff --git a/src/js_udp_wrap.cc b/src/js_udp_wrap.cc index a4f183025df4be..9e25c4a078d0da 100644 --- a/src/js_udp_wrap.cc +++ b/src/js_udp_wrap.cc @@ -19,6 +19,7 @@ using v8::HandleScope; using v8::Int32; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::Object; using v8::Value; @@ -97,7 +98,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs, int64_t value_int = JS_EXCEPTION_PENDING; size_t total_len = 0; - MaybeStackBuffer, 16> buffers(nbufs); + LocalVector buffers(env()->isolate(), nbufs); for (size_t i = 0; i < nbufs; i++) { buffers[i] = Buffer::Copy(env(), bufs[i].base, bufs[i].len) .ToLocalChecked(); @@ -108,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs, if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int; Local args[] = { - listener()->CreateSendWrap(total_len)->object(), - Array::New(env()->isolate(), buffers.out(), nbufs), - address, + listener()->CreateSendWrap(total_len)->object(), + Array::New(env()->isolate(), buffers.data(), buffers.size()), + address, }; if (!MakeCallback(env()->onwrite_string(), arraysize(args), args) diff --git a/src/node_dir.cc b/src/node_dir.cc index 2dfb1305a18909..61874bb3235130 100644 --- a/src/node_dir.cc +++ b/src/node_dir.cc @@ -37,6 +37,7 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Null; using v8::Number; @@ -212,7 +213,7 @@ static MaybeLocal DirentListToArray( int num, enum encoding encoding, Local* err_out) { - MaybeStackBuffer, 64> entries(num * 2); + LocalVector entries(env->isolate(), num * 2); // Return an array of all read filenames. int j = 0; @@ -233,7 +234,7 @@ static MaybeLocal DirentListToArray( entries[j++] = Integer::New(env->isolate(), ents[i].type); } - return Array::New(env->isolate(), entries.out(), j); + return Array::New(env->isolate(), entries.data(), entries.size()); } static void AfterDirRead(uv_fs_t* req) { diff --git a/src/node_env_var.cc b/src/node_env_var.cc index fdf86f17d460f5..dec6d4dfc6992f 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -22,6 +22,7 @@ using v8::Isolate; using v8::Just; using v8::JustVoid; using v8::Local; +using v8::LocalVector; using v8::Maybe; using v8::MaybeLocal; using v8::Name; @@ -196,8 +197,8 @@ Local RealEnvStore::Enumerate(Isolate* isolate) const { auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); }); CHECK_EQ(uv_os_environ(&items, &count), 0); - MaybeStackBuffer, 256> env_v(count); - int env_v_index = 0; + LocalVector env_v(isolate, count); + size_t env_v_index = 0; for (int i = 0; i < count; i++) { #ifdef _WIN32 // If the key starts with '=' it is a hidden environment variable. @@ -211,7 +212,8 @@ Local RealEnvStore::Enumerate(Isolate* isolate) const { env_v[env_v_index++] = str.ToLocalChecked(); } - return Array::New(isolate, env_v.out(), env_v_index); + CHECK_LE(env_v_index, env_v.size()); + return Array::New(isolate, env_v.data(), env_v_index); } std::shared_ptr KVStore::Clone(Isolate* isolate) const { diff --git a/src/node_http2.cc b/src/node_http2.cc index a07d3ce40d9ac8..597b3b45dc268b 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -37,6 +37,7 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::NewStringType; using v8::Number; @@ -1447,8 +1448,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { // this way for performance reasons (it's faster to generate and pass an // array than it is to generate and pass the object). - MaybeStackBuffer, 64> headers_v(stream->headers_count() * 2); - MaybeStackBuffer, 32> sensitive_v(stream->headers_count()); + LocalVector headers_v(isolate, stream->headers_count() * 2); + LocalVector sensitive_v(isolate, stream->headers_count()); size_t sensitive_count = 0; stream->TransferHeaders([&](const Http2Header& header, size_t i) { @@ -1463,12 +1464,12 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { stream->current_headers_length_ = 0; Local args[] = { - stream->object(), - Integer::New(isolate, id), - Integer::New(isolate, stream->headers_category()), - Integer::New(isolate, frame->hd.flags), - Array::New(isolate, headers_v.out(), headers_v.length()), - Array::New(isolate, sensitive_v.out(), sensitive_count), + stream->object(), + Integer::New(isolate, id), + Integer::New(isolate, stream->headers_category()), + Integer::New(isolate, frame->hd.flags), + Array::New(isolate, headers_v.data(), headers_v.size()), + Array::New(isolate, sensitive_v.data(), sensitive_count), }; MakeCallback(env()->http2session_on_headers_function(), arraysize(args), args); diff --git a/src/node_messaging.h b/src/node_messaging.h index 6dd34b8bd5a407..7f2b35502f2aec 100644 --- a/src/node_messaging.h +++ b/src/node_messaging.h @@ -17,6 +17,7 @@ namespace worker { class MessagePortData; class MessagePort; +// TODO(@jasnell): Can this be implemented in terms of v8::LocalVector instead typedef MaybeStackBuffer, 8> TransferList; // Used to represent the in-flight structure of an object that is being diff --git a/src/node_sockaddr.cc b/src/node_sockaddr.cc index e1572187437f1b..908ed62afee10e 100644 --- a/src/node_sockaddr.cc +++ b/src/node_sockaddr.cc @@ -20,6 +20,7 @@ using v8::FunctionTemplate; using v8::Int32; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Object; using v8::Uint32; @@ -503,15 +504,14 @@ std::string SocketAddressBlockList::SocketAddressMaskRule::ToString() { MaybeLocal SocketAddressBlockList::ListRules(Environment* env) { Mutex::ScopedLock lock(mutex_); - std::vector> rules; + v8::LocalVector rules(env->isolate()); if (!ListRules(env, &rules)) return MaybeLocal(); return Array::New(env->isolate(), rules.data(), rules.size()); } -bool SocketAddressBlockList::ListRules( - Environment* env, - std::vector>* rules) { +bool SocketAddressBlockList::ListRules(Environment* env, + LocalVector* rules) { if (parent_ && !parent_->ListRules(env, rules)) return false; for (const auto& rule : rules_) { diff --git a/src/node_sockaddr.h b/src/node_sockaddr.h index 84aa3adf5fc72a..95f3fbf2458340 100644 --- a/src/node_sockaddr.h +++ b/src/node_sockaddr.h @@ -324,9 +324,7 @@ class SocketAddressBlockList : public MemoryRetainer { SET_SELF_SIZE(SocketAddressBlockList) private: - bool ListRules( - Environment* env, - std::vector>* vec); + bool ListRules(Environment* env, v8::LocalVector* vec); std::shared_ptr parent_; std::list> rules_; diff --git a/src/node_v8.cc b/src/node_v8.cc index a7f0ba7973498e..0c211c40df13ac 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -42,6 +42,7 @@ using v8::HeapStatistics; using v8::Integer; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::Object; using v8::ScriptCompiler; using v8::String; @@ -446,17 +447,16 @@ void Initialize(Local target, // Heap space names are extracted once and exposed to JavaScript to // avoid excessive creation of heap space name Strings. HeapSpaceStatistics s; - MaybeStackBuffer, 16> heap_spaces(number_of_heap_spaces); + LocalVector heap_spaces(env->isolate(), number_of_heap_spaces); for (size_t i = 0; i < number_of_heap_spaces; i++) { env->isolate()->GetHeapSpaceStatistics(&s, i); heap_spaces[i] = String::NewFromUtf8(env->isolate(), s.space_name()) .ToLocalChecked(); } target - ->Set( - context, - FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"), - Array::New(env->isolate(), heap_spaces.out(), number_of_heap_spaces)) + ->Set(context, + FIXED_ONE_BYTE_STRING(env->isolate(), "kHeapSpaces"), + Array::New(env->isolate(), heap_spaces.data(), heap_spaces.size())) .Check(); SetMethod(context, diff --git a/src/quic/session.cc b/src/quic/session.cc index ec54a67588d9b2..8a7ccaa2fb7bef 100644 --- a/src/quic/session.cc +++ b/src/quic/session.cc @@ -45,6 +45,7 @@ using v8::HandleScope; using v8::Integer; using v8::Just; using v8::Local; +using v8::LocalVector; using v8::Maybe; using v8::Nothing; using v8::Object; @@ -1705,8 +1706,7 @@ void Session::EmitVersionNegotiation(const ngtcp2_pkt_hd& hd, // version() is the version that was actually configured for this session. // versions are the versions requested by the peer. - MaybeStackBuffer, 5> versions; - versions.AllocateSufficientStorage(nsv); + LocalVector versions(isolate, nsv); for (size_t n = 0; n < nsv; n++) versions[n] = to_integer(sv[n]); // supported are the versons we acutually support expressed as a range. @@ -1717,7 +1717,7 @@ void Session::EmitVersionNegotiation(const ngtcp2_pkt_hd& hd, Local argv[] = {// The version configured for this session. to_integer(version()), // The versions requested. - Array::New(isolate, versions.out(), nsv), + Array::New(isolate, versions.data(), versions.size()), // The versions we actually support. Array::New(isolate, supported, arraysize(supported))}; diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 36570d069ad00b..3c636d00b3d498 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -42,6 +42,7 @@ using v8::Integer; using v8::Isolate; using v8::Just; using v8::Local; +using v8::LocalVector; using v8::Maybe; using v8::MaybeLocal; using v8::Nothing; @@ -735,7 +736,7 @@ Local SyncProcessRunner::BuildOutputArray() { CHECK(!stdio_pipes_.empty()); EscapableHandleScope scope(env()->isolate()); - MaybeStackBuffer, 8> js_output(stdio_pipes_.size()); + LocalVector js_output(env()->isolate(), stdio_pipes_.size()); for (uint32_t i = 0; i < stdio_pipes_.size(); i++) { SyncProcessStdioPipe* h = stdio_pipes_[i].get(); @@ -746,7 +747,7 @@ Local SyncProcessRunner::BuildOutputArray() { } return scope.Escape( - Array::New(env()->isolate(), js_output.out(), js_output.length())); + Array::New(env()->isolate(), js_output.data(), js_output.size())); } Maybe SyncProcessRunner::ParseOptions(Local js_value) { diff --git a/src/util-inl.h b/src/util-inl.h index 9dd61a98933685..a61eaa019f399b 100644 --- a/src/util-inl.h +++ b/src/util-inl.h @@ -345,14 +345,13 @@ v8::MaybeLocal ToV8Value(v8::Local context, if (isolate == nullptr) isolate = context->GetIsolate(); v8::EscapableHandleScope handle_scope(isolate); - MaybeStackBuffer, 128> arr(vec.size()); - arr.SetLength(vec.size()); + v8::LocalVector arr(isolate, vec.size()); for (size_t i = 0; i < vec.size(); ++i) { if (!ToV8Value(context, vec[i], isolate).ToLocal(&arr[i])) return v8::MaybeLocal(); } - return handle_scope.Escape(v8::Array::New(isolate, arr.out(), arr.length())); + return handle_scope.Escape(v8::Array::New(isolate, arr.data(), arr.size())); } template diff --git a/src/util.h b/src/util.h index a6da8720c499df..0e3b521a063908 100644 --- a/src/util.h +++ b/src/util.h @@ -784,6 +784,7 @@ constexpr inline bool IsBigEndian() { static_assert(IsLittleEndian() || IsBigEndian(), "Node.js does not support mixed-endian systems"); +// TODO(@jasnell): Can this be implement in terms of v8::LocalVector instead? class SlicedArguments : public MaybeStackBuffer> { public: inline explicit SlicedArguments(