Commit 813713f
authored
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: #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>1 parent d37b0d2 commit 813713fCopy full SHA for 813713f
File tree
Expand file treeCollapse file tree
6 files changed
+173
-384
lines changedOpen diff view settings
Filter options
- lib
- internal/fs
- src
- test/parallel
Expand file treeCollapse file tree
6 files changed
+173
-384
lines changedOpen diff view settings
Collapse file
+52-14Lines changed: 52 additions & 14 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
141 | 141 | |
142 | 142 | |
143 | 143 | |
144 | | - |
145 | 144 | |
146 | 145 | |
147 | 146 | |
| ||
243 | 242 | |
244 | 243 | |
245 | 244 | |
246 | | - |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | + |
247 | 249 | |
248 | 250 | |
249 | 251 | |
| ||
285 | 287 | |
286 | 288 | |
287 | 289 | |
288 | | - |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
289 | 297 | |
290 | 298 | |
291 | 299 | |
| ||
438 | 446 | |
439 | 447 | |
440 | 448 | |
441 | | - |
| 449 | + |
| 450 | + |
| 451 | + |
| 452 | + |
442 | 453 | |
443 | 454 | |
444 | 455 | |
| ||
516 | 527 | |
517 | 528 | |
518 | 529 | |
519 | | - |
| 530 | + |
| 531 | + |
| 532 | + |
520 | 533 | |
521 | 534 | |
522 | 535 | |
| ||
562 | 575 | |
563 | 576 | |
564 | 577 | |
565 | | - |
| 578 | + |
| 579 | + |
| 580 | + |
| 581 | + |
| 582 | + |
| 583 | + |
| 584 | + |
566 | 585 | |
567 | 586 | |
568 | 587 | |
| ||
1667 | 1686 | |
1668 | 1687 | |
1669 | 1688 | |
1670 | | - |
1671 | | - |
| 1689 | + |
| 1690 | + |
| 1691 | + |
| 1692 | + |
| 1693 | + |
| 1694 | + |
| 1695 | + |
| 1696 | + |
| 1697 | + |
| 1698 | + |
| 1699 | + |
| 1700 | + |
1672 | 1701 | |
1673 | 1702 | |
1674 | | - |
1675 | | - |
| 1703 | + |
| 1704 | + |
| 1705 | + |
| 1706 | + |
1676 | 1707 | |
1677 | 1708 | |
1678 | 1709 | |
| ||
1852 | 1883 | |
1853 | 1884 | |
1854 | 1885 | |
1855 | | - |
| 1886 | + |
| 1887 | + |
1856 | 1888 | |
1857 | 1889 | |
1858 | 1890 | |
| ||
2652 | 2684 | |
2653 | 2685 | |
2654 | 2686 | |
2655 | | - |
2656 | | - |
| 2687 | + |
2657 | 2688 | |
2658 | 2689 | |
2659 | 2690 | |
| ||
2948 | 2979 | |
2949 | 2980 | |
2950 | 2981 | |
2951 | | - |
| 2982 | + |
| 2983 | + |
| 2984 | + |
| 2985 | + |
| 2986 | + |
| 2987 | + |
| 2988 | + |
| 2989 | + |
2952 | 2990 | |
2953 | 2991 | |
2954 | 2992 | |
|
Collapse file
-106Lines changed: 0 additions & 106 deletions
This file was deleted.
Collapse file
+32Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
349 | 349 | |
350 | 350 | |
351 | 351 | |
| 352 | + |
| 353 | + |
| 354 | + |
| 355 | + |
| 356 | + |
| 357 | + |
| 358 | + |
| 359 | + |
| 360 | + |
| 361 | + |
| 362 | + |
| 363 | + |
| 364 | + |
| 365 | + |
| 366 | + |
| 367 | + |
| 368 | + |
| 369 | + |
| 370 | + |
| 371 | + |
| 372 | + |
| 373 | + |
| 374 | + |
| 375 | + |
| 376 | + |
| 377 | + |
| 378 | + |
| 379 | + |
| 380 | + |
| 381 | + |
| 382 | + |
| 383 | + |
352 | 384 | |
353 | 385 | |
354 | 386 | |
|
0 commit comments