Skip to content

Commit e0982f7

Browse files
addaleaxtargos
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 833cb00 commit e0982f7

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
@@ -336,7 +336,8 @@ MaybeLocal<Value> Environment::RunBootstrapping() {
336336

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

src/node_env_var.cc

+5
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Maybe<bool> KVStore::AssignFromObject(Local<Context> context,
255255
static void EnvGetter(Local<Name> property,
256256
const PropertyCallbackInfo<Value>& info) {
257257
Environment* env = Environment::GetCurrent(info);
258+
CHECK(env->has_run_bootstrapping_code());
258259
if (property->IsSymbol()) {
259260
return info.GetReturnValue().SetUndefined();
260261
}
@@ -270,6 +271,7 @@ static void EnvSetter(Local<Name> property,
270271
Local<Value> value,
271272
const PropertyCallbackInfo<Value>& info) {
272273
Environment* env = Environment::GetCurrent(info);
274+
CHECK(env->has_run_bootstrapping_code());
273275
// calling env->EmitProcessEnvWarning() sets a variable indicating that
274276
// warnings have been emitted. It should be called last after other
275277
// conditions leading to a warning have been met.
@@ -303,6 +305,7 @@ static void EnvSetter(Local<Name> property,
303305
static void EnvQuery(Local<Name> property,
304306
const PropertyCallbackInfo<Integer>& info) {
305307
Environment* env = Environment::GetCurrent(info);
308+
CHECK(env->has_run_bootstrapping_code());
306309
if (property->IsString()) {
307310
int32_t rc = env->env_vars()->Query(env->isolate(), property.As<String>());
308311
if (rc != -1) info.GetReturnValue().Set(rc);
@@ -312,6 +315,7 @@ static void EnvQuery(Local<Name> property,
312315
static void EnvDeleter(Local<Name> property,
313316
const PropertyCallbackInfo<Boolean>& info) {
314317
Environment* env = Environment::GetCurrent(info);
318+
CHECK(env->has_run_bootstrapping_code());
315319
if (property->IsString()) {
316320
env->env_vars()->Delete(env->isolate(), property.As<String>());
317321
}
@@ -323,6 +327,7 @@ static void EnvDeleter(Local<Name> property,
323327

324328
static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
325329
Environment* env = Environment::GetCurrent(info);
330+
CHECK(env->has_run_bootstrapping_code());
326331

327332
info.GetReturnValue().Set(
328333
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)