Skip to content

Commit 592d51c

Browse files
addaleaxBridgeAR
authored andcommitted
src: enhance feature access CHECKs during bootstrap
This adds `CHECK`s verifying that bootstrapping has finished before environment variables are accessed or handles/requests are created. The latter complements a pair of existent checks, but fails earlier and thus gives information about the call site, effectively addressing the TODO comment there. PR-URL: #30452 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent fba2f9a commit 592d51c

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

src/handle_wrap.cc

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ HandleWrap::HandleWrap(Environment* env,
116116
handle_(handle) {
117117
handle_->data = this;
118118
HandleScope scope(env->isolate());
119+
CHECK(env->has_run_bootstrapping_code());
119120
env->handle_wrap_queue()->PushBack(this);
120121
}
121122

src/node.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ MaybeLocal<Value> Environment::RunBootstrapping() {
344344

345345
// Make sure that no request or handle is created during bootstrap -
346346
// if necessary those should be done in pre-execution.
347-
// TODO(joyeecheung): print handles/requests before aborting
347+
// Usually, doing so would trigger the checks present in the ReqWrap and
348+
// HandleWrap classes, so this is only a consistency check.
348349
CHECK(req_wrap_queue()->IsEmpty());
349350
CHECK(handle_wrap_queue()->IsEmpty());
350351

src/node_env_var.cc

+5
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ Maybe<bool> KVStore::AssignFromObject(Local<Context> context,
272272
static void EnvGetter(Local<Name> property,
273273
const PropertyCallbackInfo<Value>& info) {
274274
Environment* env = Environment::GetCurrent(info);
275+
CHECK(env->has_run_bootstrapping_code());
275276
if (property->IsSymbol()) {
276277
return info.GetReturnValue().SetUndefined();
277278
}
@@ -287,6 +288,7 @@ static void EnvSetter(Local<Name> property,
287288
Local<Value> value,
288289
const PropertyCallbackInfo<Value>& info) {
289290
Environment* env = Environment::GetCurrent(info);
291+
CHECK(env->has_run_bootstrapping_code());
290292
// calling env->EmitProcessEnvWarning() sets a variable indicating that
291293
// warnings have been emitted. It should be called last after other
292294
// conditions leading to a warning have been met.
@@ -320,6 +322,7 @@ static void EnvSetter(Local<Name> property,
320322
static void EnvQuery(Local<Name> property,
321323
const PropertyCallbackInfo<Integer>& info) {
322324
Environment* env = Environment::GetCurrent(info);
325+
CHECK(env->has_run_bootstrapping_code());
323326
if (property->IsString()) {
324327
int32_t rc = env->env_vars()->Query(env->isolate(), property.As<String>());
325328
if (rc != -1) info.GetReturnValue().Set(rc);
@@ -329,6 +332,7 @@ static void EnvQuery(Local<Name> property,
329332
static void EnvDeleter(Local<Name> property,
330333
const PropertyCallbackInfo<Boolean>& info) {
331334
Environment* env = Environment::GetCurrent(info);
335+
CHECK(env->has_run_bootstrapping_code());
332336
if (property->IsString()) {
333337
env->env_vars()->Delete(env->isolate(), property.As<String>());
334338
}
@@ -340,6 +344,7 @@ static void EnvDeleter(Local<Name> property,
340344

341345
static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
342346
Environment* env = Environment::GetCurrent(info);
347+
CHECK(env->has_run_bootstrapping_code());
343348

344349
info.GetReturnValue().Set(
345350
env->env_vars()->Enumerate(env->isolate()));

src/req_wrap-inl.h

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace node {
1111

1212
ReqWrapBase::ReqWrapBase(Environment* env) {
13+
CHECK(env->has_run_bootstrapping_code());
1314
env->req_wrap_queue()->PushBack(this);
1415
}
1516

0 commit comments

Comments
 (0)