diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-09 00:54:31 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-02-26 23:18:12 +0000 |
commit | e9f2cecf1a14285574f9b6104dd690ef92495d74 (patch) | |
tree | 6160626254f229aceff338614f71a2091a55e485 /lib | |
parent | 009e41826f47c595ca994f673023f9380198be36 (diff) | |
download | android-node-v8-e9f2cecf1a14285574f9b6104dd690ef92495d74.tar.gz android-node-v8-e9f2cecf1a14285574f9b6104dd690ef92495d74.tar.bz2 android-node-v8-e9f2cecf1a14285574f9b6104dd690ef92495d74.zip |
Revert "fs: Revert throw on invalid callbacks"
This reverts commit 8250bfd1e5188d5dada58aedf7a991e959d5eaa9.
PR-URL: https://github.com/nodejs/node/pull/18668
Refs: https://github.com/nodejs/node/pull/12562
Refs: https://github.com/nodejs/node/pull/12976
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.js | 54 |
1 files changed, 5 insertions, 49 deletions
@@ -77,7 +77,6 @@ const { kMaxLength } = require('buffer'); const isWindows = process.platform === 'win32'; -const DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG); const errnoException = errors.errnoException; let truncateWarn = true; @@ -106,46 +105,17 @@ function handleErrorFromBinding(ctx) { } } -// TODO(joyeecheung): explore how the deprecation could be solved via linting -// rules. See https://github.com/nodejs/node/pull/12976 -function rethrow() { - process.emitWarning( - 'Calling an asynchronous function without callback is deprecated.', - 'DeprecationWarning', 'DEP0013', rethrow - ); - - // Only enable in debug mode. A backtrace uses ~1000 bytes of heap space and - // is fairly slow to generate. - if (DEBUG) { - var backtrace = new Error(); - return function(err) { - if (err) { - backtrace.stack = `${err.name}: ${err.message}` + - backtrace.stack.substr(backtrace.name.length); - throw backtrace; - } - }; - } - - return function(err) { - if (err) { - throw err; // Forgot a callback but don't know where? Use NODE_DEBUG=fs - } - }; -} - function maybeCallback(cb) { - return typeof cb === 'function' ? cb : rethrow(); + if (typeof cb === 'function') + return cb; + + throw new errors.TypeError('ERR_INVALID_CALLBACK'); } // Ensure that callbacks run in the global context. Only use this function // for callbacks that are passed to the binding layer, callbacks that are // invoked from JS already run in the proper scope. function makeCallback(cb) { - if (cb === undefined) { - return rethrow(); - } - if (typeof cb !== 'function') { throw new errors.TypeError('ERR_INVALID_CALLBACK'); } @@ -159,10 +129,6 @@ function makeCallback(cb) { // an optimization, since the data passed back to the callback needs to be // transformed anyway. function makeStatsCallback(cb) { - if (cb === undefined) { - return rethrow(); - } - if (typeof cb !== 'function') { throw new errors.TypeError('ERR_INVALID_CALLBACK'); } @@ -191,8 +157,6 @@ fs.access = function(path, mode, callback) { if (typeof mode === 'function') { callback = mode; mode = fs.F_OK; - } else if (typeof callback !== 'function') { - throw new errors.TypeError('ERR_INVALID_CALLBACK'); } path = getPathFromURL(path); @@ -218,16 +182,8 @@ fs.accessSync = function(path, mode) { handleErrorFromBinding(ctx); }; -// fs.exists never throws even when the arguments are invalid - if there is -// a callback it would invoke it with false, otherwise it emits a warning -// (see the comments of rethrow()). -// This is to bring it inline with fs.existsSync, which never throws. -// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior fs.exists = function(path, callback) { - if (typeof callback !== 'function') { - rethrow(); - return; - } + maybeCallback(callback); function suppressedCallback(err) { callback(err ? false : true); |