File tree 2 files changed +55
-0
lines changed
2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const { getOptionValue } = require ( 'internal/options' ) ;
4
+ const { Buffer } = require ( 'buffer' ) ;
4
5
5
6
function prepareMainThreadExecution ( ) {
6
7
// Patch the process object with legacy properties and normalizations
@@ -221,6 +222,33 @@ function initializeDeprecations() {
221
222
'process.binding() is deprecated. ' +
222
223
'Please use public APIs instead.' , 'DEP0111' ) ;
223
224
}
225
+
226
+ // Create global.process and global.Buffer as getters so that we have a
227
+ // deprecation path for these in ES Modules.
228
+ // See https://github.com/nodejs/node/pull/26334.
229
+ let _process = process ;
230
+ Object . defineProperty ( global , 'process' , {
231
+ get ( ) {
232
+ return _process ;
233
+ } ,
234
+ set ( value ) {
235
+ _process = value ;
236
+ } ,
237
+ enumerable : false ,
238
+ configurable : true
239
+ } ) ;
240
+
241
+ let _Buffer = Buffer ;
242
+ Object . defineProperty ( global , 'Buffer' , {
243
+ get ( ) {
244
+ return _Buffer ;
245
+ } ,
246
+ set ( value ) {
247
+ _Buffer = value ;
248
+ } ,
249
+ enumerable : false ,
250
+ configurable : true
251
+ } ) ;
224
252
}
225
253
226
254
function setupChildProcessIpcChannel ( ) {
Original file line number Diff line number Diff line change
1
+ /* eslint-disable strict */
2
+ require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
+ const _process = require ( 'process' ) ;
5
+ const { Buffer : _Buffer } = require ( 'buffer' ) ;
6
+
7
+ assert . strictEqual ( process , _process ) ;
8
+ // eslint-disable-next-line no-global-assign
9
+ process = 'asdf' ;
10
+ assert . strictEqual ( process , 'asdf' ) ;
11
+ assert . strictEqual ( global . process , 'asdf' ) ;
12
+ global . process = _process ;
13
+ assert . strictEqual ( process , _process ) ;
14
+ assert . strictEqual (
15
+ typeof Object . getOwnPropertyDescriptor ( global , 'process' ) . get ,
16
+ 'function' ) ;
17
+
18
+ assert . strictEqual ( Buffer , _Buffer ) ;
19
+ // eslint-disable-next-line no-global-assign
20
+ Buffer = 'asdf' ;
21
+ assert . strictEqual ( Buffer , 'asdf' ) ;
22
+ assert . strictEqual ( global . Buffer , 'asdf' ) ;
23
+ global . Buffer = _Buffer ;
24
+ assert . strictEqual ( Buffer , _Buffer ) ;
25
+ assert . strictEqual (
26
+ typeof Object . getOwnPropertyDescriptor ( global , 'Buffer' ) . get ,
27
+ 'function' ) ;
You can’t perform that action at this time.
0 commit comments