@@ -43,7 +43,10 @@ const {
43
43
JSONParse,
44
44
ObjectDefineProperty,
45
45
ObjectGetPrototypeOf,
46
+ ObjectPreventExtensions,
46
47
ObjectSetPrototypeOf,
48
+ ReflectGet,
49
+ ReflectSet,
47
50
SymbolToStringTag,
48
51
} = primordials ;
49
52
const config = internalBinding ( 'config' ) ;
@@ -59,7 +62,74 @@ process._exiting = false;
59
62
60
63
// process.config is serialized config.gypi
61
64
const nativeModule = internalBinding ( 'native_module' ) ;
62
- process . config = JSONParse ( nativeModule . config ) ;
65
+
66
+ // TODO(@jasnell): Once this has gone through one full major
67
+ // release cycle, remove the Proxy and setter and update the
68
+ // getter to either return a read-only object or always return
69
+ // a freshly parsed version of nativeModule.config.
70
+
71
+ const deprecationHandler = {
72
+ warned : false ,
73
+ message : 'Setting process.config is deprecated. ' +
74
+ 'In the future the property will be read-only.' ,
75
+ code : 'DEP0XXX' ,
76
+ maybeWarn ( ) {
77
+ if ( ! this . warned ) {
78
+ process . emitWarning ( this . message , {
79
+ type : 'DeprecationWarning' ,
80
+ code : this . code
81
+ } ) ;
82
+ this . warned = true ;
83
+ }
84
+ } ,
85
+
86
+ defineProperty ( target , key , descriptor ) {
87
+ this . maybeWarn ( ) ;
88
+ return ObjectDefineProperty ( target , key , descriptor ) ;
89
+ } ,
90
+
91
+ deleteProperty ( target , key ) {
92
+ this . maybeWarn ( ) ;
93
+ delete target [ key ] ;
94
+ } ,
95
+
96
+ preventExtensions ( target ) {
97
+ this . maybeWarn ( ) ;
98
+ return ObjectPreventExtensions ( target ) ;
99
+ } ,
100
+
101
+ set ( target , key , value ) {
102
+ this . maybeWarn ( ) ;
103
+ return ReflectSet ( target , key , value ) ;
104
+ } ,
105
+
106
+ get ( target , key , receiver ) {
107
+ const val = ReflectGet ( target , key , receiver ) ;
108
+ if ( val != null && typeof val === 'object' )
109
+ return new Proxy ( val , deprecationHandler ) ;
110
+ return val ;
111
+ } ,
112
+
113
+ setPrototypeOf ( target , proto ) {
114
+ this . maybeWarn ( ) ;
115
+ return ObjectSetPrototypeOf ( target , proto ) ;
116
+ }
117
+ } ;
118
+
119
+ let processConfig = new Proxy (
120
+ JSONParse ( nativeModule . config ) ,
121
+ deprecationHandler ) ;
122
+
123
+ ObjectDefineProperty ( process , 'config' , {
124
+ enumerable : true ,
125
+ configurable : true ,
126
+ get ( ) { return processConfig ; } ,
127
+ set ( value ) {
128
+ deprecationHandler . maybeWarn ( ) ;
129
+ processConfig = value ;
130
+ }
131
+ } ) ;
132
+
63
133
require ( 'internal/worker/js_transferable' ) . setup ( ) ;
64
134
65
135
// Bootstrappers for all threads, including worker threads and main thread
0 commit comments