From 23ef3e4cfb8da65b205e6895947375e5284bebdc Mon Sep 17 00:00:00 2001 From: ZYSzys Date: Sun, 12 May 2019 20:30:29 +0800 Subject: fs: extract path conversion and validation to getValidatedPath Almost all path validations within our file system are combined with: ```js path = toPathIfFileURL(path); validatePath(path); ``` So simply extracted them out into `getValidatedPath` function to `internal/fs/utils.js` to DRY up the code and reduce duplicating them. PR-URL: https://github.com/nodejs/node/pull/27656 Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Anto Aravinth Reviewed-By: Rich Trott --- lib/v8.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lib/v8.js') diff --git a/lib/v8.js b/lib/v8.js index efce85533d..2bede41291 100644 --- a/lib/v8.js +++ b/lib/v8.js @@ -25,8 +25,7 @@ const { const assert = require('internal/assert'); const { copy } = internalBinding('buffer'); const { FastBuffer } = require('internal/buffer'); -const { toPathIfFileURL } = require('internal/url'); -const { validatePath } = require('internal/fs/utils'); +const { getValidatedPath } = require('internal/fs/utils'); const { toNamespacedPath } = require('path'); const { createHeapSnapshotStream, @@ -43,8 +42,7 @@ const kHandle = Symbol('kHandle'); function writeHeapSnapshot(filename) { if (filename !== undefined) { - filename = toPathIfFileURL(filename); - validatePath(filename); + filename = getValidatedPath(filename); filename = toNamespacedPath(filename); } return triggerHeapSnapshot(filename); -- cgit v1.2.3