@@ -46,10 +46,8 @@ const {
4646 JSONParse,
4747 ObjectDefineProperty,
4848 ObjectGetPrototypeOf,
49- ObjectPreventExtensions,
5049 ObjectSetPrototypeOf,
51- ReflectGet,
52- ReflectSet,
50+ ObjectFreeze,
5351 SymbolToStringTag,
5452 globalThis,
5553} = primordials ;
@@ -91,75 +89,18 @@ process._exiting = false;
9189// process.config is serialized config.gypi
9290const nativeModule = internalBinding ( 'builtins' ) ;
9391
94- // TODO(@jasnell): Once this has gone through one full major
95- // release cycle, remove the Proxy and setter and update the
96- // getter to either return a read-only object or always return
97- // a freshly parsed version of nativeModule.config.
98-
99- const deprecationHandler = {
100- warned : false ,
101- message : 'Setting process.config is deprecated. ' +
102- 'In the future the property will be read-only.' ,
103- code : 'DEP0150' ,
104- maybeWarn ( ) {
105- if ( ! this . warned ) {
106- process . emitWarning ( this . message , {
107- type : 'DeprecationWarning' ,
108- code : this . code
109- } ) ;
110- this . warned = true ;
111- }
112- } ,
113-
114- defineProperty ( target , key , descriptor ) {
115- this . maybeWarn ( ) ;
116- return ObjectDefineProperty ( target , key , descriptor ) ;
117- } ,
118-
119- deleteProperty ( target , key ) {
120- this . maybeWarn ( ) ;
121- delete target [ key ] ;
122- } ,
123-
124- preventExtensions ( target ) {
125- this . maybeWarn ( ) ;
126- return ObjectPreventExtensions ( target ) ;
127- } ,
128-
129- set ( target , key , value ) {
130- this . maybeWarn ( ) ;
131- return ReflectSet ( target , key , value ) ;
132- } ,
133-
134- get ( target , key , receiver ) {
135- const val = ReflectGet ( target , key , receiver ) ;
136- if ( val != null && typeof val === 'object' ) {
137- // eslint-disable-next-line node-core/prefer-primordials
138- return new Proxy ( val , deprecationHandler ) ;
139- }
140- return val ;
141- } ,
142-
143- setPrototypeOf ( target , proto ) {
144- this . maybeWarn ( ) ;
145- return ObjectSetPrototypeOf ( target , proto ) ;
146- }
147- } ;
148-
149- // eslint-disable-next-line node-core/prefer-primordials
150- let processConfig = new Proxy (
151- JSONParse ( nativeModule . config ) ,
152- deprecationHandler ) ;
92+ const processConfig = JSONParse ( nativeModule . config , ( _key , value ) => {
93+ // The `reviver` argument of the JSONParse method will visit all the values of
94+ // the parsed config, including the "root" object, so there is no need to
95+ // explicitly freeze the config outside of this method
96+ return ObjectFreeze ( value ) ;
97+ } ) ;
15398
15499ObjectDefineProperty ( process , 'config' , {
155100 __proto__ : null ,
156101 enumerable : true ,
157102 configurable : true ,
158- get ( ) { return processConfig ; } ,
159- set ( value ) {
160- deprecationHandler . maybeWarn ( ) ;
161- processConfig = value ;
162- }
103+ value : processConfig ,
163104} ) ;
164105
165106require ( 'internal/worker/js_transferable' ) . setup ( ) ;
0 commit comments