@@ -77,7 +77,6 @@ const { kMaxLength } = require('buffer');
7777
7878const isWindows = process . platform === 'win32' ;
7979
80- const DEBUG = process . env . NODE_DEBUG && / f s / . test ( process . env . NODE_DEBUG ) ;
8180const errnoException = errors . errnoException ;
8281
8382let truncateWarn = true ;
@@ -106,46 +105,17 @@ function handleErrorFromBinding(ctx) {
106105 }
107106}
108107
109- // TODO(joyeecheung): explore how the deprecation could be solved via linting
110- // rules. See https://github.com/nodejs/node/pull/12976
111- function rethrow ( ) {
112- process . emitWarning (
113- 'Calling an asynchronous function without callback is deprecated.' ,
114- 'DeprecationWarning' , 'DEP0013' , rethrow
115- ) ;
116-
117- // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and
118- // is fairly slow to generate.
119- if ( DEBUG ) {
120- var backtrace = new Error ( ) ;
121- return function ( err ) {
122- if ( err ) {
123- backtrace . stack = `${ err . name } : ${ err . message } ` +
124- backtrace . stack . substr ( backtrace . name . length ) ;
125- throw backtrace ;
126- }
127- } ;
128- }
129-
130- return function ( err ) {
131- if ( err ) {
132- throw err ; // Forgot a callback but don't know where? Use NODE_DEBUG=fs
133- }
134- } ;
135- }
136-
137108function maybeCallback ( cb ) {
138- return typeof cb === 'function' ? cb : rethrow ( ) ;
109+ if ( typeof cb === 'function' )
110+ return cb ;
111+
112+ throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
139113}
140114
141115// Ensure that callbacks run in the global context. Only use this function
142116// for callbacks that are passed to the binding layer, callbacks that are
143117// invoked from JS already run in the proper scope.
144118function makeCallback ( cb ) {
145- if ( cb === undefined ) {
146- return rethrow ( ) ;
147- }
148-
149119 if ( typeof cb !== 'function' ) {
150120 throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
151121 }
@@ -159,10 +129,6 @@ function makeCallback(cb) {
159129// an optimization, since the data passed back to the callback needs to be
160130// transformed anyway.
161131function makeStatsCallback ( cb ) {
162- if ( cb === undefined ) {
163- return rethrow ( ) ;
164- }
165-
166132 if ( typeof cb !== 'function' ) {
167133 throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
168134 }
@@ -191,8 +157,6 @@ fs.access = function(path, mode, callback) {
191157 if ( typeof mode === 'function' ) {
192158 callback = mode ;
193159 mode = fs . F_OK ;
194- } else if ( typeof callback !== 'function' ) {
195- throw new errors . TypeError ( 'ERR_INVALID_CALLBACK' ) ;
196160 }
197161
198162 path = getPathFromURL ( path ) ;
@@ -218,16 +182,8 @@ fs.accessSync = function(path, mode) {
218182 handleErrorFromBinding ( ctx ) ;
219183} ;
220184
221- // fs.exists never throws even when the arguments are invalid - if there is
222- // a callback it would invoke it with false, otherwise it emits a warning
223- // (see the comments of rethrow()).
224- // This is to bring it inline with fs.existsSync, which never throws.
225- // TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
226185fs . exists = function ( path , callback ) {
227- if ( typeof callback !== 'function' ) {
228- rethrow ( ) ;
229- return ;
230- }
186+ maybeCallback ( callback ) ;
231187
232188 function suppressedCallback ( err ) {
233189 callback ( err ? false : true ) ;
0 commit comments