src: add missing qualifiers to env.cc

PR-URL: https://github.com/nodejs/node/pull/56062
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Yagiz Nizipli 2024-12-03 09:05:50 -05:00 committed by GitHub
parent 742ea1c85f
commit ebc179d68b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 29 deletions

View File

@ -87,13 +87,13 @@ void AsyncHooks::ResetPromiseHooks(Local<Function> init,
js_promise_hooks_[3].Reset(env()->isolate(), resolve); js_promise_hooks_[3].Reset(env()->isolate(), resolve);
} }
Local<Array> AsyncHooks::GetPromiseHooks(Isolate* isolate) { Local<Array> AsyncHooks::GetPromiseHooks(Isolate* isolate) const {
std::vector<Local<Value>> values; v8::LocalVector<Value> values(isolate, js_promise_hooks_.size());
for (size_t i = 0; i < js_promise_hooks_.size(); ++i) { for (size_t i = 0; i < js_promise_hooks_.size(); ++i) {
if (js_promise_hooks_[i].IsEmpty()) { if (js_promise_hooks_[i].IsEmpty()) {
values.push_back(Undefined(isolate)); values[i] = Undefined(isolate);
} else { } else {
values.push_back(js_promise_hooks_[i].Get(isolate)); values[i] = js_promise_hooks_[i].Get(isolate);
} }
} }
return Array::New(isolate, values.data(), values.size()); return Array::New(isolate, values.data(), values.size());
@ -236,13 +236,10 @@ void Environment::TrackContext(Local<Context> context) {
void Environment::UntrackContext(Local<Context> context) { void Environment::UntrackContext(Local<Context> context) {
HandleScope handle_scope(isolate_); HandleScope handle_scope(isolate_);
contexts_.erase(std::remove_if(contexts_.begin(), std::erase_if(contexts_, [&](auto&& el) { return el.IsEmpty(); });
contexts_.end(),
[&](auto&& el) { return el.IsEmpty(); }),
contexts_.end());
for (auto it = contexts_.begin(); it != contexts_.end(); it++) { for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
Local<Context> saved_context = PersistentToLocal::Weak(isolate_, *it); if (Local<Context> saved_context = PersistentToLocal::Weak(isolate_, *it);
if (saved_context == context) { saved_context == context) {
it->Reset(); it->Reset();
contexts_.erase(it); contexts_.erase(it);
break; break;
@ -351,9 +348,11 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
#undef VS #undef VS
#undef VP #undef VP
for (size_t i = 0; i < AsyncWrap::PROVIDERS_LENGTH; i++) info.primitive_values.reserve(info.primitive_values.size() +
AsyncWrap::PROVIDERS_LENGTH);
for (size_t i = 0; i < AsyncWrap::PROVIDERS_LENGTH; i++) {
info.primitive_values.push_back(creator->AddData(async_wrap_provider(i))); info.primitive_values.push_back(creator->AddData(async_wrap_provider(i)));
}
uint32_t id = 0; uint32_t id = 0;
#define VM(PropertyName) V(PropertyName##_binding_template, ObjectTemplate) #define VM(PropertyName) V(PropertyName##_binding_template, ObjectTemplate)
#define V(PropertyName, TypeName) \ #define V(PropertyName, TypeName) \
@ -375,7 +374,7 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) { void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) {
size_t i = 0; size_t i = 0;
v8::Isolate::Scope isolate_scope(isolate_); Isolate::Scope isolate_scope(isolate_);
HandleScope handle_scope(isolate_); HandleScope handle_scope(isolate_);
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) { if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
@ -721,9 +720,8 @@ void Environment::TryLoadAddon(
std::string Environment::GetCwd(const std::string& exec_path) { std::string Environment::GetCwd(const std::string& exec_path) {
char cwd[PATH_MAX_BYTES]; char cwd[PATH_MAX_BYTES];
size_t size = PATH_MAX_BYTES; size_t size = PATH_MAX_BYTES;
const int err = uv_cwd(cwd, &size);
if (err == 0) { if (uv_cwd(cwd, &size) == 0) {
CHECK_GT(size, 0); CHECK_GT(size, 0);
return cwd; return cwd;
} }
@ -769,7 +767,7 @@ std::string Environment::GetExecPath(const std::vector<std::string>& argv) {
std::string exec_path; std::string exec_path;
if (uv_exepath(exec_path_buf, &exec_path_len) == 0) { if (uv_exepath(exec_path_buf, &exec_path_len) == 0) {
exec_path = std::string(exec_path_buf, exec_path_len); exec_path = std::string(exec_path_buf, exec_path_len);
} else if (argv.size() > 0) { } else if (!argv.empty()) {
exec_path = argv[0]; exec_path = argv[0];
} }
@ -1239,7 +1237,8 @@ void Environment::StartProfilerIdleNotifier() {
} }
void Environment::PrintSyncTrace() const { void Environment::PrintSyncTrace() const {
if (!trace_sync_io_) return; if (!trace_sync_io_) [[likely]]
return;
HandleScope handle_scope(isolate()); HandleScope handle_scope(isolate());
@ -1314,7 +1313,7 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) {
at_exit_functions_.push_front(ExitCallback{cb, arg}); at_exit_functions_.push_front(ExitCallback{cb, arg});
} }
Maybe<bool> Environment::CheckUnsettledTopLevelAwait() { Maybe<bool> Environment::CheckUnsettledTopLevelAwait() const {
HandleScope scope(isolate_); HandleScope scope(isolate_);
Local<Context> ctx = context(); Local<Context> ctx = context();
Local<Value> value; Local<Value> value;
@ -1516,7 +1515,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
int64_t expiry_ms = int64_t expiry_ms =
ret.ToLocalChecked()->IntegerValue(env->context()).FromJust(); ret.ToLocalChecked()->IntegerValue(env->context()).FromJust();
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(handle); auto* h = reinterpret_cast<uv_handle_t*>(handle);
if (expiry_ms != 0) { if (expiry_ms != 0) {
int64_t duration_ms = int64_t duration_ms =
@ -1582,7 +1581,6 @@ Local<Value> Environment::GetNow() {
uint64_t now = GetNowUint64(); uint64_t now = GetNowUint64();
if (now <= 0xffffffff) if (now <= 0xffffffff)
return Integer::NewFromUnsigned(isolate(), static_cast<uint32_t>(now)); return Integer::NewFromUnsigned(isolate(), static_cast<uint32_t>(now));
else
return Number::New(isolate(), static_cast<double>(now)); return Number::New(isolate(), static_cast<double>(now));
} }
@ -1642,8 +1640,8 @@ void Environment::CollectUVExceptionInfo(Local<Value> object,
message = uv_strerror(errorno); message = uv_strerror(errorno);
} }
node::CollectExceptionInfo(this, obj, errorno, err_string, CollectExceptionInfo(
syscall, message, path, dest); this, obj, errorno, err_string, syscall, message, path, dest);
} }
ImmediateInfo::ImmediateInfo(Isolate* isolate, const SerializeInfo* info) ImmediateInfo::ImmediateInfo(Isolate* isolate, const SerializeInfo* info)
@ -1973,7 +1971,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
EmbedderGraph* graph, EmbedderGraph* graph,
void* data) { void* data) {
MemoryTracker tracker(isolate, graph); MemoryTracker tracker(isolate, graph);
Environment* env = static_cast<Environment*>(data); auto* env = static_cast<Environment*>(data);
// Start traversing embedder objects from the root Environment object. // Start traversing embedder objects from the root Environment object.
tracker.Track(env); tracker.Track(env);
} }
@ -2035,7 +2033,7 @@ void Environment::TracePromises(PromiseHookType type,
size_t Environment::NearHeapLimitCallback(void* data, size_t Environment::NearHeapLimitCallback(void* data,
size_t current_heap_limit, size_t current_heap_limit,
size_t initial_heap_limit) { size_t initial_heap_limit) {
Environment* env = static_cast<Environment*>(data); auto* env = static_cast<Environment*>(data);
Debug(env, Debug(env,
DebugCategory::DIAGNOSTICS, DebugCategory::DIAGNOSTICS,
@ -2081,8 +2079,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
DebugCategory::DIAGNOSTICS, DebugCategory::DIAGNOSTICS,
"Estimated available memory=%" PRIu64 ", " "Estimated available memory=%" PRIu64 ", "
"estimated overhead=%" PRIu64 "\n", "estimated overhead=%" PRIu64 "\n",
static_cast<uint64_t>(available), available,
static_cast<uint64_t>(estimated_overhead)); estimated_overhead);
// This might be hit when the snapshot is being taken in another // This might be hit when the snapshot is being taken in another
// NearHeapLimitCallback invocation. // NearHeapLimitCallback invocation.

View File

@ -329,7 +329,7 @@ class AsyncHooks : public MemoryRetainer {
v8::Local<v8::Function> resolve); v8::Local<v8::Function> resolve);
// Used for testing since V8 doesn't provide API for retrieving configured // Used for testing since V8 doesn't provide API for retrieving configured
// JS promise hooks. // JS promise hooks.
v8::Local<v8::Array> GetPromiseHooks(v8::Isolate* isolate); v8::Local<v8::Array> GetPromiseHooks(v8::Isolate* isolate) const;
inline v8::Local<v8::String> provider_string(int idx); inline v8::Local<v8::String> provider_string(int idx);
inline void no_force_checks(); inline void no_force_checks();
@ -848,7 +848,7 @@ class Environment final : public MemoryRetainer {
void AtExit(void (*cb)(void* arg), void* arg); void AtExit(void (*cb)(void* arg), void* arg);
void RunAtExitCallbacks(); void RunAtExitCallbacks();
v8::Maybe<bool> CheckUnsettledTopLevelAwait(); v8::Maybe<bool> CheckUnsettledTopLevelAwait() const;
void RunWeakRefCleanup(); void RunWeakRefCleanup();
v8::MaybeLocal<v8::Value> RunSnapshotSerializeCallback() const; v8::MaybeLocal<v8::Value> RunSnapshotSerializeCallback() const;