3
3
4
4
'use strict' ;
5
5
6
+ const {
7
+ FunctionPrototype,
8
+ FunctionPrototypeCall,
9
+ } = primordials ;
6
10
const {
7
11
ERR_STREAM_PREMATURE_CLOSE
8
12
} = require ( 'internal/errors' ) . codes ;
@@ -53,7 +57,7 @@ function isWritableFinished(stream) {
53
57
return wState . finished || ( wState . ended && wState . length === 0 ) ;
54
58
}
55
59
56
- function nop ( ) { }
60
+ const nop = FunctionPrototype ;
57
61
58
62
function isReadableEnded ( stream ) {
59
63
if ( stream . readableEnded ) return true ;
@@ -110,7 +114,7 @@ function eos(stream, options, callback) {
110
114
if ( stream . destroyed ) willEmitClose = false ;
111
115
112
116
if ( willEmitClose && ( ! stream . readable || readable ) ) return ;
113
- if ( ! readable || readableEnded ) callback . call ( stream ) ;
117
+ if ( ! readable || readableEnded ) FunctionPrototypeCall ( callback , stream ) ;
114
118
} ;
115
119
116
120
let readableEnded = stream . readableEnded ||
@@ -123,23 +127,25 @@ function eos(stream, options, callback) {
123
127
if ( stream . destroyed ) willEmitClose = false ;
124
128
125
129
if ( willEmitClose && ( ! stream . writable || writable ) ) return ;
126
- if ( ! writable || writableFinished ) callback . call ( stream ) ;
130
+ if ( ! writable || writableFinished ) FunctionPrototypeCall ( callback , stream ) ;
127
131
} ;
128
132
129
133
const onerror = ( err ) => {
130
- callback . call ( stream , err ) ;
134
+ FunctionPrototypeCall ( callback , stream , err ) ;
131
135
} ;
132
136
133
137
const onclose = ( ) => {
134
138
if ( readable && ! readableEnded ) {
135
139
if ( ! isReadableEnded ( stream ) )
136
- return callback . call ( stream , new ERR_STREAM_PREMATURE_CLOSE ( ) ) ;
140
+ return FunctionPrototypeCall ( callback , stream ,
141
+ new ERR_STREAM_PREMATURE_CLOSE ( ) ) ;
137
142
}
138
143
if ( writable && ! writableFinished ) {
139
144
if ( ! isWritableFinished ( stream ) )
140
- return callback . call ( stream , new ERR_STREAM_PREMATURE_CLOSE ( ) ) ;
145
+ return FunctionPrototypeCall ( callback , stream ,
146
+ new ERR_STREAM_PREMATURE_CLOSE ( ) ) ;
141
147
}
142
- callback . call ( stream ) ;
148
+ FunctionPrototypeCall ( callback , stream ) ;
143
149
} ;
144
150
145
151
const onrequest = ( ) => {
0 commit comments