| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,15 +33,22 @@ const kIoMaxLength = 2 ** 31 - 1; | |||
| 33 | 33 | // in case they are created but never used due to an exception. | |
| 34 | 34 | ||
| 35 | 35 | const { | |
| 36 | - Map, | ||
| 36 | + ArrayPrototypePush, | ||
| 37 | + BigIntPrototypeToString, | ||
| 37 | 38 | MathMax, | |
| 38 | 39 | Number, | |
| 39 | 40 | NumberIsSafeInteger, | |
| 40 | 41 | ObjectCreate, | |
| 41 | 42 | ObjectDefineProperties, | |
| 42 | 43 | ObjectDefineProperty, | |
| 43 | 44 | Promise, | |
| 45 | + ReflectApply, | ||
| 46 | + RegExpPrototypeExec, | ||
| 47 | + SafeMap, | ||
| 44 | 48 | String, | |
| 49 | + StringPrototypeCharCodeAt, | ||
| 50 | + StringPrototypeIndexOf, | ||
| 51 | + StringPrototypeSlice, | ||
| 45 | 52 | } = primordials; | |
| 46 | 53 | ||
| 47 | 54 | const { fs: constants } = internalBinding('constants'); | |
@@ -329,7 +336,7 @@ function readFile(path, options, callback) { | |||
| 329 | 336 | } | |
| 330 | 337 | if (context.isUserFd) { | |
| 331 | 338 | process.nextTick(function tick(context) { | |
| 332 | - readFileAfterOpen.call({ context }, null, path); | ||
| 339 | + ReflectApply(readFileAfterOpen, { context }, [null, path]); | ||
| 333 | 340 | }, context); | |
| 334 | 341 | return; | |
| 335 | 342 | } | |
@@ -414,7 +421,7 @@ function readFileSync(path, options) { | |||
| 414 | 421 | buffer = Buffer.allocUnsafe(8192); | |
| 415 | 422 | bytesRead = tryReadSync(fd, isUserFd, buffer, 0, 8192); | |
| 416 | 423 | if (bytesRead !== 0) { | |
| 417 | - buffers.push(buffer.slice(0, bytesRead)); | ||
| 424 | + ArrayPrototypePush(buffers, buffer.slice(0, bytesRead)); | ||
| 418 | 425 | } | |
| 419 | 426 | pos += bytesRead; | |
| 420 | 427 | } while (bytesRead !== 0); | |
@@ -1580,7 +1587,7 @@ function watch(filename, options, listener) { | |||
| 1580 | 1587 | } | |
| 1581 | 1588 | ||
| 1582 | 1589 | ||
| 1583 | - const statWatchers = new Map(); | ||
| 1590 | + const statWatchers = new SafeMap(); | ||
| 1584 | 1591 | ||
| 1585 | 1592 | function watchFile(filename, options, listener) { | |
| 1586 | 1593 | filename = getValidatedPath(filename); | |
@@ -1652,13 +1659,13 @@ if (isWindows) { | |||
| 1652 | 1659 | // slash. | |
| 1653 | 1660 | const splitRootRe = /^(?:[a-zA-Z]:|[\\/]{2}[^\\/]+[\\/][^\\/]+)?[\\/]*/; | |
| 1654 | 1661 | splitRoot = function splitRoot(str) { | |
| 1655 | - return splitRootRe.exec(str)[0]; | ||
| 1662 | + return RegExpPrototypeExec(splitRootRe, str)[0]; | ||
| 1656 | 1663 | }; | |
| 1657 | 1664 | } else { | |
| 1658 | 1665 | splitRoot = function splitRoot(str) { | |
| 1659 | 1666 | for (let i = 0; i < str.length; ++i) { | |
| 1660 | - if (str.charCodeAt(i) !== CHAR_FORWARD_SLASH) | ||
| 1661 | - return str.slice(0, i); | ||
| 1667 | + if (StringPrototypeCharCodeAt(str, i) !== CHAR_FORWARD_SLASH) | ||
| 1668 | + return StringPrototypeSlice(str, 0, i); | ||
| 1662 | 1669 | } | |
| 1663 | 1670 | return str; | |
| 1664 | 1671 | }; | |
@@ -1679,7 +1686,7 @@ let nextPart; | |||
| 1679 | 1686 | if (isWindows) { | |
| 1680 | 1687 | nextPart = function nextPart(p, i) { | |
| 1681 | 1688 | for (; i < p.length; ++i) { | |
| 1682 | - const ch = p.charCodeAt(i); | ||
| 1689 | + const ch = StringPrototypeCharCodeAt(p, i); | ||
| 1683 | 1690 | ||
| 1684 | 1691 | // Check for a separator character | |
| 1685 | 1692 | if (ch === CHAR_BACKWARD_SLASH || ch === CHAR_FORWARD_SLASH) | |
@@ -1688,7 +1695,9 @@ if (isWindows) { | |||
| 1688 | 1695 | return -1; | |
| 1689 | 1696 | }; | |
| 1690 | 1697 | } else { | |
| 1691 | - nextPart = function nextPart(p, i) { return p.indexOf('/', i); }; | ||
| 1698 | + nextPart = function nextPart(p, i) { | ||
| 1699 | + return StringPrototypeIndexOf(p, '/', i); | ||
| 1700 | + }; | ||
| 1692 | 1701 | } | |
| 1693 | 1702 | ||
| 1694 | 1703 | const emptyObj = ObjectCreate(null); | |
@@ -1740,13 +1749,13 @@ function realpathSync(p, options) { | |||
| 1740 | 1749 | const result = nextPart(p, pos); | |
| 1741 | 1750 | previous = current; | |
| 1742 | 1751 | if (result === -1) { | |
| 1743 | - const last = p.slice(pos); | ||
| 1752 | + const last = StringPrototypeSlice(p, pos); | ||
| 1744 | 1753 | current += last; | |
| 1745 | 1754 | base = previous + last; | |
| 1746 | 1755 | pos = p.length; | |
| 1747 | 1756 | } else { | |
| 1748 | - current += p.slice(pos, result + 1); | ||
| 1749 | - base = previous + p.slice(pos, result); | ||
| 1757 | + current += StringPrototypeSlice(p, pos, result + 1); | ||
| 1758 | + base = previous + StringPrototypeSlice(p, pos, result); | ||
| 1750 | 1759 | pos = result + 1; | |
| 1751 | 1760 | } | |
| 1752 | 1761 | ||
@@ -1783,8 +1792,8 @@ function realpathSync(p, options) { | |||
| 1783 | 1792 | let linkTarget = null; | |
| 1784 | 1793 | let id; | |
| 1785 | 1794 | if (!isWindows) { | |
| 1786 | - const dev = stats[0].toString(32); | ||
| 1787 | - const ino = stats[7].toString(32); | ||
| 1795 | + const dev = BigIntPrototypeToString(stats[0], 32); | ||
| 1796 | + const ino = BigIntPrototypeToString(stats[7], 32); | ||
| 1788 | 1797 | id = `${dev}:${ino}`; | |
| 1789 | 1798 | if (seenLinks[id]) { | |
| 1790 | 1799 | linkTarget = seenLinks[id]; | |
@@ -1804,7 +1813,7 @@ function realpathSync(p, options) { | |||
| 1804 | 1813 | } | |
| 1805 | 1814 | ||
| 1806 | 1815 | // Resolve the link, then start over | |
| 1807 | - p = pathModule.resolve(resolvedLink, p.slice(pos)); | ||
| 1816 | + p = pathModule.resolve(resolvedLink, StringPrototypeSlice(p, pos)); | ||
| 1808 | 1817 | ||
| 1809 | 1818 | // Skip over roots | |
| 1810 | 1819 | current = base = splitRoot(p); | |
@@ -1883,13 +1892,13 @@ function realpath(p, options, callback) { | |||
| 1883 | 1892 | const result = nextPart(p, pos); | |
| 1884 | 1893 | previous = current; | |
| 1885 | 1894 | if (result === -1) { | |
| 1886 | - const last = p.slice(pos); | ||
| 1895 | + const last = StringPrototypeSlice(p, pos); | ||
| 1887 | 1896 | current += last; | |
| 1888 | 1897 | base = previous + last; | |
| 1889 | 1898 | pos = p.length; | |
| 1890 | 1899 | } else { | |
| 1891 | - current += p.slice(pos, result + 1); | ||
| 1892 | - base = previous + p.slice(pos, result); | ||
| 1900 | + current += StringPrototypeSlice(p, pos, result + 1); | ||
| 1901 | + base = previous + StringPrototypeSlice(p, pos, result); | ||
| 1893 | 1902 | pos = result + 1; | |
| 1894 | 1903 | } | |
| 1895 | 1904 | ||
@@ -1919,8 +1928,8 @@ function realpath(p, options, callback) { | |||
| 1919 | 1928 | // `dev`/`ino` always return 0 on windows, so skip the check. | |
| 1920 | 1929 | let id; | |
| 1921 | 1930 | if (!isWindows) { | |
| 1922 | - const dev = stats.dev.toString(32); | ||
| 1923 | - const ino = stats.ino.toString(32); | ||
| 1931 | + const dev = BigIntPrototypeToString(stats.dev, 32); | ||
| 1932 | + const ino = BigIntPrototypeToString(stats.ino, 32); | ||
| 1924 | 1933 | id = `${dev}:${ino}`; | |
| 1925 | 1934 | if (seenLinks[id]) { | |
| 1926 | 1935 | return gotTarget(null, seenLinks[id]); | |
@@ -1944,7 +1953,7 @@ function realpath(p, options, callback) { | |||
| 1944 | 1953 | ||
| 1945 | 1954 | function gotResolvedLink(resolvedLink) { | |
| 1946 | 1955 | // Resolve the link, then start over | |
| 1947 | - p = pathModule.resolve(resolvedLink, p.slice(pos)); | ||
| 1956 | + p = pathModule.resolve(resolvedLink, StringPrototypeSlice(p, pos)); | ||
| 1948 | 1957 | current = base = splitRoot(p); | |
| 1949 | 1958 | pos = current.length; | |
| 1950 | 1959 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,10 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypePush, | ||
| 5 | + ArrayPrototypeSlice, | ||
| 6 | + ArrayPrototypeSplice, | ||
| 7 | + FunctionPrototypeBind, | ||
| 4 | 8 | ObjectDefineProperty, | |
| 5 | 9 | Symbol, | |
| 6 | 10 | SymbolAsyncIterator, | |
@@ -61,9 +65,10 @@ class Dir { | |||
| 61 | 65 | ||
| 62 | 66 | validateUint32(this[kDirOptions].bufferSize, 'options.bufferSize', true); | |
| 63 | 67 | ||
| 64 | - this[kDirReadPromisified] = | ||
| 65 | - internalUtil.promisify(this[kDirReadImpl]).bind(this, false); | ||
| 66 | - this[kDirClosePromisified] = internalUtil.promisify(this.close).bind(this); | ||
| 68 | + this[kDirReadPromisified] = FunctionPrototypeBind( | ||
| 69 | + internalUtil.promisify(this[kDirReadImpl]), this, false); | ||
| 70 | + this[kDirClosePromisified] = FunctionPrototypeBind( | ||
| 71 | + internalUtil.promisify(this.close), this); | ||
| 67 | 72 | } | |
| 68 | 73 | ||
| 69 | 74 | get path() { | |
@@ -86,14 +91,15 @@ class Dir { | |||
| 86 | 91 | } | |
| 87 | 92 | ||
| 88 | 93 | if (this[kDirOperationQueue] !== null) { | |
| 89 | - this[kDirOperationQueue].push(() => { | ||
| 94 | + ArrayPrototypePush(this[kDirOperationQueue], () => { | ||
| 90 | 95 | this[kDirReadImpl](maybeSync, callback); | |
| 91 | 96 | }); | |
| 92 | 97 | return; | |
| 93 | 98 | } | |
| 94 | 99 | ||
| 95 | 100 | if (this[kDirBufferedEntries].length > 0) { | |
| 96 | - const [ name, type ] = this[kDirBufferedEntries].splice(0, 2); | ||
| 101 | + const [ name, type ] = | ||
| 102 | + ArrayPrototypeSplice(this[kDirBufferedEntries], 0, 2); | ||
| 97 | 103 | if (maybeSync) | |
| 98 | 104 | process.nextTick(getDirent, this[kDirPath], name, type, callback); | |
| 99 | 105 | else | |
@@ -113,7 +119,7 @@ class Dir { | |||
| 113 | 119 | return callback(err, result); | |
| 114 | 120 | } | |
| 115 | 121 | ||
| 116 | - this[kDirBufferedEntries] = result.slice(2); | ||
| 122 | + this[kDirBufferedEntries] = ArrayPrototypeSlice(result, 2); | ||
| 117 | 123 | getDirent(this[kDirPath], result[0], result[1], callback); | |
| 118 | 124 | }; | |
| 119 | 125 | ||
@@ -135,7 +141,8 @@ class Dir { | |||
| 135 | 141 | } | |
| 136 | 142 | ||
| 137 | 143 | if (this[kDirBufferedEntries].length > 0) { | |
| 138 | - const [ name, type ] = this[kDirBufferedEntries].splice(0, 2); | ||
| 144 | + const [ name, type ] = | ||
| 145 | + ArrayPrototypeSplice(this[kDirBufferedEntries], 0, 2); | ||
| 139 | 146 | return getDirent(this[kDirPath], name, type); | |
| 140 | 147 | } | |
| 141 | 148 | ||
@@ -152,7 +159,7 @@ class Dir { | |||
| 152 | 159 | return result; | |
| 153 | 160 | } | |
| 154 | 161 | ||
| 155 | - this[kDirBufferedEntries] = result.slice(2); | ||
| 162 | + this[kDirBufferedEntries] = ArrayPrototypeSlice(result, 2); | ||
| 156 | 163 | return getDirent(this[kDirPath], result[0], result[1]); | |
| 157 | 164 | } | |
| 158 | 165 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,12 +10,14 @@ const kReadFileMaxChunkSize = 2 ** 14; | |||
| 10 | 10 | const kWriteFileMaxChunkSize = 2 ** 14; | |
| 11 | 11 | ||
| 12 | 12 | const { | |
| 13 | + ArrayPrototypePush, | ||
| 13 | 14 | Error, | |
| 14 | 15 | MathMax, | |
| 15 | 16 | MathMin, | |
| 16 | 17 | NumberIsSafeInteger, | |
| 17 | 18 | Promise, | |
| 18 | 19 | PromisePrototypeFinally, | |
| 20 | + PromisePrototypeThen, | ||
| 19 | 21 | PromiseResolve, | |
| 20 | 22 | Symbol, | |
| 21 | 23 | Uint8Array, | |
@@ -178,18 +180,21 @@ class FileHandle extends JSTransferable { | |||
| 178 | 180 | this[kRefs]--; | |
| 179 | 181 | if (this[kRefs] === 0) { | |
| 180 | 182 | this[kFd] = -1; | |
| 181 | - this[kClosePromise] = this[kHandle].close().finally(() => { | ||
| 182 | - this[kClosePromise] = undefined; | ||
| 183 | - }); | ||
| 183 | + this[kClosePromise] = PromisePrototypeFinally( | ||
| 184 | + this[kHandle].close(), | ||
| 185 | + () => { this[kClosePromise] = undefined; } | ||
| 186 | + ); | ||
| 184 | 187 | } else { | |
| 185 | - this[kClosePromise] = new Promise((resolve, reject) => { | ||
| 186 | - this[kCloseResolve] = resolve; | ||
| 187 | - this[kCloseReject] = reject; | ||
| 188 | - }).finally(() => { | ||
| 189 | - this[kClosePromise] = undefined; | ||
| 190 | - this[kCloseReject] = undefined; | ||
| 191 | - this[kCloseResolve] = undefined; | ||
| 192 | - }); | ||
| 188 | + this[kClosePromise] = PromisePrototypeFinally( | ||
| 189 | + new Promise((resolve, reject) => { | ||
| 190 | + this[kCloseResolve] = resolve; | ||
| 191 | + this[kCloseReject] = reject; | ||
| 192 | + }), () => { | ||
| 193 | + this[kClosePromise] = undefined; | ||
| 194 | + this[kCloseReject] = undefined; | ||
| 195 | + this[kCloseResolve] = undefined; | ||
| 196 | + } | ||
| 197 | + ); | ||
| 193 | 198 | } | |
| 194 | 199 | ||
| 195 | 200 | return this[kClosePromise]; | |
@@ -243,9 +248,11 @@ async function fsCall(fn, handle, ...args) { | |||
| 243 | 248 | handle[kRefs]--; | |
| 244 | 249 | if (handle[kRefs] === 0) { | |
| 245 | 250 | handle[kFd] = -1; | |
| 246 | - handle[kHandle] | ||
| 247 | - .close() | ||
| 248 | - .then(handle[kCloseResolve], handle[kCloseReject]); | ||
| 251 | + PromisePrototypeThen( | ||
| 252 | + handle[kHandle].close(), | ||
| 253 | + handle[kCloseResolve], | ||
| 254 | + handle[kCloseReject] | ||
| 255 | + ); | ||
| 249 | 256 | } | |
| 250 | 257 | } | |
| 251 | 258 | } | |
@@ -307,7 +314,7 @@ async function readFileHandle(filehandle, options) { | |||
| 307 | 314 | await read(filehandle, buf, 0, chunkSize, -1); | |
| 308 | 315 | endOfFile = bytesRead === 0; | |
| 309 | 316 | if (bytesRead > 0) | |
| 310 | - chunks.push(buffer.slice(0, bytesRead)); | ||
| 317 | + ArrayPrototypePush(chunks, buffer.slice(0, bytesRead)); | ||
| 311 | 318 | } while (!endOfFile); | |
| 312 | 319 | ||
| 313 | 320 | const result = Buffer.concat(chunks); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypePush, | ||
| 4 | 5 | MathMin, | |
| 6 | + ReflectApply, | ||
| 5 | 7 | } = primordials; | |
| 6 | 8 | ||
| 7 | 9 | const { Buffer } = require('buffer'); | |
@@ -42,7 +44,7 @@ function readFileAfterRead(err, bytesRead) { | |||
| 42 | 44 | // Unknown size, just read until we don't get bytes. | |
| 43 | 45 | const buffer = bytesRead === kReadFileUnknownBufferLength ? | |
| 44 | 46 | context.buffer : context.buffer.slice(0, bytesRead); | |
| 45 | - context.buffers.push(buffer); | ||
| 47 | + ArrayPrototypePush(context.buffers, buffer); | ||
| 46 | 48 | } | |
| 47 | 49 | context.read(); | |
| 48 | 50 | } | |
@@ -118,7 +120,7 @@ class ReadFileContext { | |||
| 118 | 120 | close(err) { | |
| 119 | 121 | if (this.isUserFd) { | |
| 120 | 122 | process.nextTick(function tick(context) { | |
| 121 | - readFileAfterClose.call({ context }, null); | ||
| 123 | + ReflectApply(readFileAfterClose, { context }, [null]); | ||
| 122 | 124 | }, this); | |
| 123 | 125 | return; | |
| 124 | 126 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,8 +7,9 @@ | |||
| 7 | 7 | 'use strict'; | |
| 8 | 8 | ||
| 9 | 9 | const { | |
| 10 | + ArrayPrototypeForEach, | ||
| 10 | 11 | Promise, | |
| 11 | - Set, | ||
| 12 | + SafeSet, | ||
| 12 | 13 | } = primordials; | |
| 13 | 14 | ||
| 14 | 15 | const { Buffer } = require('buffer'); | |
@@ -30,8 +31,8 @@ const { | |||
| 30 | 31 | const { sep } = require('path'); | |
| 31 | 32 | const { setTimeout } = require('timers'); | |
| 32 | 33 | const { sleep } = require('internal/util'); | |
| 33 | - const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']); | ||
| 34 | - const retryErrorCodes = new Set( | ||
| 34 | + const notEmptyErrorCodes = new SafeSet(['ENOTEMPTY', 'EEXIST', 'EPERM']); | ||
| 35 | + const retryErrorCodes = new SafeSet( | ||
| 35 | 36 | ['EBUSY', 'EMFILE', 'ENFILE', 'ENOTEMPTY', 'EPERM']); | |
| 36 | 37 | const isWindows = process.platform === 'win32'; | |
| 37 | 38 | const epermHandler = isWindows ? fixWinEPERM : _rmdir; | |
@@ -139,7 +140,7 @@ function _rmchildren(path, options, callback) { | |||
| 139 | 140 | ||
| 140 | 141 | let done = false; | |
| 141 | 142 | ||
| 142 | - files.forEach((child) => { | ||
| 143 | + ArrayPrototypeForEach(files, (child) => { | ||
| 143 | 144 | const childPath = Buffer.concat([pathBuf, separator, child]); | |
| 144 | 145 | ||
| 145 | 146 | rimraf(childPath, options, (err) => { | |
@@ -240,7 +241,7 @@ function _rmdirSync(path, options, originalErr) { | |||
| 240 | 241 | // around that issue by retrying on Windows. | |
| 241 | 242 | const pathBuf = Buffer.from(path); | |
| 242 | 243 | ||
| 243 | - readdirSync(pathBuf, readdirEncoding).forEach((child) => { | ||
| 244 | + ArrayPrototypeForEach(readdirSync(pathBuf, readdirEncoding), (child) => { | ||
| 244 | 245 | const childPath = Buffer.concat([pathBuf, separator, child]); | |
| 245 | 246 | ||
| 246 | 247 | rimrafSync(childPath, options); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments