diff --git a/lib/fs.js b/lib/fs.js index 918762877e6f99..a4b38f10899d48 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -181,7 +181,7 @@ function maybeCallback(cb) { function makeCallback(cb) { validateCallback(cb); - return (...args) => cb(...args); + return (...args) => ReflectApply(cb, this, args); } // Special case of `makeCallback()` that is specific to async `*stat()` calls as diff --git a/lib/internal/fs/dir.js b/lib/internal/fs/dir.js index e63d09713bdcca..917319661a647d 100644 --- a/lib/internal/fs/dir.js +++ b/lib/internal/fs/dir.js @@ -99,7 +99,7 @@ class Dir { } if (this[kDirBufferedEntries].length > 0) { - const [ name, type ] = + const { 0: name, 1: type } = ArrayPrototypeSplice(this[kDirBufferedEntries], 0, 2); if (maybeSync) process.nextTick(getDirent, this[kDirPath], name, type, callback); @@ -142,7 +142,7 @@ class Dir { } if (this[kDirBufferedEntries].length > 0) { - const [ name, type ] = + const { 0: name, 1: type } = ArrayPrototypeSplice(this[kDirBufferedEntries], 0, 2); return getDirent(this[kDirPath], name, type); } @@ -182,7 +182,7 @@ class Dir { } if (this[kDirOperationQueue] !== null) { - this[kDirOperationQueue].push(() => { + ArrayPrototypePush(this[kDirOperationQueue], () => { this.close(callback); }); return; diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 34aa897c331dc1..d805f5ca359d05 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -19,6 +19,7 @@ const { PromisePrototypeFinally, PromisePrototypeThen, PromiseResolve, + SafeArrayIterator, Symbol, Uint8Array, } = primordials; @@ -263,7 +264,7 @@ async function fsCall(fn, handle, ...args) { try { handle[kRef](); - return await fn(handle, ...args); + return await fn(handle, ...new SafeArrayIterator(args)); } finally { handle[kUnref](); } diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index d5f3b4c78f16a2..2353fd8c3cbcf2 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -217,7 +217,7 @@ function join(path, name) { 'path', ['string', 'Buffer'], path); } -function getDirents(path, [names, types], callback) { +function getDirents(path, { 0: names, 1: types }, callback) { let i; if (typeof callback === 'function') { const len = names.length;