Skip to content

Commit d384a10

Browse files
jasnellRafaelGSS
authored andcommitted
src: use LocalVector in more places
PR-URL: #56457 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 2d67129 commit d384a10

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/crypto/crypto_util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ void TestFipsCrypto(const v8::FunctionCallbackInfo<v8::Value>& args);
620620

621621
class CipherPushContext {
622622
public:
623-
inline explicit CipherPushContext(Environment* env) : env_(env) {}
623+
inline explicit CipherPushContext(Environment* env)
624+
: list_(env->isolate()), env_(env) {}
624625

625626
inline void push_back(const char* str) {
626627
list_.emplace_back(OneByteString(env_->isolate(), str));
@@ -631,7 +632,7 @@ class CipherPushContext {
631632
}
632633

633634
private:
634-
std::vector<v8::Local<v8::Value>> list_;
635+
v8::LocalVector<v8::Value> list_;
635636
Environment* env_;
636637
};
637638

src/env.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ bool AsyncHooks::pop_async_context(double async_id) {
173173
}
174174
#endif
175175
native_execution_async_resources_.resize(offset);
176-
if (native_execution_async_resources_.size() <
177-
native_execution_async_resources_.capacity() / 2 &&
178-
native_execution_async_resources_.size() > 16) {
179-
native_execution_async_resources_.shrink_to_fit();
180-
}
176+
native_execution_async_resources_.shrink_to_fit();
181177
}
182178

183179
if (UNLIKELY(js_execution_async_resources()->Length() > offset)) {
@@ -1610,6 +1606,7 @@ AsyncHooks::AsyncHooks(Isolate* isolate, const SerializeInfo* info)
16101606
fields_(isolate, kFieldsCount, MAYBE_FIELD_PTR(info, fields)),
16111607
async_id_fields_(
16121608
isolate, kUidFieldsCount, MAYBE_FIELD_PTR(info, async_id_fields)),
1609+
native_execution_async_resources_(isolate),
16131610
info_(info) {
16141611
HandleScope handle_scope(isolate);
16151612
if (info == nullptr) {

src/env.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,16 @@ class AsyncHooks : public MemoryRetainer {
404404
void grow_async_ids_stack();
405405

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

409418
// Non-empty during deserialization
410419
const SerializeInfo* info_ = nullptr;

0 commit comments

Comments
 (0)