Skip to content

Commit

Permalink
process: mark process.env as side-effect-free
Browse files Browse the repository at this point in the history
Read-only access to `process.env` does not have side effects.

Refs: nodejs#27523
  • Loading branch information
addaleax committed May 14, 2019
1 parent 815b3aa commit 5b79b17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using v8::Nothing;
using v8::Object;
using v8::ObjectTemplate;
using v8::PropertyCallbackInfo;
using v8::PropertyHandlerFlags;
using v8::String;
using v8::Value;

Expand Down Expand Up @@ -377,7 +378,8 @@ MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context,
EscapableHandleScope scope(isolate);
Local<ObjectTemplate> env_proxy_template = ObjectTemplate::New(isolate);
env_proxy_template->SetHandler(NamedPropertyHandlerConfiguration(
EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, data));
EnvGetter, EnvSetter, EnvQuery, EnvDeleter, EnvEnumerator, data,
PropertyHandlerFlags::kHasNoSideEffect));
return scope.EscapeMaybe(env_proxy_template->NewInstance(context));
}
} // namespace node
24 changes: 24 additions & 0 deletions test/parallel/test-process-env-sideeffects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

// Test that read-only process.env access is considered to have no
// side-effects by the insepctor.

const assert = require('assert');
const inspector = require('inspector');

const session = new inspector.Session();
session.connect();

process.env.TESTVAR = 'foobar';

session.post('Runtime.evaluate', {
expression: 'process.env.TESTVAR',
throwOnSideEffect: true
}, (error, res) => {
assert.ifError(error);
assert.deepStrictEqual(res, {
result: { type: 'string', value: 'foobar' }
});
});

0 comments on commit 5b79b17

Please sign in to comment.