-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add fast api for
fs.closeSync
only
- Loading branch information
Showing
7 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
// A large number is selected to ensure that the fast path is called. | ||
// Ref: https://github.com/nodejs/node/issues/53902 | ||
for (let i = 0; i < 100_000; i++) { | ||
try { | ||
fs.closeSync(20); | ||
} catch (e) { | ||
// Ignore all EBADF errors. | ||
// EBADF stands for "Bad file descriptor". | ||
if (e.code !== 'EBADF') { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
// This test is to ensure that fs.close() does not crash under pressure. | ||
for (let i = 0; i < 100_000; i++) { | ||
fs.close(100, common.mustCall()); | ||
} | ||
|
||
// This test is to ensure that fs.readFile() does not crash. | ||
// readFile() calls fs.close() internally if the input is not a file descriptor. | ||
// Large number is selected to ensure that the fast path is called. | ||
// Ref: https://github.com/nodejs/node/issues/53902 | ||
for (let i = 0; i < 100_000; i++) { | ||
fs.readFile(__filename, common.mustCall()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters