diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-12-28 23:16:33 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-17 06:20:06 +0800 |
commit | 8c00a809bc08d87776f74c84751607155f3df61f (patch) | |
tree | 190f8d8689797a96cd28282ea860cce48ab3353e /test | |
parent | da7804f25914fe5a460db01c2e234dafc3649dfc (diff) | |
download | android-node-v8-8c00a809bc08d87776f74c84751607155f3df61f.tar.gz android-node-v8-8c00a809bc08d87776f74c84751607155f3df61f.tar.bz2 android-node-v8-8c00a809bc08d87776f74c84751607155f3df61f.zip |
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>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-fs-sync-fd-leak.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/test/parallel/test-fs-sync-fd-leak.js b/test/parallel/test-fs-sync-fd-leak.js index 7e785ea3a2..e7107546e5 100644 --- a/test/parallel/test-fs-sync-fd-leak.js +++ b/test/parallel/test-fs-sync-fd-leak.js @@ -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; } |