Skip to content

Commit b736028

Browse files
committed
src: use LocalVector in more places
PR-URL: #56457 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 9400eae commit b736028

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/crypto/crypto_util.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,8 @@ void ThrowCryptoError(Environment* env,
547547

548548
class CipherPushContext {
549549
public:
550-
inline explicit CipherPushContext(Environment* env) : env_(env) {}
550+
inline explicit CipherPushContext(Environment* env)
551+
: list_(env->isolate()), env_(env) {}
551552

552553
inline void push_back(const char* str) {
553554
list_.emplace_back(OneByteString(env_->isolate(), str));
@@ -558,7 +559,7 @@ class CipherPushContext {
558559
}
559560

560561
private:
561-
std::vector<v8::Local<v8::Value>> list_;
562+
v8::LocalVector<v8::Value> list_;
562563
Environment* env_;
563564
};
564565

src/env.cc

+2-5
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ bool AsyncHooks::pop_async_context(double async_id) {
176176
}
177177
#endif
178178
native_execution_async_resources_.resize(offset);
179-
if (native_execution_async_resources_.size() <
180-
native_execution_async_resources_.capacity() / 2 &&
181-
native_execution_async_resources_.size() > 16) {
182-
native_execution_async_resources_.shrink_to_fit();
183-
}
179+
native_execution_async_resources_.shrink_to_fit();
184180
}
185181

186182
if (js_execution_async_resources()->Length() > offset) [[unlikely]] {
@@ -1694,6 +1690,7 @@ AsyncHooks::AsyncHooks(Isolate* isolate, const SerializeInfo* info)
16941690
fields_(isolate, kFieldsCount, MAYBE_FIELD_PTR(info, fields)),
16951691
async_id_fields_(
16961692
isolate, kUidFieldsCount, MAYBE_FIELD_PTR(info, async_id_fields)),
1693+
native_execution_async_resources_(isolate),
16971694
info_(info) {
16981695
HandleScope handle_scope(isolate);
16991696
if (info == nullptr) {

src/env.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,16 @@ class AsyncHooks : public MemoryRetainer {
401401
void grow_async_ids_stack();
402402

403403
v8::Global<v8::Array> js_execution_async_resources_;
404-
std::vector<v8::Local<v8::Object>> native_execution_async_resources_;
404+
405+
// TODO(@jasnell): Note that this is technically illegal use of
406+
// v8::Locals which should be kept on the stack. Here, the entries
407+
// in this object grows and shrinks with the C stack, and entries
408+
// will be in the right handle scopes, but v8::Locals are supposed
409+
// to remain on the stack and not the heap. For general purposes
410+
// this *should* be ok but may need to be looked at further should
411+
// v8 become stricter in the future about v8::Locals being held in
412+
// the stack.
413+
v8::LocalVector<v8::Object> native_execution_async_resources_;
405414

406415
// Non-empty during deserialization
407416
const SerializeInfo* info_ = nullptr;

0 commit comments

Comments
 (0)