summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-08-17 15:03:46 -0400
committercjihrig <cjihrig@gmail.com>2019-08-19 15:34:40 -0400
commit8d100c21c5b7c4687b0fc7f36aeed0a517dca1f7 (patch)
tree8cd2de4c1e3d9683a54e150867133aea4202eb37 /lib
parent3273d0e9514da750405cc2e3662d72dcbb489380 (diff)
downloadandroid-node-v8-8d100c21c5b7c4687b0fc7f36aeed0a517dca1f7.tar.gz
android-node-v8-8d100c21c5b7c4687b0fc7f36aeed0a517dca1f7.tar.bz2
android-node-v8-8d100c21c5b7c4687b0fc7f36aeed0a517dca1f7.zip
fs: use consistent buffer array validation
This commit updates fs.writev() and fs.writevSync() to use the same validation method as filehandle.writev(). PR-URL: https://github.com/nodejs/node/pull/29186 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js27
1 files changed, 4 insertions, 23 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 2c10a5c8d0..37d1eb7917 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -72,6 +72,7 @@ const {
stringToFlags,
stringToSymlinkType,
toUnixTimestamp,
+ validateBufferArray,
validateOffsetLengthRead,
validateOffsetLengthWrite,
validatePath,
@@ -142,19 +143,6 @@ function maybeCallback(cb) {
throw new ERR_INVALID_CALLBACK(cb);
}
-function isBuffersArray(value) {
- if (!Array.isArray(value))
- return false;
-
- for (var i = 0; i < value.length; i += 1) {
- if (!isArrayBufferView(value[i])) {
- return false;
- }
- }
-
- return true;
-}
-
// Ensure that callbacks run in the global context. Only use this function
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
@@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) {
}
validateInt32(fd, 'fd', 0);
-
- if (!isBuffersArray(buffers)) {
- throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
- }
+ validateBufferArray(buffers);
const req = new FSReqCallback();
req.oncomplete = wrapper;
@@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, {
enumerable: false
});
-// fs.writevSync(fd, buffers[, position]);
function writevSync(fd, buffers, position) {
-
validateInt32(fd, 'fd', 0);
- const ctx = {};
+ validateBufferArray(buffers);
- if (!isBuffersArray(buffers)) {
- throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers);
- }
+ const ctx = {};
if (typeof position !== 'number')
position = null;