Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e17c737
tools: copyedit `build-tarball.yml`
aduh95 Sep 10, 2025
43e6e54
build: do not include custom ESLint rules testing in tarball
aduh95 Sep 8, 2025
f0c20cc
src: remove unnecessary `Environment::GetCurrent()` calls
iknoom Sep 11, 2025
0d23fd5
tools: skip test-internet workflow for draft PRs
targos Sep 11, 2025
b200cd8
lib,src: refactor assert to load error source from memory
legendecas Sep 2, 2025
d785929
lib: add source map support for assert messages
legendecas Sep 3, 2025
ff13d1d
lib,src: cache ModuleWrap.hasAsyncGraph
legendecas Sep 11, 2025
8a5325d
src: ensure `v8::Eternal` is empty before setting it
addaleax Sep 11, 2025
b711256
deps: update undici to 7.16.0
nodejs-github-bot Sep 11, 2025
e9cb986
doc: rephrase dynamic import() description
meteorqz6 Sep 12, 2025
e4f5716
doc: deprecate closing `fs.Dir` on garbage collection
LiviaMedeiros Sep 12, 2025
6458867
url: add type checking to urlToHttpOptions()
simon-id Sep 12, 2025
9a4bbdc
benchmark: calibrate config cluster/echo.js
meteorqz6 Sep 12, 2025
bb051c5
crypto: avoid calls to `promise.catch()`
Renegade334 Sep 9, 2025
8ed4587
crypto: use async functions for non-stub Promise-returning functions
Renegade334 Sep 9, 2025
647c332
crypto: use `return await` when returning Promises from async functions
Renegade334 Sep 9, 2025
f006a14
node-api: make napi_delete_reference use node_api_basic_env
JeetuSuthar Sep 12, 2025
03116a7
src: remove `std::array` overload of `FIXED_ONE_BYTE_STRING`
addaleax Aug 4, 2025
2bb1525
src: create strings in `FIXED_ONE_BYTE_STRING` as internalized
addaleax Aug 4, 2025
026d4e3
doc,crypto: update subtle.generateKey and subtle.importKey
panva Sep 13, 2025
0f46c1c
repl: fix cpu overhead pasting big strings to the REPL
BridgeAR Sep 14, 2025
6133a82
util: fix debuglog.enabled not being present with callback logger
BridgeAR Sep 14, 2025
3c62b38
util: inspect objects with throwing Symbol.toStringTag
BridgeAR Sep 14, 2025
9df91e5
doc: type improvement of file `http.md`
samuel871211 Sep 14, 2025
8b29bbc
url: replaced slice with at
Connormiha Sep 14, 2025
cbec4fd
benchmark: calibrate config dgram multi-buffer
brunocroh Sep 14, 2025
fed1dac
lib: update isDeepStrictEqual to support options
miguelmarcondesf Sep 14, 2025
9782ca2
zlib: implement fast path for crc32
gurgunday Sep 14, 2025
83ae610
http: optimize checkIsHttpToken for short strings
JinhyeokFang Sep 14, 2025
acada1f
inspector: ensure adequate memory allocation for `Binary::toBase64`
Renegade334 Sep 14, 2025
bd767c5
doc: add security escalation policy
UlisesGascon Sep 15, 2025
97c4e1b
typings: remove unused imports
meteorqz6 Sep 15, 2025
be48760
node-api: added SharedArrayBuffer api
mertcanaltin Sep 16, 2025
039ac19
crypto: expose signatureAlgorithm on X509Certificate
patrickrbc Sep 16, 2025
213188e
stream: use new AsyncResource instead of bind
mcollina Sep 16, 2025
abecdcb
src: replace FIXED_ONE_BYTE_STRING with Environment-cached strings
iknoom Sep 17, 2025
ac78491
src: reduce the nearest parent package JSON cache size
michaelsmithxyz Sep 17, 2025
993f05d
fs,win: do not add a second trailing slash in readdir
Flarna Sep 17, 2025
728472a
module: only put directly require-d ESM into require.cache
joyeecheung Sep 17, 2025
8f32746
test: guard write to proxy client if proxy connection is ended
joyeecheung Sep 17, 2025
d17f299
src: use DictionaryTemplate more in URLPattern
jasnell Sep 17, 2025
87bbaa2
tools: fix `tools/make-v8.sh` for clang
richardlau Sep 17, 2025
7aec53b
http: add shouldUpgradeCallback to let servers control HTTP upgrades
pimterry Sep 17, 2025
9a3e58a
sqlite: add tagged template
0hmX Sep 17, 2025
e94c573
meta: add .npmrc with ignore-scripts=true
joyeecheung Sep 17, 2025
8c85570
deps: upgrade openssl sources to openssl-3.5.3
nodejs-github-bot Sep 16, 2025
fa40d3a
deps: update archs files for openssl-3.5.3
nodejs-github-bot Sep 16, 2025
f5d3f91
tls: only do off-thread certificate loading on loading tls
joyeecheung Sep 11, 2025
6790093
tls: load bundled and extra certificates off-thread
joyeecheung Sep 11, 2025
2b2591d
esm: make hasAsyncGraph non-enumerable
joyeecheung Sep 18, 2025
b0c1e67
diagnostics_channel: fix race condition with diagnostics_channel and GC
uurien Sep 19, 2025
6e586a1
vm: expose hasTopLevelAwait on SourceTextModule
legendecas Sep 19, 2025
c5d910a
http2: fix allowHttp1+Upgrade, broken by shouldUpgradeCallback
pimterry Sep 20, 2025
86150f3
src: rename private fields to follow naming convention
iknoom Sep 20, 2025
69b5607
src: simplify is_callable by making it a concept
tniessen Sep 20, 2025
396cc8e
lib: update inspect output format for subclasses
miguelmarcondesf Sep 21, 2025
ce8435b
test: testcase demonstrating issue 59541
ericrannaud Sep 7, 2025
44ce971
vm: "afterEvaluate", evaluate() return a promise from the outer context
ericrannaud Sep 10, 2025
9347ddd
vm: explain how to share promises between contexts w/ afterEvaluate
ericrannaud Sep 19, 2025
dea5dd7
dgram: restore buffer optimization in fixBufferList
ri7116 Sep 21, 2025
a28962a
doc: update V8 fast API guidance
Renegade334 Sep 21, 2025
0b284d8
build: add the missing macro definitions for OpenHarmony
hqzing Sep 22, 2025
e330f03
src: update crypto objects to use DictionaryTemplate
jasnell Sep 22, 2025
b970c0b
zlib: reduce code duplication
jhofstee Sep 22, 2025
6695067
http,https: handle IPv6 with proxies
joyeecheung Sep 22, 2025
05e560d
deps: update googletest to 50b8600
nodejs-github-bot Sep 23, 2025
1e723f9
doc: fix typo in section on microtask order
tniessen Sep 23, 2025
49747a5
worker: add heap profile API
theanarkh Sep 23, 2025
f14ed5a
src: simplify watchdog instantiations via `std::optional`
addaleax Sep 23, 2025
0b37b59
doc: use "WebAssembly" instead of "Web Assembly"
tniessen Sep 24, 2025
0fe5337
sqlite: cleanup ERM support and export Session class
jasnell May 18, 2025
3eeb7b4
sqlite: fix crash session extension callbacks with workers
louwers Sep 23, 2025
31c6e70
2025-09-25, Version 24.9.0 (Current)
nodejs-github-bot Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lib,src: cache ModuleWrap.hasAsyncGraph
`v8::Module::IsGraphAsync()` traverses the dependencies to find if they
contain TLA each time. `ModuleWrap.hasAsyncGraph` caches the result
and exposes the property to JS land so that the presence of the property
`module.hasAsyncGraph` can be consistent.

This also allows C++ access of cached `hasAsyncGraph`.

This merges the `intantiateSync`/`instantiate` and
`getNamespaceSync`/`getNamespace` as they are always sync.

PR-URL: #59703
Reviewed-By: Joyee Cheung <[email protected]>
  • Loading branch information
legendecas authored and targos committed Sep 12, 2025
commit ff13d1d61e049d1b22a55c2a2b58cdcc871cce49
1 change: 0 additions & 1 deletion lib/internal/bootstrap/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ class BuiltinModule {
this.setExport('default', builtin.exports);
});
// Ensure immediate sync execution to capture exports now
this.module.link([]);
this.module.instantiate();
this.module.evaluate(-1, false);
return this.module;
Expand Down
9 changes: 5 additions & 4 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,14 @@ class ModuleLoader {
if (!job.module) {
assert.fail(getRaceMessage(filename, parentFilename));
}
if (job.module.hasAsyncGraph) {
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
}
const status = job.module.getStatus();
debug('Module status', job, status);
// hasAsyncGraph is available after module been instantiated.
if (status >= kInstantiated && job.module.hasAsyncGraph) {
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
}
if (status === kEvaluated) {
return { wrap: job.module, namespace: job.module.getNamespaceSync(filename, parentFilename) };
return { wrap: job.module, namespace: job.module.getNamespace() };
} else if (status === kInstantiated) {
// When it's an async job cached by another import request,
// which has finished linking but has not started its
Expand Down
22 changes: 14 additions & 8 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,18 @@ class ModuleJob extends ModuleJobBase {
let status = this.module.getStatus();

debug('ModuleJob.runSync()', status, this.module);
// FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking
// fully synchronous instead.
if (status === kUninstantiated) {
this.module.hasAsyncGraph = this.module.instantiateSync();
// FIXME(joyeecheung): this cannot fully handle < kInstantiated. Make the linking
// fully synchronous instead.
if (this.module.getModuleRequests().length === 0) {
this.module.link([]);
}
this.module.instantiate();
status = this.module.getStatus();
}
if (status === kInstantiated || status === kErrored) {
const filename = urlToFilename(this.url);
const parentFilename = urlToFilename(parent?.filename);
this.module.hasAsyncGraph ??= this.module.isGraphAsync();

if (this.module.hasAsyncGraph && !getOptionValue('--experimental-print-required-tla')) {
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
}
Expand All @@ -345,14 +346,19 @@ class ModuleJob extends ModuleJobBase {
}
throw this.module.getError();
} else if (status === kEvaluating || status === kEvaluated) {
if (this.module.hasAsyncGraph) {
const filename = urlToFilename(this.url);
const parentFilename = urlToFilename(parent?.filename);
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parentFilename);
}
// kEvaluating can show up when this is being used to deal with CJS <-> CJS cycles.
// Allow it for now, since we only need to ban ESM <-> CJS cycles which would be
// detected earlier during the linking phase, though the CJS handling in the ESM
// loader won't be able to emit warnings on pending circular exports like what
// the CJS loader does.
// TODO(joyeecheung): remove the re-invented require() in the ESM loader and
// always handle CJS using the CJS loader to eliminate the quirks.
return { __proto__: null, module: this.module, namespace: this.module.getNamespaceSync() };
return { __proto__: null, module: this.module, namespace: this.module.getNamespace() };
}
assert.fail(`Unexpected module status ${status}.`);
}
Expand Down Expand Up @@ -472,7 +478,7 @@ class ModuleJobSync extends ModuleJobBase {
}
return { __proto__: null, module: this.module };
} else if (status === kInstantiated) {
// The evaluation may have been canceled because instantiateSync() detected TLA first.
// The evaluation may have been canceled because instantiate() detected TLA first.
// But when it is imported again, it's fine to re-evaluate it asynchronously.
const timeout = -1;
const breakOnSigint = false;
Expand All @@ -490,7 +496,7 @@ class ModuleJobSync extends ModuleJobBase {
debug('ModuleJobSync.runSync()', this.module);
assert(this.phase === kEvaluationPhase);
// TODO(joyeecheung): add the error decoration logic from the async instantiate.
this.module.hasAsyncGraph = this.module.instantiateSync();
this.module.instantiate();
// If --experimental-print-required-tla is true, proceeds to evaluation even
// if it's async because we want to search for the TLA and help users locate
// them.
Expand Down
1 change: 0 additions & 1 deletion lib/internal/vm/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ class SyntheticModule extends Module {
identifier,
});
// A synthetic module does not have dependencies.
this[kWrap].link([]);
this[kWrap].instantiate();
}

Expand Down
146 changes: 49 additions & 97 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ using v8::ObjectTemplate;
using v8::PrimitiveArray;
using v8::Promise;
using v8::PromiseRejectEvent;
using v8::PropertyCallbackInfo;
using v8::ScriptCompiler;
using v8::ScriptOrigin;
using v8::String;
Expand Down Expand Up @@ -158,6 +159,8 @@ ModuleWrap::ModuleWrap(Realm* realm,

if (!synthetic_evaluation_step->IsUndefined()) {
synthetic_ = true;
// Synthetic modules have no dependencies.
linked_ = true;
}
MakeWeak();
module_.SetWeak();
Expand Down Expand Up @@ -240,7 +243,7 @@ Maybe<bool> ModuleWrap::CheckUnsettledTopLevelAwait() {
return Just(true);
}

if (!module->IsGraphAsync()) { // There is no TLA, no need to check.
if (!HasAsyncGraph()) { // There is no TLA, no need to check.
return Just(true);
}

Expand All @@ -263,6 +266,16 @@ Maybe<bool> ModuleWrap::CheckUnsettledTopLevelAwait() {
return Just(false);
}

bool ModuleWrap::HasAsyncGraph() {
if (!has_async_graph_.has_value()) {
Isolate* isolate = env()->isolate();
HandleScope scope(isolate);

has_async_graph_ = module_.Get(isolate)->IsGraphAsync();
}
return has_async_graph_.value();
}

Local<PrimitiveArray> ModuleWrap::GetHostDefinedOptions(
Isolate* isolate, Local<Symbol> id_symbol) {
Local<PrimitiveArray> host_defined_options =
Expand Down Expand Up @@ -687,25 +700,28 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());
Local<Context> context = obj->context();
Local<Module> module = obj->module_.Get(isolate);
Environment* env = realm->env();

if (!obj->IsLinked()) {
THROW_ERR_VM_MODULE_LINK_FAILURE(realm->env(), "module is not linked");
THROW_ERR_VM_MODULE_LINK_FAILURE(env, "module is not linked");
return;
}

TryCatchScope try_catch(realm->env());
USE(module->InstantiateModule(
context, ResolveModuleCallback, ResolveSourceCallback));
{
TryCatchScope try_catch(env);
USE(module->InstantiateModule(
context, ResolveModuleCallback, ResolveSourceCallback));

if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
CHECK(!try_catch.Message().IsEmpty());
CHECK(!try_catch.Exception().IsEmpty());
AppendExceptionLine(realm->env(),
try_catch.Exception(),
try_catch.Message(),
ErrorHandlingMode::MODULE_ERROR);
try_catch.ReThrow();
return;
if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
CHECK(!try_catch.Message().IsEmpty());
CHECK(!try_catch.Exception().IsEmpty());
AppendExceptionLine(env,
try_catch.Exception(),
try_catch.Message(),
ErrorHandlingMode::MODULE_ERROR);
try_catch.ReThrow();
return;
}
}
}

Expand Down Expand Up @@ -790,37 +806,6 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
}
}

void ModuleWrap::InstantiateSync(const FunctionCallbackInfo<Value>& args) {
Realm* realm = Realm::GetCurrent(args);
Isolate* isolate = args.GetIsolate();
ModuleWrap* obj;
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());
Local<Context> context = obj->context();
Local<Module> module = obj->module_.Get(isolate);
Environment* env = realm->env();

{
TryCatchScope try_catch(env);
USE(module->InstantiateModule(
context, ResolveModuleCallback, ResolveSourceCallback));

if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
CHECK(!try_catch.Message().IsEmpty());
CHECK(!try_catch.Exception().IsEmpty());
AppendExceptionLine(env,
try_catch.Exception(),
try_catch.Message(),
ErrorHandlingMode::MODULE_ERROR);
try_catch.ReThrow();
return;
}
}

// TODO(joyeecheung): record Module::HasTopLevelAwait() in every ModuleWrap
// and infer the asynchronicity from a module's children during linking.
args.GetReturnValue().Set(module->IsGraphAsync());
}

Maybe<void> ThrowIfPromiseRejected(Realm* realm, Local<Promise> promise) {
Isolate* isolate = realm->isolate();
Local<Context> context = realm->context();
Expand Down Expand Up @@ -886,7 +871,7 @@ void ModuleWrap::EvaluateSync(const FunctionCallbackInfo<Value>& args) {
return;
}

if (module->IsGraphAsync()) {
if (obj->HasAsyncGraph()) {
CHECK(env->options()->print_required_tla);
auto stalled_messages =
std::get<1>(module->GetStalledTopLevelAwaitMessages(isolate));
Expand All @@ -908,52 +893,15 @@ void ModuleWrap::EvaluateSync(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(module->GetModuleNamespace());
}

void ModuleWrap::GetNamespaceSync(const FunctionCallbackInfo<Value>& args) {
Realm* realm = Realm::GetCurrent(args);
Isolate* isolate = args.GetIsolate();
ModuleWrap* obj;
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());
Local<Module> module = obj->module_.Get(isolate);

switch (module->GetStatus()) {
case Module::Status::kUninstantiated:
case Module::Status::kInstantiating:
return realm->env()->ThrowError(
"Cannot get namespace, module has not been instantiated");
case Module::Status::kInstantiated:
case Module::Status::kEvaluating:
case Module::Status::kEvaluated:
case Module::Status::kErrored:
break;
}

if (module->IsGraphAsync()) {
return THROW_ERR_REQUIRE_ASYNC_MODULE(realm->env(), args[0], args[1]);
}
Local<Value> result = module->GetModuleNamespace();
args.GetReturnValue().Set(result);
}

void ModuleWrap::GetNamespace(const FunctionCallbackInfo<Value>& args) {
Realm* realm = Realm::GetCurrent(args);
Isolate* isolate = args.GetIsolate();
ModuleWrap* obj;
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());

Local<Module> module = obj->module_.Get(isolate);

switch (module->GetStatus()) {
case Module::Status::kUninstantiated:
case Module::Status::kInstantiating:
return realm->env()->ThrowError(
"cannot get namespace, module has not been instantiated");
case Module::Status::kInstantiated:
case Module::Status::kEvaluating:
case Module::Status::kEvaluated:
case Module::Status::kErrored:
break;
default:
UNREACHABLE();
if (module->GetStatus() < Module::kInstantiated) {
return THROW_ERR_MODULE_NOT_INSTANTIATED(realm->env());
}

Local<Value> result = module->GetModuleNamespace();
Expand Down Expand Up @@ -1004,23 +952,28 @@ void ModuleWrap::GetStatus(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(module->GetStatus());
}

void ModuleWrap::IsGraphAsync(const FunctionCallbackInfo<Value>& args) {
void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
ModuleWrap* obj;
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());

Local<Module> module = obj->module_.Get(isolate);

args.GetReturnValue().Set(module->IsGraphAsync());
args.GetReturnValue().Set(module->GetException());
}

void ModuleWrap::GetError(const FunctionCallbackInfo<Value>& args) {
void ModuleWrap::HasAsyncGraph(Local<Name> property,
const PropertyCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
Environment* env = Environment::GetCurrent(isolate);
ModuleWrap* obj;
ASSIGN_OR_RETURN_UNWRAP(&obj, args.This());

Local<Module> module = obj->module_.Get(isolate);
args.GetReturnValue().Set(module->GetException());
if (module->GetStatus() < Module::kInstantiated) {
return THROW_ERR_MODULE_NOT_INSTANTIATED(env);
}

args.GetReturnValue().Set(obj->HasAsyncGraph());
}

// static
Expand Down Expand Up @@ -1424,10 +1377,8 @@ void ModuleWrap::CreatePerIsolateProperties(IsolateData* isolate_data,

SetProtoMethod(isolate, tpl, "link", Link);
SetProtoMethod(isolate, tpl, "getModuleRequests", GetModuleRequests);
SetProtoMethod(isolate, tpl, "instantiateSync", InstantiateSync);
SetProtoMethod(isolate, tpl, "evaluateSync", EvaluateSync);
SetProtoMethod(isolate, tpl, "getNamespaceSync", GetNamespaceSync);
SetProtoMethod(isolate, tpl, "instantiate", Instantiate);
SetProtoMethod(isolate, tpl, "evaluateSync", EvaluateSync);
SetProtoMethod(isolate, tpl, "evaluate", Evaluate);
SetProtoMethod(isolate, tpl, "setExport", SetSyntheticExport);
SetProtoMethod(isolate, tpl, "setModuleSourceObject", SetModuleSourceObject);
Expand All @@ -1436,9 +1387,12 @@ void ModuleWrap::CreatePerIsolateProperties(IsolateData* isolate_data,
isolate, tpl, "createCachedData", CreateCachedData);
SetProtoMethodNoSideEffect(isolate, tpl, "getNamespace", GetNamespace);
SetProtoMethodNoSideEffect(isolate, tpl, "getStatus", GetStatus);
SetProtoMethodNoSideEffect(isolate, tpl, "isGraphAsync", IsGraphAsync);
SetProtoMethodNoSideEffect(isolate, tpl, "getError", GetError);
SetConstructorFunction(isolate, target, "ModuleWrap", tpl);

tpl->InstanceTemplate()->SetLazyDataProperty(
FIXED_ONE_BYTE_STRING(isolate, "hasAsyncGraph"), HasAsyncGraph);

isolate_data->set_module_wrap_constructor_template(tpl);

SetMethod(isolate,
Expand Down Expand Up @@ -1486,9 +1440,7 @@ void ModuleWrap::RegisterExternalReferences(

registry->Register(Link);
registry->Register(GetModuleRequests);
registry->Register(InstantiateSync);
registry->Register(EvaluateSync);
registry->Register(GetNamespaceSync);
registry->Register(Instantiate);
registry->Register(Evaluate);
registry->Register(SetSyntheticExport);
Expand All @@ -1498,7 +1450,7 @@ void ModuleWrap::RegisterExternalReferences(
registry->Register(GetNamespace);
registry->Register(GetStatus);
registry->Register(GetError);
registry->Register(IsGraphAsync);
registry->Register(HasAsyncGraph);

registry->Register(CreateRequiredModuleFacade);

Expand Down
Loading