| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,16 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | + ArrayPrototypeForEach, | ||
| 4 | 5 | ArrayPrototypeJoin, | |
| 5 | 6 | ObjectDefineProperty, | |
| 6 | 7 | ObjectPrototypeHasOwnProperty, | |
| 7 | 8 | SafeMap, | |
| 8 | 9 | SafeSet, | |
| 10 | + StringPrototypeCharCodeAt, | ||
| 11 | + StringPrototypeIncludes, | ||
| 12 | + StringPrototypeSlice, | ||
| 13 | + StringPrototypeStartsWith, | ||
| 9 | 14 | } = primordials; | |
| 10 | 15 | const { | |
| 11 | 16 | ERR_MANIFEST_DEPENDENCY_MISSING, | |
@@ -15,8 +20,7 @@ const { NativeModule } = require('internal/bootstrap/loaders'); | |||
| 15 | 20 | ||
| 16 | 21 | const { validateString } = require('internal/validators'); | |
| 17 | 22 | const path = require('path'); | |
| 18 | - const { pathToFileURL, fileURLToPath } = require('internal/url'); | ||
| 19 | - const { URL } = require('url'); | ||
| 23 | + const { pathToFileURL, fileURLToPath, URL } = require('internal/url'); | ||
| 20 | 24 | ||
| 21 | 25 | const { getOptionValue } = require('internal/options'); | |
| 22 | 26 | const userConditions = getOptionValue('--conditions'); | |
@@ -119,20 +123,20 @@ function makeRequireFunction(mod, redirects) { | |||
| 119 | 123 | * translates it to FEFF, the UTF-16 BOM. | |
| 120 | 124 | */ | |
| 121 | 125 | function stripBOM(content) { | |
| 122 | - if (content.charCodeAt(0) === 0xFEFF) { | ||
| 123 | - content = content.slice(1); | ||
| 126 | + if (StringPrototypeCharCodeAt(content) === 0xFEFF) { | ||
| 127 | + content = StringPrototypeSlice(content, 1); | ||
| 124 | 128 | } | |
| 125 | 129 | return content; | |
| 126 | 130 | } | |
| 127 | 131 | ||
| 128 | 132 | function addBuiltinLibsToObject(object) { | |
| 129 | 133 | // Make built-in modules available directly (loaded lazily). | |
| 130 | 134 | const { builtinModules } = require('internal/modules/cjs/loader').Module; | |
| 131 | - builtinModules.forEach((name) => { | ||
| 135 | + ArrayPrototypeForEach(builtinModules, (name) => { | ||
| 132 | 136 | // Neither add underscored modules, nor ones that contain slashes (e.g., | |
| 133 | 137 | // 'fs/promises') or ones that are already defined. | |
| 134 | - if (name.startsWith('_') || | ||
| 135 | - name.includes('/') || | ||
| 138 | + if (StringPrototypeStartsWith(name, '_') || | ||
| 139 | + StringPrototypeIncludes(name, '/') || | ||
| 136 | 140 | ObjectPrototypeHasOwnProperty(object, name)) { | |
| 137 | 141 | return; | |
| 138 | 142 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,10 +23,17 @@ | |||
| 23 | 23 | ||
| 24 | 24 | const { | |
| 25 | 25 | ArrayIsArray, | |
| 26 | + ArrayPrototypeConcat, | ||
| 27 | + ArrayPrototypeFilter, | ||
| 28 | + ArrayPrototypeIncludes, | ||
| 29 | + ArrayPrototypeIndexOf, | ||
| 26 | 30 | ArrayPrototypeJoin, | |
| 31 | + ArrayPrototypePush, | ||
| 32 | + ArrayPrototypeSlice, | ||
| 33 | + ArrayPrototypeSplice, | ||
| 34 | + Boolean, | ||
| 27 | 35 | Error, | |
| 28 | 36 | JSONParse, | |
| 29 | - Map, | ||
| 30 | 37 | ObjectCreate, | |
| 31 | 38 | ObjectDefineProperty, | |
| 32 | 39 | ObjectFreeze, | |
@@ -36,16 +43,20 @@ const { | |||
| 36 | 43 | ObjectPrototype, | |
| 37 | 44 | ObjectPrototypeHasOwnProperty, | |
| 38 | 45 | ObjectSetPrototypeOf, | |
| 46 | + ReflectApply, | ||
| 39 | 47 | ReflectSet, | |
| 40 | 48 | RegExpPrototypeTest, | |
| 41 | 49 | SafeMap, | |
| 42 | 50 | SafeWeakMap, | |
| 43 | 51 | String, | |
| 52 | + StringPrototypeCharAt, | ||
| 53 | + StringPrototypeCharCodeAt, | ||
| 44 | 54 | StringPrototypeEndsWith, | |
| 45 | 55 | StringPrototypeLastIndexOf, | |
| 46 | 56 | StringPrototypeIndexOf, | |
| 47 | 57 | StringPrototypeMatch, | |
| 48 | 58 | StringPrototypeSlice, | |
| 59 | + StringPrototypeSplit, | ||
| 49 | 60 | StringPrototypeStartsWith, | |
| 50 | 61 | } = primordials; | |
| 51 | 62 | ||
@@ -142,8 +153,8 @@ function stat(filename) { | |||
| 142 | 153 | ||
| 143 | 154 | function updateChildren(parent, child, scan) { | |
| 144 | 155 | const children = parent && parent.children; | |
| 145 | - if (children && !(scan && children.includes(child))) | ||
| 146 | - children.push(child); | ||
| 156 | + if (children && !(scan && ArrayPrototypeIncludes(children, child))) | ||
| 157 | + ArrayPrototypePush(children, child); | ||
| 147 | 158 | } | |
| 148 | 159 | ||
| 149 | 160 | const moduleParentCache = new SafeWeakMap(); | |
@@ -161,7 +172,7 @@ function Module(id = '', parent) { | |||
| 161 | 172 | const builtinModules = []; | |
| 162 | 173 | for (const [id, mod] of NativeModule.map) { | |
| 163 | 174 | if (mod.canBeRequiredByUsers) { | |
| 164 | - builtinModules.push(id); | ||
| 175 | + ArrayPrototypePush(builtinModules, id); | ||
| 165 | 176 | } | |
| 166 | 177 | } | |
| 167 | 178 | ||
@@ -349,7 +360,7 @@ function tryPackage(requestPath, exts, isMain, originalPath) { | |||
| 349 | 360 | // In order to minimize unnecessary lstat() calls, | |
| 350 | 361 | // this cache is a list of known-real paths. | |
| 351 | 362 | // Set to an empty Map to reset. | |
| 352 | - const realpathCache = new Map(); | ||
| 363 | + const realpathCache = new SafeMap(); | ||
| 353 | 364 | ||
| 354 | 365 | // Check if the file exists and is not a directory | |
| 355 | 366 | // if using --preserve-symlinks and isMain is false, | |
@@ -389,10 +400,10 @@ function findLongestRegisteredExtension(filename) { | |||
| 389 | 400 | let currentExtension; | |
| 390 | 401 | let index; | |
| 391 | 402 | let startIndex = 0; | |
| 392 | - while ((index = name.indexOf('.', startIndex)) !== -1) { | ||
| 403 | + while ((index = StringPrototypeIndexOf(name, '.', startIndex)) !== -1) { | ||
| 393 | 404 | startIndex = index + 1; | |
| 394 | 405 | if (index === 0) continue; // Skip dotfiles like .gitignore | |
| 395 | - currentExtension = name.slice(index); | ||
| 406 | + currentExtension = StringPrototypeSlice(name, index); | ||
| 396 | 407 | if (Module._extensions[currentExtension]) return currentExtension; | |
| 397 | 408 | } | |
| 398 | 409 | return '.js'; | |
@@ -473,15 +484,15 @@ Module._findPath = function(request, paths, isMain) { | |||
| 473 | 484 | return false; | |
| 474 | 485 | } | |
| 475 | 486 | ||
| 476 | - const cacheKey = request + '\x00' + | ||
| 477 | - (paths.length === 1 ? paths[0] : paths.join('\x00')); | ||
| 487 | + const cacheKey = request + '\x00' + ArrayPrototypeJoin(paths, '\x00'); | ||
| 478 | 488 | const entry = Module._pathCache[cacheKey]; | |
| 479 | 489 | if (entry) | |
| 480 | 490 | return entry; | |
| 481 | 491 | ||
| 482 | 492 | let exts; | |
| 483 | 493 | let trailingSlash = request.length > 0 && | |
| 484 | - request.charCodeAt(request.length - 1) === CHAR_FORWARD_SLASH; | ||
| 494 | + StringPrototypeCharCodeAt(request, request.length - 1) === | ||
| 495 | + CHAR_FORWARD_SLASH; | ||
| 485 | 496 | if (!trailingSlash) { | |
| 486 | 497 | trailingSlash = RegExpPrototypeTest(trailingSlashRegex, request); | |
| 487 | 498 | } | |
@@ -564,13 +575,14 @@ if (isWindows) { | |||
| 564 | 575 | ||
| 565 | 576 | // return root node_modules when path is 'D:\\'. | |
| 566 | 577 | // path.resolve will make sure from.length >=3 in Windows. | |
| 567 | - if (from.charCodeAt(from.length - 1) === CHAR_BACKWARD_SLASH && | ||
| 568 | - from.charCodeAt(from.length - 2) === CHAR_COLON) | ||
| 578 | + if (StringPrototypeCharCodeAt(from, from.length - 1) === | ||
| 579 | + CHAR_BACKWARD_SLASH && | ||
| 580 | + StringPrototypeCharCodeAt(from, from.length - 2) === CHAR_COLON) | ||
| 569 | 581 | return [from + 'node_modules']; | |
| 570 | 582 | ||
| 571 | 583 | const paths = []; | |
| 572 | 584 | for (let i = from.length - 1, p = 0, last = from.length; i >= 0; --i) { | |
| 573 | - const code = from.charCodeAt(i); | ||
| 585 | + const code = StringPrototypeCharCodeAt(from, i); | ||
| 574 | 586 | // The path segment separator check ('\' and '/') was used to get | |
| 575 | 587 | // node_modules path for every path segment. | |
| 576 | 588 | // Use colon as an extra condition since we can get node_modules | |
@@ -580,7 +592,10 @@ if (isWindows) { | |||
| 580 | 592 | code === CHAR_FORWARD_SLASH || | |
| 581 | 593 | code === CHAR_COLON) { | |
| 582 | 594 | if (p !== nmLen) | |
| 583 | - paths.push(from.slice(0, last) + '\\node_modules'); | ||
| 595 | + ArrayPrototypePush( | ||
| 596 | + paths, | ||
| 597 | + StringPrototypeSlice(from, 0, last) + '\\node_modules' | ||
| 598 | + ); | ||
| 584 | 599 | last = i; | |
| 585 | 600 | p = 0; | |
| 586 | 601 | } else if (p !== -1) { | |
@@ -609,10 +624,13 @@ if (isWindows) { | |||
| 609 | 624 | // that works on both Windows and Posix is non-trivial. | |
| 610 | 625 | const paths = []; | |
| 611 | 626 | for (let i = from.length - 1, p = 0, last = from.length; i >= 0; --i) { | |
| 612 | - const code = from.charCodeAt(i); | ||
| 627 | + const code = StringPrototypeCharCodeAt(from, i); | ||
| 613 | 628 | if (code === CHAR_FORWARD_SLASH) { | |
| 614 | 629 | if (p !== nmLen) | |
| 615 | - paths.push(from.slice(0, last) + '/node_modules'); | ||
| 630 | + ArrayPrototypePush( | ||
| 631 | + paths, | ||
| 632 | + StringPrototypeSlice(from, 0, last) + '/node_modules' | ||
| 633 | + ); | ||
| 616 | 634 | last = i; | |
| 617 | 635 | p = 0; | |
| 618 | 636 | } else if (p !== -1) { | |
@@ -625,7 +643,7 @@ if (isWindows) { | |||
| 625 | 643 | } | |
| 626 | 644 | ||
| 627 | 645 | // Append /node_modules to handle root paths. | |
| 628 | - paths.push('/node_modules'); | ||
| 646 | + ArrayPrototypePush(paths, '/node_modules'); | ||
| 629 | 647 | ||
| 630 | 648 | return paths; | |
| 631 | 649 | }; | |
@@ -638,15 +656,15 @@ Module._resolveLookupPaths = function(request, parent) { | |||
| 638 | 656 | } | |
| 639 | 657 | ||
| 640 | 658 | // Check for node modules paths. | |
| 641 | - if (request.charAt(0) !== '.' || | ||
| 659 | + if (StringPrototypeCharAt(request, 0) !== '.' || | ||
| 642 | 660 | (request.length > 1 && | |
| 643 | - request.charAt(1) !== '.' && | ||
| 644 | - request.charAt(1) !== '/' && | ||
| 645 | - (!isWindows || request.charAt(1) !== '\\'))) { | ||
| 661 | + StringPrototypeCharAt(request, 1) !== '.' && | ||
| 662 | + StringPrototypeCharAt(request, 1) !== '/' && | ||
| 663 | + (!isWindows || StringPrototypeCharAt(request, 1) !== '\\'))) { | ||
| 646 | 664 | ||
| 647 | 665 | let paths = modulePaths; | |
| 648 | 666 | if (parent != null && parent.paths && parent.paths.length) { | |
| 649 | - paths = parent.paths.concat(paths); | ||
| 667 | + paths = ArrayPrototypeConcat(parent.paths, paths); | ||
| 650 | 668 | } | |
| 651 | 669 | ||
| 652 | 670 | debug('looking for %j in %j', request, paths); | |
@@ -796,9 +814,9 @@ Module._load = function(request, parent, isMain) { | |||
| 796 | 814 | delete relativeResolveCache[relResolveCacheIdentifier]; | |
| 797 | 815 | const children = parent && parent.children; | |
| 798 | 816 | if (ArrayIsArray(children)) { | |
| 799 | - const index = children.indexOf(module); | ||
| 817 | + const index = ArrayPrototypeIndexOf(children, module); | ||
| 800 | 818 | if (index !== -1) { | |
| 801 | - children.splice(index, 1); | ||
| 819 | + ArrayPrototypeSplice(children, index, 1); | ||
| 802 | 820 | } | |
| 803 | 821 | } | |
| 804 | 822 | } | |
@@ -822,10 +840,10 @@ Module._resolveFilename = function(request, parent, isMain, options) { | |||
| 822 | 840 | ||
| 823 | 841 | if (typeof options === 'object' && options !== null) { | |
| 824 | 842 | if (ArrayIsArray(options.paths)) { | |
| 825 | - const isRelative = request.startsWith('./') || | ||
| 826 | - request.startsWith('../') || | ||
| 827 | - ((isWindows && request.startsWith('.\\')) || | ||
| 828 | - request.startsWith('..\\')); | ||
| 843 | + const isRelative = StringPrototypeStartsWith(request, './') || | ||
| 844 | + StringPrototypeStartsWith(request, '../') || | ||
| 845 | + ((isWindows && StringPrototypeStartsWith(request, '.\\')) || | ||
| 846 | + StringPrototypeStartsWith(request, '..\\')); | ||
| 829 | 847 | ||
| 830 | 848 | if (isRelative) { | |
| 831 | 849 | paths = options.paths; | |
@@ -840,8 +858,8 @@ Module._resolveFilename = function(request, parent, isMain, options) { | |||
| 840 | 858 | const lookupPaths = Module._resolveLookupPaths(request, fakeParent); | |
| 841 | 859 | ||
| 842 | 860 | for (let j = 0; j < lookupPaths.length; j++) { | |
| 843 | - if (!paths.includes(lookupPaths[j])) | ||
| 844 | - paths.push(lookupPaths[j]); | ||
| 861 | + if (!ArrayPrototypeIncludes(paths, lookupPaths[j])) | ||
| 862 | + ArrayPrototypePush(paths, lookupPaths[j]); | ||
| 845 | 863 | } | |
| 846 | 864 | } | |
| 847 | 865 | } | |
@@ -890,11 +908,12 @@ Module._resolveFilename = function(request, parent, isMain, options) { | |||
| 890 | 908 | for (let cursor = parent; | |
| 891 | 909 | cursor; | |
| 892 | 910 | cursor = moduleParentCache.get(cursor)) { | |
| 893 | - requireStack.push(cursor.filename || cursor.id); | ||
| 911 | + ArrayPrototypePush(requireStack, cursor.filename || cursor.id); | ||
| 894 | 912 | } | |
| 895 | 913 | let message = `Cannot find module '${request}'`; | |
| 896 | 914 | if (requireStack.length > 0) { | |
| 897 | - message = message + '\nRequire stack:\n- ' + requireStack.join('\n- '); | ||
| 915 | + message = message + '\nRequire stack:\n- ' + | ||
| 916 | + ArrayPrototypeJoin(requireStack, '\n- '); | ||
| 898 | 917 | } | |
| 899 | 918 | // eslint-disable-next-line no-restricted-syntax | |
| 900 | 919 | const err = new Error(message); | |
@@ -905,7 +924,7 @@ Module._resolveFilename = function(request, parent, isMain, options) { | |||
| 905 | 924 | ||
| 906 | 925 | function finalizeEsmResolution(match, request, parentPath, pkgPath) { | |
| 907 | 926 | const { resolved, exact } = match; | |
| 908 | - if (StringPrototypeMatch(resolved, encodedSepRegEx)) | ||
| 927 | + if (RegExpPrototypeTest(encodedSepRegEx, resolved)) | ||
| 909 | 928 | throw new ERR_INVALID_MODULE_SPECIFIER( | |
| 910 | 929 | resolved, 'must not include encoded "/" or "\\" characters', parentPath); | |
| 911 | 930 | const filename = fileURLToPath(resolved); | |
@@ -942,9 +961,9 @@ Module.prototype.load = function(filename) { | |||
| 942 | 961 | ||
| 943 | 962 | const extension = findLongestRegisteredExtension(filename); | |
| 944 | 963 | // allow .mjs to be overridden | |
| 945 | - if (filename.endsWith('.mjs') && !Module._extensions['.mjs']) { | ||
| 964 | + if (StringPrototypeEndsWith(filename, '.mjs') && !Module._extensions['.mjs']) | ||
| 946 | 965 | throw new ERR_REQUIRE_ESM(filename); | |
| 947 | - } | ||
| 966 | + | ||
| 948 | 967 | Module._extensions[extension](this, filename); | |
| 949 | 968 | this.loaded = true; | |
| 950 | 969 | ||
@@ -1075,13 +1094,13 @@ Module.prototype._compile = function(content, filename) { | |||
| 1075 | 1094 | const exports = this.exports; | |
| 1076 | 1095 | const thisValue = exports; | |
| 1077 | 1096 | const module = this; | |
| 1078 | - if (requireDepth === 0) statCache = new Map(); | ||
| 1097 | + if (requireDepth === 0) statCache = new SafeMap(); | ||
| 1079 | 1098 | if (inspectorWrapper) { | |
| 1080 | 1099 | result = inspectorWrapper(compiledWrapper, thisValue, exports, | |
| 1081 | 1100 | require, module, filename, dirname); | |
| 1082 | 1101 | } else { | |
| 1083 | - result = compiledWrapper.call(thisValue, exports, require, module, | ||
| 1084 | - filename, dirname); | ||
| 1102 | + result = ReflectApply(compiledWrapper, thisValue, | ||
| 1103 | + [exports, require, module, filename, dirname]); | ||
| 1085 | 1104 | } | |
| 1086 | 1105 | hasLoadedAnyUserCJSModule = true; | |
| 1087 | 1106 | if (requireDepth === 0) statCache = null; | |
@@ -1090,7 +1109,7 @@ Module.prototype._compile = function(content, filename) { | |||
| 1090 | 1109 | ||
| 1091 | 1110 | // Native extension for .js | |
| 1092 | 1111 | Module._extensions['.js'] = function(module, filename) { | |
| 1093 | - if (filename.endsWith('.js')) { | ||
| 1112 | + if (StringPrototypeEndsWith(filename, '.js')) { | ||
| 1094 | 1113 | const pkg = readPackageScope(filename); | |
| 1095 | 1114 | // Function require shouldn't be used in ES modules. | |
| 1096 | 1115 | if (pkg && pkg.data && pkg.data.type === 'module') { | |
@@ -1145,7 +1164,8 @@ Module._extensions['.node'] = function(module, filename) { | |||
| 1145 | 1164 | function createRequireFromPath(filename) { | |
| 1146 | 1165 | // Allow a directory to be passed as the filename | |
| 1147 | 1166 | const trailingSlash = | |
| 1148 | - filename.endsWith('/') || (isWindows && filename.endsWith('\\')); | ||
| 1167 | + StringPrototypeEndsWith(filename, '/') || | ||
| 1168 | + (isWindows && StringPrototypeEndsWith(filename, '\\')); | ||
| 1149 | 1169 | ||
| 1150 | 1170 | const proxyPath = trailingSlash ? | |
| 1151 | 1171 | path.join(filename, 'noop.js') : | |
@@ -1207,15 +1227,16 @@ Module._initPaths = function() { | |||
| 1207 | 1227 | } | |
| 1208 | 1228 | ||
| 1209 | 1229 | if (nodePath) { | |
| 1210 | - paths = nodePath.split(path.delimiter).filter(function pathsFilterCB(path) { | ||
| 1211 | - return !!path; | ||
| 1212 | - }).concat(paths); | ||
| 1230 | + paths = ArrayPrototypeConcat(ArrayPrototypeFilter( | ||
| 1231 | + StringPrototypeSplit(nodePath, path.delimiter), | ||
| 1232 | + Boolean | ||
| 1233 | + ), paths); | ||
| 1213 | 1234 | } | |
| 1214 | 1235 | ||
| 1215 | 1236 | modulePaths = paths; | |
| 1216 | 1237 | ||
| 1217 | 1238 | // Clone as a shallow copy, for introspection. | |
| 1218 | - Module.globalPaths = modulePaths.slice(0); | ||
| 1239 | + Module.globalPaths = ArrayPrototypeSlice(modulePaths); | ||
| 1219 | 1240 | }; | |
| 1220 | 1241 | ||
| 1221 | 1242 | Module._preloadModules = function(requests) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,9 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + const { | ||
| 4 | + PromisePrototypeFinally, | ||
| 5 | + StringPrototypeEndsWith, | ||
| 6 | + } = primordials; | ||
| 3 | 7 | const CJSLoader = require('internal/modules/cjs/loader'); | |
| 4 | 8 | const { Module, toRealPath, readPackageScope } = CJSLoader; | |
| 5 | 9 | const { getOptionValue } = require('internal/options'); | |
@@ -29,9 +33,9 @@ function shouldUseESMLoader(mainPath) { | |||
| 29 | 33 | if (esModuleSpecifierResolution === 'node') | |
| 30 | 34 | return true; | |
| 31 | 35 | // Determine the module format of the main | |
| 32 | - if (mainPath && mainPath.endsWith('.mjs')) | ||
| 36 | + if (mainPath && StringPrototypeEndsWith(mainPath, '.mjs')) | ||
| 33 | 37 | return true; | |
| 34 | - if (!mainPath || mainPath.endsWith('.cjs')) | ||
| 38 | + if (!mainPath || StringPrototypeEndsWith(mainPath, '.cjs')) | ||
| 35 | 39 | return false; | |
| 36 | 40 | const pkg = readPackageScope(mainPath); | |
| 37 | 41 | return pkg && pkg.data.type === 'module'; | |
@@ -56,7 +60,7 @@ function handleMainPromise(promise) { | |||
| 56 | 60 | process.exitCode = 13; | |
| 57 | 61 | } | |
| 58 | 62 | process.on('exit', handler); | |
| 59 | - return promise.finally(() => process.off('exit', handler)); | ||
| 63 | + return PromisePrototypeFinally(promise, () => process.off('exit', handler)); | ||
| 60 | 64 | } | |
| 61 | 65 | ||
| 62 | 66 | // For backwards compatibility, we have to run a bunch of | |
| Back | FazBrowse Home | New Git URL |
0 commit comments