@@ -11,33 +11,26 @@ const assert = require('assert');
11
11
const buffer = require ( 'buffer' ) ;
12
12
13
13
// Monkey-patch setupBufferJS() to have an undefined zeroFill.
14
- const process = require ( 'process' ) ;
15
- const originalBinding = process . binding ;
14
+ const internalBuffer = require ( 'internal/buffer' ) ;
16
15
17
- const binding = originalBinding ( 'buffer' ) ;
18
- const originalSetup = binding . setupBufferJS ;
16
+ const originalSetup = internalBuffer . setupBufferJS ;
19
17
20
- binding . setupBufferJS = ( proto , obj ) => {
18
+ internalBuffer . setupBufferJS = ( proto , obj ) => {
21
19
originalSetup ( proto , obj ) ;
22
20
assert . strictEqual ( obj . zeroFill [ 0 ] , 1 ) ;
23
21
delete obj . zeroFill ;
24
22
} ;
25
23
26
24
const bindingObj = { } ;
27
25
28
- binding . setupBufferJS ( Buffer . prototype , bindingObj ) ;
26
+ internalBuffer . setupBufferJS ( Buffer . prototype , bindingObj ) ;
29
27
assert . strictEqual ( bindingObj . zeroFill , undefined ) ;
30
28
31
- process . binding = ( bindee ) => {
32
- if ( bindee === 'buffer' )
33
- return binding ;
34
- return originalBinding ( bindee ) ;
35
- } ;
36
-
37
29
// Load from file system because internal buffer is already loaded and we're
38
30
// testing code that runs on first load only.
39
31
// Do not move this require() to top of file. It is important that
40
- // `process.binding('buffer').setupBufferJS` be monkey-patched before this runs.
32
+ // `require('internal/buffer').setupBufferJS` be monkey-patched before this
33
+ // runs.
41
34
const monkeyPatchedBuffer = require ( '../../lib/buffer' ) ;
42
35
43
36
// On unpatched buffer, allocUnsafe() should not zero fill memory. It's always
@@ -51,3 +44,6 @@ while (uninitialized.every((val) => val === 0))
51
44
// zero-fill in that case.
52
45
const zeroFilled = monkeyPatchedBuffer . Buffer . allocUnsafe ( 1024 ) ;
53
46
assert ( zeroFilled . every ( ( val ) => val === 0 ) ) ;
47
+
48
+ // setupBufferJS shouldn't still be exposed on the binding
49
+ assert ( ! ( 'setupBufferJs' in process . binding ( 'buffer' ) ) ) ;
0 commit comments