mirror of
https://github.com/nodejs/node.git
synced 2026-12-06 07:38:48 -05:00
fs: throw fs.fstat{Sync} errors in JS
PR-URL: https://github.com/nodejs/node/pull/17914 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
3 files changed
+29
-19
No files matched your search
@@ -23,6 +23,7 @@
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const uv = process.binding('uv');
|
||||
|
||||
// ensure that (read|write|append)FileSync() closes the file descriptor
|
||||
fs.openSync = function() {
|
||||
@@ -39,29 +40,30 @@ fs.writeSync = function() {
|
||||
throw new Error('BAM');
|
||||
};
|
||||
|
||||
process.binding('fs').fstat = function() {
|
||||
throw new Error('BAM');
|
||||
process.binding('fs').fstat = function(fd, _, ctx) {
|
||||
ctx.errno = uv.UV_EBADF;
|
||||
ctx.syscall = 'fstat';
|
||||
};
|
||||
|
||||
let close_called = 0;
|
||||
ensureThrows(function() {
|
||||
fs.readFileSync('dummy');
|
||||
});
|
||||
}, 'EBADF: bad file descriptor, fstat');
|
||||
ensureThrows(function() {
|
||||
fs.writeFileSync('dummy', 'xxx');
|
||||
});
|
||||
}, 'BAM');
|
||||
ensureThrows(function() {
|
||||
fs.appendFileSync('dummy', 'xxx');
|
||||
});
|
||||
}, 'BAM');
|
||||
|
||||
function ensureThrows(cb) {
|
||||
function ensureThrows(cb, message) {
|
||||
let got_exception = false;
|
||||
|
||||
close_called = 0;
|
||||
try {
|
||||
cb();
|
||||
} catch (e) {
|
||||
assert.strictEqual(e.message, 'BAM');
|
||||
assert.strictEqual(e.message, message);
|
||||
got_exception = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user