process: check env->EmitProcessEnvWarning() last

Calling env->EmitProcessEnvWarning() prevents additional warnings
from being set it should therefore be called only if a warning will
emit.

PR-URL: https://github.com/nodejs/node/pull/25575
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
Benjamin 2019-01-20 21:53:19 -08:00
parent f698386c7e
commit 0b50972e6c
No known key found for this signature in database
GPG Key ID: 60AB1C1D478E1286
2 changed files with 10 additions and 2 deletions

View File

@ -72,8 +72,12 @@ static void EnvSetter(Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
if (env->options()->pending_deprecation && env->EmitProcessEnvWarning() &&
!value->IsString() && !value->IsNumber() && !value->IsBoolean()) {
// calling env->EmitProcessEnvWarning() sets a variable indicating that
// warnings have been emitted. It should be called last after other
// conditions leading to a warning have been met.
if (env->options()->pending_deprecation && !value->IsString() &&
!value->IsNumber() && !value->IsBoolean() &&
env->EmitProcessEnvWarning()) {
if (ProcessEmitDeprecationWarning(
env,
"Assigning any value other than a string, number, or boolean to a "

View File

@ -12,5 +12,9 @@ common.expectWarning(
'DEP0104'
);
// Make sure setting a valid environment variable doesn't
// result in warning being suppressed, see:
// https://github.com/nodejs/node/pull/25157
process.env.FOO = 'apple';
process.env.ABC = undefined;
assert.strictEqual(process.env.ABC, 'undefined');