GeezerVison is showing github.com — src: add v8::Local specialization for MaybeStackBuffer · nodejs/node@613be79
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/api/callback.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,7 +245,7 @@ MaybeLocal<Value> InternalMakeCallback(Environment* env, | 245 | 245 |
| 246 | 246 | Local<Context> context = env->context(); | 247 | 247 | if (use_async_hooks_trampoline) { | 248 | | - MaybeStackBuffer<Local<Value>, 16> args(3 + argc); | | 248 | + MaybeStackBuffer<Value, 16> args(env->isolate(), 3 + argc); | 249 | 249 | args[0] = Number::New(env->isolate(), asyncContext.async_id); | 250 | 250 | args[1] = resource; | 251 | 251 | args[2] = callback; | |
Collapse file Copy file name to clipboardExpand all lines: src/cares_wrap.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -201,12 +201,12 @@ Local<Array> AddrTTLToArray( | 201 | 201 | Environment* env, | 202 | 202 | const T* addrttls, | 203 | 203 | size_t naddrttls) { | 204 | | - MaybeStackBuffer<Local<Value>, 8> ttls(naddrttls); | | 204 | + MaybeStackBuffer<Value, 8> ttls(env->isolate(), naddrttls); | 205 | 205 | for (size_t i = 0; i < naddrttls; i++) { | 206 | 206 | ttls[i] = Integer::NewFromUnsigned(env->isolate(), addrttls[i].ttl); | 207 | 207 | } | 208 | 208 |
| 209 | | - return Array::New(env->isolate(), ttls.out(), naddrttls); | | 209 | + return ttls.ToArray(); | 210 | 210 | } | 211 | 211 |
| 212 | 212 | int GetAnswerCountForTTLBuffer(const unsigned char* buf, int len) { | |
Collapse file Copy file name to clipboardExpand all lines: src/crypto/crypto_tls.cc +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,7 +41,6 @@ using ncrypto::MarkPopErrorOnReturn; | 41 | 41 | using ncrypto::SSLPointer; | 42 | 42 | using ncrypto::SSLSessionPointer; | 43 | 43 | using ncrypto::X509Pointer; | 44 | | -using v8::Array; | 45 | 44 | using v8::ArrayBuffer; | 46 | 45 | using v8::ArrayBufferView; | 47 | 46 | using v8::BackingStore; | @@ -1956,7 +1955,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) { | 1956 | 1955 | SSL* ssl = w->ssl_.get(); | 1957 | 1956 | int nsig = SSL_get_shared_sigalgs(ssl, 0, nullptr, nullptr, nullptr, nullptr, | 1958 | 1957 | nullptr); | 1959 | | - MaybeStackBuffer<Local<Value>, 16> ret_arr(nsig); | | 1958 | + MaybeStackBuffer<Value, 16> ret_arr(env->isolate(), nsig); | 1960 | 1959 |
| 1961 | 1960 | for (int i = 0; i < nsig; i++) { | 1962 | 1961 | int hash_nid; | @@ -2023,8 +2022,7 @@ void TLSWrap::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) { | 2023 | 2022 | ret_arr[i] = OneByteString(env->isolate(), sig_with_md); | 2024 | 2023 | } | 2025 | 2024 |
| 2026 | | - args.GetReturnValue().Set( | 2027 | | - Array::New(env->isolate(), ret_arr.out(), ret_arr.length())); | | 2025 | + args.GetReturnValue().Set(ret_arr.ToArray()); | 2028 | 2026 | } | 2029 | 2027 |
| 2030 | 2028 | void TLSWrap::ExportKeyingMaterial(const FunctionCallbackInfo<Value>& args) { | |
Collapse file Copy file name to clipboardExpand all lines: src/js_stream.cc +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,7 +11,6 @@ namespace node { | 11 | 11 |
| 12 | 12 | using errors::TryCatchScope; | 13 | 13 |
| 14 | | -using v8::Array; | 15 | 14 | using v8::Context; | 16 | 15 | using v8::FunctionCallbackInfo; | 17 | 16 | using v8::FunctionTemplate; | @@ -119,17 +118,14 @@ int JSStream::DoWrite(WriteWrap* w, | 119 | 118 |
| 120 | 119 | int value_int = UV_EPROTO; | 121 | 120 |
| 122 | | - MaybeStackBuffer<Local<Value>, 16> bufs_arr(count); | | 121 | + MaybeStackBuffer<Value, 16> bufs_arr(env()->isolate(), count); | 123 | 122 | for (size_t i = 0; i < count; i++) { | 124 | 123 | if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&bufs_arr[i])) { | 125 | 124 | return value_int; | 126 | 125 | } | 127 | 126 | } | 128 | 127 |
| 129 | | - Local<Value> argv[] = { | 130 | | - w->object(), | 131 | | - Array::New(env()->isolate(), bufs_arr.out(), count) | 132 | | - }; | | 128 | + Local<Value> argv[] = {w->object(), bufs_arr.ToArray()}; | 133 | 129 |
| 134 | 130 | TryCatchScope try_catch(env()); | 135 | 131 | Local<Value> value; | |
Collapse file Copy file name to clipboardExpand all lines: src/js_udp_wrap.cc +4-5Lines changed: 4 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 11 | 11 | namespace node { | 12 | 12 |
| 13 | 13 | using errors::TryCatchScope; | 14 | | -using v8::Array; | 15 | 14 | using v8::Context; | 16 | 15 | using v8::FunctionCallbackInfo; | 17 | 16 | using v8::FunctionTemplate; | @@ -98,7 +97,7 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs, | 98 | 97 | int64_t value_int = JS_EXCEPTION_PENDING; | 99 | 98 | size_t total_len = 0; | 100 | 99 |
| 101 | | - MaybeStackBuffer<Local<Value>, 16> buffers(nbufs); | | 100 | + MaybeStackBuffer<Value, 16> buffers(env()->isolate(), nbufs); | 102 | 101 | for (size_t i = 0; i < nbufs; i++) { | 103 | 102 | if (!Buffer::Copy(env(), bufs[i].base, bufs[i].len).ToLocal(&buffers[i])) { | 104 | 103 | return value_int; | @@ -110,9 +109,9 @@ ssize_t JSUDPWrap::Send(uv_buf_t* bufs, | 110 | 109 | if (!AddressToJS(env(), addr).ToLocal(&address)) return value_int; | 111 | 110 |
| 112 | 111 | Local<Value> args[] = { | 113 | | - listener()->CreateSendWrap(total_len)->object(), | 114 | | - Array::New(env()->isolate(), buffers.out(), nbufs), | 115 | | - address, | | 112 | + listener()->CreateSendWrap(total_len)->object(), | | 113 | + buffers.ToArray(), | | 114 | + address, | 116 | 115 | }; | 117 | 116 |
| 118 | 117 | if (!MakeCallback(env()->onwrite_string(), arraysize(args), args) | |
Collapse file Copy file name to clipboardExpand all lines: src/node_concepts.h +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 |
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | 5 | 5 |
| | 6 | +#include <v8.h> | 6 | 7 | #include <concepts> | 7 | 8 | #include <limits> | 8 | 9 | #include <type_traits> | @@ -32,6 +33,12 @@ concept StandardCharType = | 32 | 33 | template <typename T> | 33 | 34 | concept IsCallable = std::is_function<T>::value || requires { &T::operator(); }; | 34 | 35 |
| | 36 | +// Types that can reside on V8's managed heap (v8::Value, v8::Object, etc.). | | 37 | +// Used to select the MaybeStackBuffer specialization that holds handles in a | | 38 | +// v8::LocalVector instead of malloc'd memory. | | 39 | +template <typename T> | | 40 | +concept V8Type = std::is_base_of_v<v8::Data, T>; | | 41 | + | 35 | 42 | } // namespace node | 36 | 43 |
| 37 | 44 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
Collapse file Copy file name to clipboardExpand all lines: src/node_dir.cc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -206,7 +206,7 @@ static MaybeLocal<Array> DirentListToArray(Environment* env, | 206 | 206 | uv_dirent_t* ents, | 207 | 207 | int num, | 208 | 208 | enum encoding encoding) { | 209 | | - MaybeStackBuffer<Local<Value>, 64> entries(num * 2); | | 209 | + MaybeStackBuffer<Value, 64> entries(env->isolate(), num * 2); | 210 | 210 |
| 211 | 211 | // Return an array of all read filenames. | 212 | 212 | int j = 0; | @@ -222,7 +222,8 @@ static MaybeLocal<Array> DirentListToArray(Environment* env, | 222 | 222 | entries[j++] = Integer::New(env->isolate(), ents[i].type); | 223 | 223 | } | 224 | 224 |
| 225 | | - return Array::New(env->isolate(), entries.out(), j); | | 225 | + CHECK_EQ(j, num * 2); | | 226 | + return entries.ToArray(); | 226 | 227 | } | 227 | 228 |
| 228 | 229 | static void AfterDirRead(uv_fs_t* req) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_env_var.cc +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -201,7 +201,7 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const { | 201 | 201 | auto cleanup = OnScopeLeave([&]() { uv_os_free_environ(items, count); }); | 202 | 202 | CHECK_EQ(uv_os_environ(&items, &count), 0); | 203 | 203 |
| 204 | | - MaybeStackBuffer<Local<Value>, 256> env_v(count); | | 204 | + MaybeStackBuffer<Value, 256> env_v(isolate, count); | 205 | 205 | int env_v_index = 0; | 206 | 206 | for (int i = 0; i < count; i++) { | 207 | 207 | #ifdef _WIN32 | @@ -216,7 +216,10 @@ MaybeLocal<Array> RealEnvStore::Enumerate(Isolate* isolate) const { | 216 | 216 | env_v[env_v_index++] = str; | 217 | 217 | } | 218 | 218 |
| 219 | | - return Array::New(isolate, env_v.out(), env_v_index); | | 219 | + // We're possibly not filling the entire buffer. | | 220 | + CHECK_LE(env_v_index, count); | | 221 | + env_v.SetLength(env_v_index); | | 222 | + return env_v.ToArray(); | 220 | 223 | } | 221 | 224 |
| 222 | 225 | std::shared_ptr<KVStore> KVStore::Clone(Isolate* isolate) const { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_http2.cc +9-8Lines changed: 9 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1585,8 +1585,8 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { | 1585 | 1585 | // this way for performance reasons (it's faster to generate and pass an | 1586 | 1586 | // array than it is to generate and pass the object). | 1587 | 1587 |
| 1588 | | - MaybeStackBuffer<Local<Value>, 64> headers_v(stream->headers_count() * 2); | 1589 | | - MaybeStackBuffer<Local<Value>, 32> sensitive_v(stream->headers_count()); | | 1588 | + MaybeStackBuffer<Value, 64> headers_v(isolate, stream->headers_count() * 2); | | 1589 | + MaybeStackBuffer<Value, 32> sensitive_v(isolate, stream->headers_count()); | 1590 | 1590 | size_t sensitive_count = 0; | 1591 | 1591 |
| 1592 | 1592 | stream->TransferHeaders([&](const Http2Header& header, size_t i) { | @@ -1603,13 +1603,14 @@ void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) { | 1603 | 1603 | stream->retained_headers_length_ += stream->current_headers_length_; | 1604 | 1604 | stream->current_headers_length_ = 0; | 1605 | 1605 |
| | 1606 | + sensitive_v.SetLength(sensitive_count); | 1606 | 1607 | Local<Value> args[] = { | 1607 | | - stream->object(), | 1608 | | - Integer::New(isolate, id), | 1609 | | - Integer::New(isolate, stream->headers_category()), | 1610 | | - Integer::New(isolate, frame->hd.flags), | 1611 | | - Array::New(isolate, headers_v.out(), headers_v.length()), | 1612 | | - Array::New(isolate, sensitive_v.out(), sensitive_count), | | 1608 | + stream->object(), | | 1609 | + Integer::New(isolate, id), | | 1610 | + Integer::New(isolate, stream->headers_category()), | | 1611 | + Integer::New(isolate, frame->hd.flags), | | 1612 | + headers_v.ToArray(), | | 1613 | + sensitive_v.ToArray(), | 1613 | 1614 | }; | 1614 | 1615 | MakeCallback(env()->http2session_on_headers_function(), | 1615 | 1616 | arraysize(args), args); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_messaging.cc +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1093,7 +1093,7 @@ void MessagePort::PostMessage(const FunctionCallbackInfo<Value>& args) { | 1093 | 1093 | "MessagePort.postMessage"); | 1094 | 1094 | } | 1095 | 1095 |
| 1096 | | - TransferList transfer_list; | | 1096 | + TransferList transfer_list(env->isolate()); | 1097 | 1097 | if (!GetTransferList(env, context, args[1], &transfer_list)) { | 1098 | 1098 | return; | 1099 | 1099 | } | @@ -1607,7 +1607,7 @@ static void StructuredClone(const FunctionCallbackInfo<Value>& args) { | 1607 | 1607 |
| 1608 | 1608 | Local<Value> value = args[0]; | 1609 | 1609 |
| 1610 | | - TransferList transfer_list; | | 1610 | + TransferList transfer_list(isolate); | 1611 | 1611 | Local<Object> options = args[1].As<Object>(); | 1612 | 1612 | Local<Value> transfer_list_v; | 1613 | 1613 | if (!options->Get(context, env->transfer_string()) | |
|