process: mark process.env as side-effect-free
Read-only access to `process.env` does not have side effects. Refs: https://github.com/nodejs/node/pull/27523 PR-URL: https://github.com/nodejs/node/pull/27684 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Aleksei Koziatinskii <ak239spb@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
parent
2a24aa2bd4
commit
abe82110b7
@ -28,6 +28,7 @@ using v8::Nothing;
|
|||||||
using v8::Object;
|
using v8::Object;
|
||||||
using v8::ObjectTemplate;
|
using v8::ObjectTemplate;
|
||||||
using v8::PropertyCallbackInfo;
|
using v8::PropertyCallbackInfo;
|
||||||
|
using v8::PropertyHandlerFlags;
|
||||||
using v8::String;
|
using v8::String;
|
||||||
using v8::Value;
|
using v8::Value;
|
||||||
|
|
||||||
@ -377,7 +378,8 @@ MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context,
|
|||||||
EscapableHandleScope scope(isolate);
|
EscapableHandleScope scope(isolate);
|
||||||
Local<ObjectTemplate> env_proxy_template = ObjectTemplate::New(isolate);
|
Local<ObjectTemplate> env_proxy_template = ObjectTemplate::New(isolate);
|
||||||
env_proxy_template->SetHandler(NamedPropertyHandlerConfiguration(
|
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));
|
return scope.EscapeMaybe(env_proxy_template->NewInstance(context));
|
||||||
}
|
}
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
@ -19,7 +19,7 @@ session.post('Runtime.evaluate', {
|
|||||||
expression: 'a',
|
expression: 'a',
|
||||||
throwOnSideEffect: true,
|
throwOnSideEffect: true,
|
||||||
contextId: 2 // context's id
|
contextId: 2 // context's id
|
||||||
}, (error, res) => {
|
}, common.mustCall((error, res) => {
|
||||||
assert.ifError(error),
|
assert.ifError(error),
|
||||||
assert.deepStrictEqual(res, {
|
assert.deepStrictEqual(res, {
|
||||||
result: {
|
result: {
|
||||||
@ -28,4 +28,4 @@ session.post('Runtime.evaluate', {
|
|||||||
description: '100'
|
description: '100'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
}));
|
||||||
|
24
test/parallel/test-process-env-sideeffects.js
Normal file
24
test/parallel/test-process-env-sideeffects.js
Normal file
@ -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 inspector.
|
||||||
|
|
||||||
|
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' }
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user