| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 19b4aa4 commit b46bad3
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,15 +99,7 @@ bool SafeGetenv(const char* key, std::string* text, Environment* env) { | |||
| 99 | 99 | *text = value.value(); | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | - auto options = | ||
| 103 | - (env != nullptr ? env->options() | ||
| 104 | - : per_process::cli_options->per_isolate->per_env); | ||
| 105 | - | ||
| 106 | - if (options->trace_env) { | ||
| 107 | - fprintf(stderr, "[--trace-env] get environment variable \"%s\"\n", key); | ||
| 108 | - | ||
| 109 | - PrintTraceEnvStack(options); | ||
| 110 | - } | ||
| 102 | + TraceEnvVar(env, "get", key); | ||
| 111 | 103 | ||
| 112 | 104 | return has_env; | |
| 113 | 105 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -338,19 +338,73 @@ Maybe<void> KVStore::AssignToObject(v8::Isolate* isolate, | |||
| 338 | 338 | return JustVoid(); | |
| 339 | 339 | } | |
| 340 | 340 | ||
| 341 | - void PrintTraceEnvStack(Environment* env) { | ||
| 342 | - PrintTraceEnvStack(env->options()); | ||
| 343 | - } | ||
| 341 | + struct TraceEnvVarOptions { | ||
| 342 | + bool print_message : 1 = 0; | ||
| 343 | + bool print_js_stack : 1 = 0; | ||
| 344 | + bool print_native_stack : 1 = 0; | ||
| 345 | + }; | ||
| 344 | 346 | ||
| 345 | - void PrintTraceEnvStack(std::shared_ptr<EnvironmentOptions> options) { | ||
| 346 | - if (options->trace_env_native_stack) { | ||
| 347 | + template <typename... Args> | ||
| 348 | + inline void TraceEnvVarImpl(Environment* env, | ||
| 349 | + TraceEnvVarOptions options, | ||
| 350 | + const char* format, | ||
| 351 | + Args&&... args) { | ||
| 352 | + if (options.print_message) { | ||
| 353 | + fprintf(stderr, format, std::forward<Args>(args)...); | ||
| 354 | + } | ||
| 355 | + if (options.print_native_stack) { | ||
| 347 | 356 | DumpNativeBacktrace(stderr); | |
| 348 | 357 | } | |
| 349 | - if (options->trace_env_js_stack) { | ||
| 358 | + if (options.print_js_stack) { | ||
| 350 | 359 | DumpJavaScriptBacktrace(stderr); | |
| 351 | 360 | } | |
| 352 | 361 | } | |
| 353 | 362 | ||
| 363 | + TraceEnvVarOptions GetTraceEnvVarOptions(Environment* env) { | ||
| 364 | + TraceEnvVarOptions options; | ||
| 365 | + auto cli_options = env != nullptr | ||
| 366 | + ? env->options() | ||
| 367 | + : per_process::cli_options->per_isolate->per_env; | ||
| 368 | + if (cli_options->trace_env) { | ||
| 369 | + options.print_message = 1; | ||
| 370 | + }; | ||
| 371 | + if (cli_options->trace_env_js_stack) { | ||
| 372 | + options.print_js_stack = 1; | ||
| 373 | + }; | ||
| 374 | + if (cli_options->trace_env_native_stack) { | ||
| 375 | + options.print_native_stack = 1; | ||
| 376 | + }; | ||
| 377 | + return options; | ||
| 378 | + } | ||
| 379 | + | ||
| 380 | + void TraceEnvVar(Environment* env, const char* message) { | ||
| 381 | + TraceEnvVarImpl( | ||
| 382 | + env, GetTraceEnvVarOptions(env), "[--trace-env] %s\n", message); | ||
| 383 | + } | ||
| 384 | + | ||
| 385 | + void TraceEnvVar(Environment* env, const char* message, const char* key) { | ||
| 386 | + TraceEnvVarImpl(env, | ||
| 387 | + GetTraceEnvVarOptions(env), | ||
| 388 | + "[--trace-env] %s \"%s\"\n", | ||
| 389 | + message, | ||
| 390 | + key); | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + void TraceEnvVar(Environment* env, | ||
| 394 | + const char* message, | ||
| 395 | + v8::Local<v8::String> key) { | ||
| 396 | + TraceEnvVarOptions options = GetTraceEnvVarOptions(env); | ||
| 397 | + if (options.print_message) { | ||
| 398 | + Utf8Value key_utf8(env->isolate(), key); | ||
| 399 | + TraceEnvVarImpl(env, | ||
| 400 | + options, | ||
| 401 | + "[--trace-env] %s \"%.*s\"\n", | ||
| 402 | + message, | ||
| 403 | + static_cast<int>(key_utf8.length()), | ||
| 404 | + key_utf8.out()); | ||
| 405 | + } | ||
| 406 | + } | ||
| 407 | + | ||
| 354 | 408 | static Intercepted EnvGetter(Local<Name> property, | |
| 355 | 409 | const PropertyCallbackInfo<Value>& info) { | |
| 356 | 410 | Environment* env = Environment::GetCurrent(info); | |
@@ -364,14 +418,7 @@ static Intercepted EnvGetter(Local<Name> property, | |||
| 364 | 418 | env->env_vars()->Get(env->isolate(), property.As<String>()); | |
| 365 | 419 | ||
| 366 | 420 | bool has_env = !value_string.IsEmpty(); | |
| 367 | - if (env->options()->trace_env) { | ||
| 368 | - Utf8Value key(env->isolate(), property.As<String>()); | ||
| 369 | - fprintf(stderr, | ||
| 370 | - "[--trace-env] get environment variable \"%.*s\"\n", | ||
| 371 | - static_cast<int>(key.length()), | ||
| 372 | - key.out()); | ||
| 373 | - PrintTraceEnvStack(env); | ||
| 374 | - } | ||
| 421 | + TraceEnvVar(env, "get", property.As<String>()); | ||
| 375 | 422 | ||
| 376 | 423 | if (has_env) { | |
| 377 | 424 | info.GetReturnValue().Set(value_string.ToLocalChecked()); | |
@@ -411,14 +458,7 @@ static Intercepted EnvSetter(Local<Name> property, | |||
| 411 | 458 | } | |
| 412 | 459 | ||
| 413 | 460 | env->env_vars()->Set(env->isolate(), key, value_string); | |
| 414 | - if (env->options()->trace_env) { | ||
| 415 | - Utf8Value key_utf8(env->isolate(), key); | ||
| 416 | - fprintf(stderr, | ||
| 417 | - "[--trace-env] set environment variable \"%.*s\"\n", | ||
| 418 | - static_cast<int>(key_utf8.length()), | ||
| 419 | - key_utf8.out()); | ||
| 420 | - PrintTraceEnvStack(env); | ||
| 421 | - } | ||
| 461 | + TraceEnvVar(env, "set", key); | ||
| 422 | 462 | ||
| 423 | 463 | return Intercepted::kYes; | |
| 424 | 464 | } | |
@@ -430,16 +470,7 @@ static Intercepted EnvQuery(Local<Name> property, | |||
| 430 | 470 | if (property->IsString()) { | |
| 431 | 471 | int32_t rc = env->env_vars()->Query(env->isolate(), property.As<String>()); | |
| 432 | 472 | bool has_env = (rc != -1); | |
| 433 | - | ||
| 434 | - if (env->options()->trace_env) { | ||
| 435 | - Utf8Value key_utf8(env->isolate(), property.As<String>()); | ||
| 436 | - fprintf(stderr, | ||
| 437 | - "[--trace-env] query environment variable \"%.*s\": %s\n", | ||
| 438 | - static_cast<int>(key_utf8.length()), | ||
| 439 | - key_utf8.out(), | ||
| 440 | - has_env ? "is set" : "is not set"); | ||
| 441 | - PrintTraceEnvStack(env); | ||
| 442 | - } | ||
| 473 | + TraceEnvVar(env, "query", property.As<String>()); | ||
| 443 | 474 | if (has_env) { | |
| 444 | 475 | // Return attributes for the property. | |
| 445 | 476 | info.GetReturnValue().Set(v8::None); | |
@@ -456,14 +487,7 @@ static Intercepted EnvDeleter(Local<Name> property, | |||
| 456 | 487 | if (property->IsString()) { | |
| 457 | 488 | env->env_vars()->Delete(env->isolate(), property.As<String>()); | |
| 458 | 489 | ||
| 459 | - if (env->options()->trace_env) { | ||
| 460 | - Utf8Value key_utf8(env->isolate(), property.As<String>()); | ||
| 461 | - fprintf(stderr, | ||
| 462 | - "[--trace-env] delete environment variable \"%.*s\"\n", | ||
| 463 | - static_cast<int>(key_utf8.length()), | ||
| 464 | - key_utf8.out()); | ||
| 465 | - PrintTraceEnvStack(env); | ||
| 466 | - } | ||
| 490 | + TraceEnvVar(env, "delete", property.As<String>()); | ||
| 467 | 491 | } | |
| 468 | 492 | ||
| 469 | 493 | // process.env never has non-configurable properties, so always | |
@@ -476,11 +500,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | |||
| 476 | 500 | Environment* env = Environment::GetCurrent(info); | |
| 477 | 501 | CHECK(env->has_run_bootstrapping_code()); | |
| 478 | 502 | ||
| 479 | - if (env->options()->trace_env) { | ||
| 480 | - fprintf(stderr, "[--trace-env] enumerate environment variables\n"); | ||
| 481 | - | ||
| 482 | - PrintTraceEnvStack(env); | ||
| 483 | - } | ||
| 503 | + TraceEnvVar(env, "enumerate environment variables"); | ||
| 484 | 504 | ||
| 485 | 505 | info.GetReturnValue().Set( | |
| 486 | 506 | env->env_vars()->Enumerate(env->isolate())); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,8 +324,11 @@ namespace credentials { | |||
| 324 | 324 | bool SafeGetenv(const char* key, std::string* text, Environment* env = nullptr); | |
| 325 | 325 | } // namespace credentials | |
| 326 | 326 | ||
| 327 | - void PrintTraceEnvStack(Environment* env); | ||
| 328 | - void PrintTraceEnvStack(std::shared_ptr<EnvironmentOptions> options); | ||
| 327 | + void TraceEnvVar(Environment* env, const char* message); | ||
| 328 | + void TraceEnvVar(Environment* env, const char* message, const char* key); | ||
| 329 | + void TraceEnvVar(Environment* env, | ||
| 330 | + const char* message, | ||
| 331 | + v8::Local<v8::String> key); | ||
| 329 | 332 | ||
| 330 | 333 | void DefineZlibConstants(v8::Local<v8::Object> target); | |
| 331 | 334 | v8::Isolate* NewIsolate(v8::Isolate::CreateParams* params, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,28 +14,28 @@ spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('empty.js')], | |||
| 14 | 14 | // If the internals remove any one of them, the checks here can be updated | |
| 15 | 15 | // accordingly. | |
| 16 | 16 | if (common.hasIntl) { | |
| 17 | - assert.match(output, /get environment variable "NODE_ICU_DATA"/); | ||
| 17 | + assert.match(output, /get "NODE_ICU_DATA"/); | ||
| 18 | 18 | } | |
| 19 | 19 | if (common.hasCrypto) { | |
| 20 | - assert.match(output, /get environment variable "NODE_EXTRA_CA_CERTS"/); | ||
| 20 | + assert.match(output, /get "NODE_EXTRA_CA_CERTS"/); | ||
| 21 | 21 | } | |
| 22 | 22 | if (common.hasOpenSSL3) { | |
| 23 | - assert.match(output, /get environment variable "OPENSSL_CONF"/); | ||
| 23 | + assert.match(output, /get "OPENSSL_CONF"/); | ||
| 24 | 24 | } | |
| 25 | - assert.match(output, /get environment variable "NODE_DEBUG_NATIVE"/); | ||
| 26 | - assert.match(output, /get environment variable "NODE_COMPILE_CACHE"/); | ||
| 27 | - assert.match(output, /get environment variable "NODE_NO_WARNINGS"/); | ||
| 28 | - assert.match(output, /get environment variable "NODE_V8_COVERAGE"/); | ||
| 29 | - assert.match(output, /get environment variable "NODE_DEBUG"/); | ||
| 30 | - assert.match(output, /get environment variable "NODE_CHANNEL_FD"/); | ||
| 31 | - assert.match(output, /get environment variable "NODE_UNIQUE_ID"/); | ||
| 25 | + assert.match(output, /get "NODE_DEBUG_NATIVE"/); | ||
| 26 | + assert.match(output, /get "NODE_COMPILE_CACHE"/); | ||
| 27 | + assert.match(output, /get "NODE_NO_WARNINGS"/); | ||
| 28 | + assert.match(output, /get "NODE_V8_COVERAGE"/); | ||
| 29 | + assert.match(output, /get "NODE_DEBUG"/); | ||
| 30 | + assert.match(output, /get "NODE_CHANNEL_FD"/); | ||
| 31 | + assert.match(output, /get "NODE_UNIQUE_ID"/); | ||
| 32 | 32 | if (common.isWindows) { | |
| 33 | - assert.match(output, /get environment variable "USERPROFILE"/); | ||
| 33 | + assert.match(output, /get "USERPROFILE"/); | ||
| 34 | 34 | } else { | |
| 35 | - assert.match(output, /get environment variable "HOME"/); | ||
| 35 | + assert.match(output, /get "HOME"/); | ||
| 36 | 36 | } | |
| 37 | - assert.match(output, /get environment variable "NODE_PATH"/); | ||
| 38 | - assert.match(output, /get environment variable "WATCH_REPORT_DEPENDENCIES"/); | ||
| 37 | + assert.match(output, /get "NODE_PATH"/); | ||
| 38 | + assert.match(output, /get "WATCH_REPORT_DEPENDENCIES"/); | ||
| 39 | 39 | } | |
| 40 | 40 | }); | |
| 41 | 41 | ||
@@ -48,22 +48,22 @@ spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('process-env' | |||
| 48 | 48 | } | |
| 49 | 49 | }, { | |
| 50 | 50 | stderr(output) { | |
| 51 | - assert.match(output, /get environment variable "FOO"/); | ||
| 52 | - assert.match(output, /get environment variable "BAR"/); | ||
| 51 | + assert.match(output, /get "FOO"/); | ||
| 52 | + assert.match(output, /get "BAR"/); | ||
| 53 | 53 | } | |
| 54 | 54 | }); | |
| 55 | 55 | ||
| 56 | 56 | // Check set from user land. | |
| 57 | 57 | spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('process-env', 'set.js') ], { | |
| 58 | 58 | stderr(output) { | |
| 59 | - assert.match(output, /set environment variable "FOO"/); | ||
| 59 | + assert.match(output, /set "FOO"/); | ||
| 60 | 60 | } | |
| 61 | 61 | }); | |
| 62 | 62 | ||
| 63 | 63 | // Check define from user land. | |
| 64 | 64 | spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('process-env', 'define.js') ], { | |
| 65 | 65 | stderr(output) { | |
| 66 | - assert.match(output, /set environment variable "FOO"/); | ||
| 66 | + assert.match(output, /set "FOO"/); | ||
| 67 | 67 | } | |
| 68 | 68 | }); | |
| 69 | 69 | ||
@@ -77,16 +77,16 @@ spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('process-env' | |||
| 77 | 77 | } | |
| 78 | 78 | }, { | |
| 79 | 79 | stderr(output) { | |
| 80 | - assert.match(output, /query environment variable "FOO": is set/); | ||
| 81 | - assert.match(output, /query environment variable "BAR": is not set/); | ||
| 82 | - assert.match(output, /query environment variable "BAZ": is not set/); | ||
| 80 | + assert.match(output, /query "FOO"/); | ||
| 81 | + assert.match(output, /query "BAR"/); | ||
| 82 | + assert.match(output, /query "BAZ"/); | ||
| 83 | 83 | } | |
| 84 | 84 | }); | |
| 85 | 85 | ||
| 86 | 86 | // Check delete from user land. | |
| 87 | 87 | spawnSyncAndAssert(process.execPath, ['--trace-env', fixtures.path('process-env', 'delete.js') ], { | |
| 88 | 88 | stderr(output) { | |
| 89 | - assert.match(output, /delete environment variable "FOO"/); | ||
| 89 | + assert.match(output, /delete "FOO"/); | ||
| 90 | 90 | } | |
| 91 | 91 | }); | |
| 92 | 92 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments