src: add missing qualifiers to env.cc · nodejs/node@a32fa30
@@ -87,13 +87,13 @@ void AsyncHooks::ResetPromiseHooks(Local<Function> init,
8787 js_promise_hooks_[3].Reset(env()->isolate(), resolve);
8888}
898990-Local<Array> AsyncHooks::GetPromiseHooks(Isolate* isolate) {
91-std::vector<Local<Value>> values;
90+Local<Array> AsyncHooks::GetPromiseHooks(Isolate* isolate) const {
91+v8::LocalVector<Value> values(isolate, js_promise_hooks_.size());
9292for (size_t i = 0; i < js_promise_hooks_.size(); ++i) {
9393if (js_promise_hooks_[i].IsEmpty()) {
94- values.push_back(Undefined(isolate));
94+ values[i] = Undefined(isolate);
9595 } else {
96- values.push_back(js_promise_hooks_[i].Get(isolate));
96+ values[i] = js_promise_hooks_[i].Get(isolate);
9797 }
9898 }
9999return Array::New(isolate, values.data(), values.size());
@@ -236,13 +236,10 @@ void Environment::TrackContext(Local<Context> context) {
236236237237void Environment::UntrackContext(Local<Context> context) {
238238 HandleScope handle_scope(isolate_);
239- contexts_.erase(std::remove_if(contexts_.begin(),
240- contexts_.end(),
241- [&](auto&& el) { return el.IsEmpty(); }),
242- contexts_.end());
239+std::erase_if(contexts_, [&](auto&& el) { return el.IsEmpty(); });
243240for (auto it = contexts_.begin(); it != contexts_.end(); it++) {
244- Local<Context> saved_context = PersistentToLocal::Weak(isolate_, *it);
245-if (saved_context == context) {
241+if (Local<Context> saved_context = PersistentToLocal::Weak(isolate_, *it);
242+ saved_context == context) {
246243 it->Reset();
247244 contexts_.erase(it);
248245break;
@@ -351,9 +348,11 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
351348#undef VS
352349#undef VP
353350354-for (size_t i = 0; i < AsyncWrap::PROVIDERS_LENGTH; i++)
351+ info.primitive_values.reserve(info.primitive_values.size() +
352+ AsyncWrap::PROVIDERS_LENGTH);
353+for (size_t i = 0; i < AsyncWrap::PROVIDERS_LENGTH; i++) {
355354 info.primitive_values.push_back(creator->AddData(async_wrap_provider(i)));
356-355+ }
357356uint32_t id = 0;
358357#define VM(PropertyName) V(PropertyName##_binding_template, ObjectTemplate)
359358#define V(PropertyName, TypeName) \
@@ -375,7 +374,7 @@ IsolateDataSerializeInfo IsolateData::Serialize(SnapshotCreator* creator) {
375374void IsolateData::DeserializeProperties(const IsolateDataSerializeInfo* info) {
376375size_t i = 0;
377376378-v8::Isolate::Scope isolate_scope(isolate_);
377+ Isolate::Scope isolate_scope(isolate_);
379378 HandleScope handle_scope(isolate_);
380379381380if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
@@ -732,9 +731,8 @@ void Environment::TryLoadAddon(
732731std::string Environment::GetCwd(const std::string& exec_path) {
733732char cwd[PATH_MAX_BYTES];
734733size_t size = PATH_MAX_BYTES;
735-const int err = uv_cwd(cwd, &size);
736734737-if (err == 0) {
735+if (uv_cwd(cwd, &size) == 0) {
738736CHECK_GT(size, 0);
739737return cwd;
740738 }
@@ -780,7 +778,7 @@ std::string Environment::GetExecPath(const std::vector<std::string>& argv) {
780778 std::string exec_path;
781779if (uv_exepath(exec_path_buf, &exec_path_len) == 0) {
782780 exec_path = std::string(exec_path_buf, exec_path_len);
783- } else if (argv.size() > 0) {
781+ } else if (!argv.empty()) {
784782 exec_path = argv[0];
785783 }
786784@@ -1250,7 +1248,8 @@ void Environment::StartProfilerIdleNotifier() {
12501248}
1251124912521250void Environment::PrintSyncTrace() const {
1253-if (!trace_sync_io_) return;
1251+if (!trace_sync_io_) [[likely]]
1252+return;
1254125312551254 HandleScope handle_scope(isolate());
12561255@@ -1325,7 +1324,7 @@ void Environment::AtExit(void (*cb)(void* arg), void* arg) {
13251324 at_exit_functions_.push_front(ExitCallback{cb, arg});
13261325}
132713261328-Maybe<bool> Environment::CheckUnsettledTopLevelAwait() {
1327+Maybe<bool> Environment::CheckUnsettledTopLevelAwait() const {
13291328 HandleScope scope(isolate_);
13301329 Local<Context> ctx = context();
13311330 Local<Value> value;
@@ -1527,7 +1526,7 @@ void Environment::RunTimers(uv_timer_t* handle) {
15271526int64_t expiry_ms =
15281527 ret.ToLocalChecked()->IntegerValue(env->context()).FromJust();
152915281530-uv_handle_t* h = reinterpret_cast<uv_handle_t*>(handle);
1529+auto* h = reinterpret_cast<uv_handle_t*>(handle);
1531153015321531if (expiry_ms != 0) {
15331532int64_t duration_ms =
@@ -1593,8 +1592,7 @@ Local<Value> Environment::GetNow() {
15931592uint64_t now = GetNowUint64();
15941593if (now <= 0xffffffff)
15951594return Integer::NewFromUnsigned(isolate(), static_cast<uint32_t>(now));
1596-else
1597-return Number::New(isolate(), static_cast<double>(now));
1595+return Number::New(isolate(), static_cast<double>(now));
15981596}
1599159716001598void CollectExceptionInfo(Environment* env,
@@ -1653,8 +1651,8 @@ void Environment::CollectUVExceptionInfo(Local<Value> object,
16531651 message = uv_strerror(errorno);
16541652 }
165516531656-node::CollectExceptionInfo(this, obj, errorno, err_string,
1657- syscall, message, path, dest);
1654+CollectExceptionInfo(
1655+this, obj, errorno, err_string, syscall, message, path, dest);
16581656}
1659165716601658ImmediateInfo::ImmediateInfo(Isolate* isolate, const SerializeInfo* info)
@@ -1984,7 +1982,7 @@ void Environment::BuildEmbedderGraph(Isolate* isolate,
19841982 EmbedderGraph* graph,
19851983void* data) {
19861984 MemoryTracker tracker(isolate, graph);
1987-Environment* env = static_cast<Environment*>(data);
1985+auto* env = static_cast<Environment*>(data);
19881986// Start traversing embedder objects from the root Environment object.
19891987 tracker.Track(env);
19901988}
@@ -2046,7 +2044,7 @@ void Environment::TracePromises(PromiseHookType type,
20462044size_t Environment::NearHeapLimitCallback(void* data,
20472045size_t current_heap_limit,
20482046size_t initial_heap_limit) {
2049-Environment* env = static_cast<Environment*>(data);
2047+auto* env = static_cast<Environment*>(data);
2050204820512049Debug(env,
20522050 DebugCategory::DIAGNOSTICS,
@@ -2092,8 +2090,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
20922090 DebugCategory::DIAGNOSTICS,
20932091"Estimated available memory=%" PRIu64 ", "
20942092"estimated overhead=%" PRIu64 "\n",
2095-static_cast<uint64_t>(available),
2096-static_cast<uint64_t>(estimated_overhead));
2093+ available,
2094+ estimated_overhead);
2097209520982096// This might be hit when the snapshot is being taken in another
20992097// NearHeapLimitCallback invocation.