diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-02-28 02:17:12 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-03-02 21:13:24 +0800 |
commit | 994320b07be5da33e98785a7dab4bd2bb7cb8f12 (patch) | |
tree | b22e4475b2012c9867a6440c8288c967f96711be /lib | |
parent | 1650eaeac4d344a21f08923dc39ab09637f71ab8 (diff) | |
download | android-node-v8-994320b07be5da33e98785a7dab4bd2bb7cb8f12.tar.gz android-node-v8-994320b07be5da33e98785a7dab4bd2bb7cb8f12.tar.bz2 android-node-v8-994320b07be5da33e98785a7dab4bd2bb7cb8f12.zip |
fs: throw writeSync errors in JS
PR-URL: https://github.com/nodejs/node/pull/19041
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.js | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -635,6 +635,8 @@ Object.defineProperty(fs.write, internalUtil.customPromisifyArgs, // fs.writeSync(fd, string[, position[, encoding]]); fs.writeSync = function(fd, buffer, offset, length, position) { validateUint32(fd, 'fd'); + const ctx = {}; + let result; if (isUint8Array(buffer)) { if (position === undefined) position = null; @@ -643,13 +645,18 @@ fs.writeSync = function(fd, buffer, offset, length, position) { if (typeof length !== 'number') length = buffer.length - offset; validateOffsetLengthWrite(offset, length, buffer.byteLength); - return binding.writeBuffer(fd, buffer, offset, length, position); + result = binding.writeBuffer(fd, buffer, offset, length, position, + undefined, ctx); + } else { + if (typeof buffer !== 'string') + buffer += ''; + if (offset === undefined) + offset = null; + result = binding.writeString(fd, buffer, offset, length, + undefined, ctx); } - if (typeof buffer !== 'string') - buffer += ''; - if (offset === undefined) - offset = null; - return binding.writeString(fd, buffer, offset, length, position); + handleErrorFromBinding(ctx); + return result; }; fs.rename = function(oldPath, newPath, callback) { |