node/lib/internal/fs
Joyee Cheung 813713f211
fs: throw errors from sync branches instead of separate implementations
Previously to throw errors from C++ land, sync versions of the fs
were created by copying C++ code from the original implementation
and moving JS code to a separate file. This can lead to several
problems:

1. By moving code to a new file for the sake of moving, it would
  be harder to use git blame to trace changes and harder to backport
  changes to older branches.
2. Scattering the async and sync versions of fs methods in
  different files makes it harder to keep them in sync and
  share code in the prologues and epilogues.
3. Having two copies of code doing almost the same thing results
  in duplication and can be prone to out-of-sync problems when the
  prologue and epilogue get updated.
4. There is a minor cost to startup in adding an additional file.
  This can add up even with the help of snapshots.

This patch moves the JS code back to lib/fs.js to stop 1, 2 & 4
and introduces C++ helpers SyncCallAndThrowIf() and
SyncCallAndThrowOnError() so that the original implementations
can be easily tweaked to allow throwing from C++ and stop 3.

PR-URL: https://github.com/nodejs/node/pull/49913
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-09-30 01:17:00 +00:00
..
cp fs: add support for mode flag to specify the copy behavior 2023-04-20 06:28:18 +00:00
read fs: improve error performance of sync methods 2023-09-17 20:42:46 +00:00
dir.js fs: improve error performance of opendirSync 2023-09-21 17:04:13 +00:00
glob.js fs: add globSync implementation 2023-06-25 14:40:33 +00:00
promises.js fs: adjust position validation in reading methods 2023-09-29 10:56:07 +00:00
recursive_watch.js fs: use kResistStopPropagation 2023-06-24 15:52:38 +00:00
rimraf.js fs: add trailing commas in source files 2023-02-20 01:58:32 +01:00
streams.js errors: improve performance of instantiation 2023-09-28 09:57:38 +00:00
sync_write_stream.js fs: call the callback with an error if writeSync fails 2023-06-26 14:18:58 +00:00
utils.js fs: adjust position validation in reading methods 2023-09-29 10:56:07 +00:00
watchers.js fs: use kResistStopPropagation 2023-06-24 15:52:38 +00:00