GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: cut small costs in node::MakeCallback by nigrosimone · Pull Request #66395 · nodejs/node

src: cut small costs in node::MakeCallback #66395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nodejs-github-bot merged 1 commit into nodejs:main from nigrosimone:callback-context-scope
Oct 20, 2026
+25 −7
Merged

src: cut small costs in node::MakeCallback #66395

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
8acef08
src: cut small costs in node::MakeCallback
nigrosimone Sep 29, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 10 additions & 1 deletion 11 src/api/callback.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "node.h"
#include "v8.h"

#include <optional>

namespace node {

using v8::Context;
Expand Down Expand Up @@ -349,7 +351,14 @@ MaybeLocal<Value> InternalMakeCallback(Isolate* isolate,
}
Environment* env = Environment::GetCurrent(context);
CHECK_NOT_NULL(env);
Context::Scope context_scope(env->context());
// Entering the context changes nothing when it is already the entered and
// the current one, which is the common case for addons.
Local<Context> env_context = env->context();
std::optional<Context::Scope> context_scope;
if (isolate->GetEnteredOrMicrotaskContext() != env_context ||
isolate->GetCurrentContext() != env_context) {
context_scope.emplace(env_context);
}
MaybeLocal<Value> ret = InternalMakeCallback(
env, recv, recv, callback, argc, argv, asyncContext, context_frame);
if (ret.IsEmpty() && env->async_callback_scope_depth() == 0) {
Expand Down
3 changes: 2 additions & 1 deletion 3 src/async_context_frame.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void set(Isolate* isolate, Local<Value> value) {
// but sometimes (such as enterWith) a direct exchange is needed.
Local<Value> exchange(Environment* env, Local<Value> value) {
auto prior = current(env->isolate());
set(env, value);
// Usually the frame does not change, and there is nothing to set.
if (prior != value) set(env, value);
return prior;
}

Expand Down
16 changes: 12 additions & 4 deletions 16 src/env.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void Environment::ResetPromiseHooks(Local<Function> init,
void AsyncHooks::push_async_context(
double async_id,
double trigger_async_id,
std::variant<Local<Object>*, Global<Object>*> resource) {
const std::variant<Local<Object>*, Global<Object>*>& resource) {
std::visit([](auto* ptr) { CHECK_IMPLIES(ptr != nullptr, !ptr->IsEmpty()); },
resource);

Expand Down Expand Up @@ -161,9 +161,13 @@ void AsyncHooks::push_async_context(
// False positive: https://github.com/cpplint/cpplint/issues/410
// NOLINTNEXTLINE(whitespace/newline)
if (std::visit([](auto* ptr) { return ptr != nullptr; }, resource)) {
native_execution_async_resources_.resize(offset + 1);
// Caveat: This is a v8::Local<>* assignment, we do not keep a v8::Global<>!
native_execution_async_resources_[offset] = resource;
if (native_execution_async_resources_.size() == offset) {
native_execution_async_resources_.push_back(resource);
} else {
native_execution_async_resources_.resize(offset + 1);
native_execution_async_resources_[offset] = resource;
}
}
}

Expand Down Expand Up @@ -196,7 +200,11 @@ bool AsyncHooks::pop_async_context(double async_id) {
native_execution_async_resources_[i]);
}
#endif
native_execution_async_resources_.resize(offset);
if (native_execution_async_resources_.size() == offset + 1) {
native_execution_async_resources_.pop_back();
} else {
native_execution_async_resources_.resize(offset);
}
native_execution_async_resources_.shrink_to_fit();
}

Expand Down
2 changes: 1 addition & 1 deletion 2 src/env.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class AsyncHooks : public MemoryRetainer {
void push_async_context(
double async_id,
double trigger_async_id,
std::variant<v8::Local<v8::Object>*, v8::Global<v8::Object>*>
const std::variant<v8::Local<v8::Object>*, v8::Global<v8::Object>*>&
execution_async_resource);
bool pop_async_context(double async_id);
void clear_async_id_stack(); // Used in fatal exceptions.
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.