| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,31 +11,49 @@ | |||
| 11 | 11 | // message may change, the code should not. | |
| 12 | 12 | ||
| 13 | 13 | const { | |
| 14 | + ArrayFrom, | ||
| 14 | 15 | ArrayIsArray, | |
| 16 | + ArrayPrototypeIncludes, | ||
| 17 | + ArrayPrototypeIndexOf, | ||
| 18 | + ArrayPrototypeJoin, | ||
| 19 | + ArrayPrototypeMap, | ||
| 20 | + ArrayPrototypePop, | ||
| 21 | + ArrayPrototypePush, | ||
| 22 | + ArrayPrototypeSlice, | ||
| 23 | + ArrayPrototypeSplice, | ||
| 24 | + ArrayPrototypeUnshift, | ||
| 15 | 25 | Error, | |
| 16 | 26 | ErrorCaptureStackTrace, | |
| 17 | 27 | ErrorPrototypeToString, | |
| 18 | 28 | JSONStringify, | |
| 19 | - Map, | ||
| 20 | 29 | MathAbs, | |
| 21 | 30 | MathMax, | |
| 31 | + Number, | ||
| 22 | 32 | NumberIsInteger, | |
| 23 | 33 | ObjectDefineProperty, | |
| 24 | 34 | ObjectKeys, | |
| 25 | 35 | RangeError, | |
| 36 | + ReflectApply, | ||
| 37 | + RegExpPrototypeTest, | ||
| 38 | + SafeMap, | ||
| 39 | + SafeWeakMap, | ||
| 26 | 40 | String, | |
| 41 | + StringPrototypeEndsWith, | ||
| 42 | + StringPrototypeIncludes, | ||
| 43 | + StringPrototypeSlice, | ||
| 44 | + StringPrototypeSplit, | ||
| 27 | 45 | StringPrototypeStartsWith, | |
| 46 | + StringPrototypeToLowerCase, | ||
| 28 | 47 | Symbol, | |
| 29 | 48 | SymbolFor, | |
| 30 | 49 | SyntaxError, | |
| 31 | 50 | TypeError, | |
| 32 | 51 | URIError, | |
| 33 | - WeakMap, | ||
| 34 | 52 | } = primordials; | |
| 35 | 53 | ||
| 36 | 54 | const isWindows = process.platform === 'win32'; | |
| 37 | 55 | ||
| 38 | - const messages = new Map(); | ||
| 56 | + const messages = new SafeMap(); | ||
| 39 | 57 | const codes = {}; | |
| 40 | 58 | ||
| 41 | 59 | const classRegExp = /^([A-Z][a-z0-9]*)+$/; | |
@@ -54,7 +72,7 @@ const kTypes = [ | |||
| 54 | 72 | ]; | |
| 55 | 73 | ||
| 56 | 74 | const MainContextError = Error; | |
| 57 | - const overrideStackTrace = new WeakMap(); | ||
| 75 | + const overrideStackTrace = new SafeWeakMap(); | ||
| 58 | 76 | const kNoOverride = Symbol('kNoOverride'); | |
| 59 | 77 | const prepareStackTrace = (globalThis, error, trace) => { | |
| 60 | 78 | // API for node internals to override error stack formatting | |
@@ -366,8 +384,8 @@ function getMessage(key, args, self) { | |||
| 366 | 384 | if (args.length === 0) | |
| 367 | 385 | return msg; | |
| 368 | 386 | ||
| 369 | - args.unshift(msg); | ||
| 370 | - return lazyInternalUtilInspect().format.apply(null, args); | ||
| 387 | + ArrayPrototypeUnshift(args, msg); | ||
| 388 | + return ReflectApply(lazyInternalUtilInspect().format, null, args); | ||
| 371 | 389 | } | |
| 372 | 390 | ||
| 373 | 391 | let uvBinding; | |
@@ -640,9 +658,9 @@ function addNumericalSeparator(val) { | |||
| 640 | 658 | let i = val.length; | |
| 641 | 659 | const start = val[0] === '-' ? 1 : 0; | |
| 642 | 660 | for (; i >= start + 4; i -= 3) { | |
| 643 | - res = `_${val.slice(i - 3, i)}${res}`; | ||
| 661 | + res = `_${StringPrototypeSlice(val, i - 3, i)}${res}`; | ||
| 644 | 662 | } | |
| 645 | - return `${val.slice(0, i)}${res}`; | ||
| 663 | + return `${StringPrototypeSlice(val, 0, i)}${res}`; | ||
| 646 | 664 | } | |
| 647 | 665 | ||
| 648 | 666 | // Used to enhance the stack that will be picked up by the inspector | |
@@ -677,7 +695,8 @@ const fatalExceptionStackEnhancers = { | |||
| 677 | 695 | // ANSI escape sequences is not reliable. | |
| 678 | 696 | if (process.platform === 'win32') { | |
| 679 | 697 | const info = internalBinding('os').getOSInformation(); | |
| 680 | - const ver = info[2].split('.').map((a) => +a); | ||
| 698 | + const ver = ArrayPrototypeMap(StringPrototypeSplit(info[2], '.'), | ||
| 699 | + Number); | ||
| 681 | 700 | if (ver[0] !== 10 || ver[2] < 14393) { | |
| 682 | 701 | useColors = false; | |
| 683 | 702 | } | |
@@ -981,11 +1000,11 @@ E('ERR_INVALID_ARG_TYPE', | |||
| 981 | 1000 | } | |
| 982 | 1001 | ||
| 983 | 1002 | let msg = 'The '; | |
| 984 | - if (name.endsWith(' argument')) { | ||
| 1003 | + if (StringPrototypeEndsWith(name, ' argument')) { | ||
| 985 | 1004 | // For cases like 'first argument' | |
| 986 | 1005 | msg += `${name} `; | |
| 987 | 1006 | } else { | |
| 988 | - const type = name.includes('.') ? 'property' : 'argument'; | ||
| 1007 | + const type = StringPrototypeIncludes(name, '.') ? 'property' : 'argument'; | ||
| 989 | 1008 | msg += `"${name}" ${type} `; | |
| 990 | 1009 | } | |
| 991 | 1010 | msg += 'must be '; | |
@@ -997,31 +1016,31 @@ E('ERR_INVALID_ARG_TYPE', | |||
| 997 | 1016 | for (const value of expected) { | |
| 998 | 1017 | assert(typeof value === 'string', | |
| 999 | 1018 | 'All expected entries have to be of type string'); | |
| 1000 | - if (kTypes.includes(value)) { | ||
| 1001 | - types.push(value.toLowerCase()); | ||
| 1002 | - } else if (classRegExp.test(value)) { | ||
| 1003 | - instances.push(value); | ||
| 1019 | + if (ArrayPrototypeIncludes(kTypes, value)) { | ||
| 1020 | + ArrayPrototypePush(types, StringPrototypeToLowerCase(value)); | ||
| 1021 | + } else if (RegExpPrototypeTest(classRegExp, value)) { | ||
| 1022 | + ArrayPrototypePush(instances, value); | ||
| 1004 | 1023 | } else { | |
| 1005 | 1024 | assert(value !== 'object', | |
| 1006 | 1025 | 'The value "object" should be written as "Object"'); | |
| 1007 | - other.push(value); | ||
| 1026 | + ArrayPrototypePush(other, value); | ||
| 1008 | 1027 | } | |
| 1009 | 1028 | } | |
| 1010 | 1029 | ||
| 1011 | 1030 | // Special handle `object` in case other instances are allowed to outline | |
| 1012 | 1031 | // the differences between each other. | |
| 1013 | 1032 | if (instances.length > 0) { | |
| 1014 | - const pos = types.indexOf('object'); | ||
| 1033 | + const pos = ArrayPrototypeIndexOf(types, 'object'); | ||
| 1015 | 1034 | if (pos !== -1) { | |
| 1016 | - types.splice(pos, 1); | ||
| 1017 | - instances.push('Object'); | ||
| 1035 | + ArrayPrototypeSplice(types, pos, 1); | ||
| 1036 | + ArrayPrototypePush(instances, 'Object'); | ||
| 1018 | 1037 | } | |
| 1019 | 1038 | } | |
| 1020 | 1039 | ||
| 1021 | 1040 | if (types.length > 0) { | |
| 1022 | 1041 | if (types.length > 2) { | |
| 1023 | - const last = types.pop(); | ||
| 1024 | - msg += `one of type ${types.join(', ')}, or ${last}`; | ||
| 1042 | + const last = ArrayPrototypePop(types); | ||
| 1043 | + msg += `one of type ${ArrayPrototypeJoin(types, ', ')}, or ${last}`; | ||
| 1025 | 1044 | } else if (types.length === 2) { | |
| 1026 | 1045 | msg += `one of type ${types[0]} or ${types[1]}`; | |
| 1027 | 1046 | } else { | |
@@ -1033,8 +1052,9 @@ E('ERR_INVALID_ARG_TYPE', | |||
| 1033 | 1052 | ||
| 1034 | 1053 | if (instances.length > 0) { | |
| 1035 | 1054 | if (instances.length > 2) { | |
| 1036 | - const last = instances.pop(); | ||
| 1037 | - msg += `an instance of ${instances.join(', ')}, or ${last}`; | ||
| 1055 | + const last = ArrayPrototypePop(instances); | ||
| 1056 | + msg += | ||
| 1057 | + `an instance of ${ArrayPrototypeJoin(instances, ', ')}, or ${last}`; | ||
| 1038 | 1058 | } else { | |
| 1039 | 1059 | msg += `an instance of ${instances[0]}`; | |
| 1040 | 1060 | if (instances.length === 2) { | |
@@ -1047,12 +1067,12 @@ E('ERR_INVALID_ARG_TYPE', | |||
| 1047 | 1067 | ||
| 1048 | 1068 | if (other.length > 0) { | |
| 1049 | 1069 | if (other.length > 2) { | |
| 1050 | - const last = other.pop(); | ||
| 1051 | - msg += `one of ${other.join(', ')}, or ${last}`; | ||
| 1070 | + const last = ArrayPrototypePop(other); | ||
| 1071 | + msg += `one of ${ArrayPrototypeJoin(other, ', ')}, or ${last}`; | ||
| 1052 | 1072 | } else if (other.length === 2) { | |
| 1053 | 1073 | msg += `one of ${other[0]} or ${other[1]}`; | |
| 1054 | 1074 | } else { | |
| 1055 | - if (other[0].toLowerCase() !== other[0]) | ||
| 1075 | + if (StringPrototypeToLowerCase(other[0]) !== other[0]) | ||
| 1056 | 1076 | msg += 'an '; | |
| 1057 | 1077 | msg += `${other[0]}`; | |
| 1058 | 1078 | } | |
@@ -1074,15 +1094,15 @@ E('ERR_INVALID_ARG_TYPE', | |||
| 1074 | 1094 | let inspected = lazyInternalUtilInspect() | |
| 1075 | 1095 | .inspect(actual, { colors: false }); | |
| 1076 | 1096 | if (inspected.length > 25) | |
| 1077 | - inspected = `${inspected.slice(0, 25)}...`; | ||
| 1097 | + inspected = `${StringPrototypeSlice(inspected, 0, 25)}...`; | ||
| 1078 | 1098 | msg += `. Received type ${typeof actual} (${inspected})`; | |
| 1079 | 1099 | } | |
| 1080 | 1100 | return msg; | |
| 1081 | 1101 | }, TypeError); | |
| 1082 | 1102 | E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { | |
| 1083 | 1103 | let inspected = lazyInternalUtilInspect().inspect(value); | |
| 1084 | 1104 | if (inspected.length > 128) { | |
| 1085 | - inspected = `${inspected.slice(0, 128)}...`; | ||
| 1105 | + inspected = `${StringPrototypeSlice(inspected, 0, 128)}...`; | ||
| 1086 | 1106 | } | |
| 1087 | 1107 | return `The argument '${name}' ${reason}. Received ${inspected}`; | |
| 1088 | 1108 | }, TypeError, RangeError); | |
@@ -1208,9 +1228,10 @@ E('ERR_MANIFEST_ASSERT_INTEGRITY', | |||
| 1208 | 1228 | moduleURL | |
| 1209 | 1229 | }" does not match the expected integrity.`; | |
| 1210 | 1230 | if (realIntegrities.size) { | |
| 1211 | - const sri = [...realIntegrities.entries()].map(([alg, dgs]) => { | ||
| 1212 | - return `${alg}-${dgs}`; | ||
| 1213 | - }).join(' '); | ||
| 1231 | + const sri = ArrayPrototypeJoin( | ||
| 1232 | + ArrayFrom(realIntegrities.entries(), ([alg, dgs]) => `${alg}-${dgs}`), | ||
| 1233 | + ' ' | ||
| 1234 | + ); | ||
| 1214 | 1235 | msg += ` Integrities found are: ${sri}`; | |
| 1215 | 1236 | } else { | |
| 1216 | 1237 | msg += ' The resource was not found in the policy.'; | |
@@ -1237,7 +1258,13 @@ E('ERR_MISSING_ARGS', | |||
| 1237 | 1258 | assert(args.length > 0, 'At least one arg needs to be specified'); | |
| 1238 | 1259 | let msg = 'The '; | |
| 1239 | 1260 | const len = args.length; | |
| 1240 | - args = args.map((a) => `"${a}"`); | ||
| 1261 | + const wrap = (a) => `"${a}"`; | ||
| 1262 | + args = ArrayPrototypeMap( | ||
| 1263 | + args, | ||
| 1264 | + (a) => (ArrayIsArray(a) ? | ||
| 1265 | + ArrayPrototypeJoin(ArrayPrototypeMap(a, wrap), ' or ') : | ||
| 1266 | + wrap(a)) | ||
| 1267 | + ); | ||
| 1241 | 1268 | switch (len) { | |
| 1242 | 1269 | case 1: | |
| 1243 | 1270 | msg += `${args[0]} argument`; | |
@@ -1246,7 +1273,7 @@ E('ERR_MISSING_ARGS', | |||
| 1246 | 1273 | msg += `${args[0]} and ${args[1]} arguments`; | |
| 1247 | 1274 | break; | |
| 1248 | 1275 | default: | |
| 1249 | - msg += args.slice(0, len - 1).join(', '); | ||
| 1276 | + msg += ArrayPrototypeJoin(ArrayPrototypeSlice(args, 0, len - 1), ', '); | ||
| 1250 | 1277 | msg += `, and ${args[len - 1]} arguments`; | |
| 1251 | 1278 | break; | |
| 1252 | 1279 | } | |
@@ -1449,18 +1476,18 @@ E('ERR_VM_MODULE_STATUS', 'Module status %s', Error); | |||
| 1449 | 1476 | E('ERR_WASI_ALREADY_STARTED', 'WASI instance has already started', Error); | |
| 1450 | 1477 | E('ERR_WORKER_INIT_FAILED', 'Worker initialization failure: %s', Error); | |
| 1451 | 1478 | E('ERR_WORKER_INVALID_EXEC_ARGV', (errors, msg = 'invalid execArgv flags') => | |
| 1452 | - `Initiated Worker with ${msg}: ${errors.join(', ')}`, | ||
| 1479 | + `Initiated Worker with ${msg}: ${ArrayPrototypeJoin(errors, ', ')}`, | ||
| 1453 | 1480 | Error); | |
| 1454 | 1481 | E('ERR_WORKER_NOT_RUNNING', 'Worker instance not running', Error); | |
| 1455 | 1482 | E('ERR_WORKER_OUT_OF_MEMORY', | |
| 1456 | 1483 | 'Worker terminated due to reaching memory limit: %s', Error); | |
| 1457 | 1484 | E('ERR_WORKER_PATH', (filename) => | |
| 1458 | 1485 | 'The worker script or module filename must be an absolute path or a ' + | |
| 1459 | 1486 | 'relative path starting with \'./\' or \'../\'.' + | |
| 1460 | - (filename.startsWith('file://') ? | ||
| 1487 | + (StringPrototypeStartsWith(filename, 'file://') ? | ||
| 1461 | 1488 | ' Wrap file:// URLs with `new URL`.' : '' | |
| 1462 | 1489 | ) + | |
| 1463 | - (filename.startsWith('data:text/javascript') ? | ||
| 1490 | + (StringPrototypeStartsWith(filename, 'data:text/javascript') ? | ||
| 1464 | 1491 | ' Wrap data: URLs with `new URL`.' : '' | |
| 1465 | 1492 | ) + | |
| 1466 | 1493 | ` Received "${filename}"`, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | ArrayPrototypeIndexOf, | |
| 5 | - Error, | ||
| 5 | + ArrayPrototypeJoin, | ||
| 6 | + ArrayPrototypeMap, | ||
| 7 | + ErrorPrototypeToString, | ||
| 8 | + StringPrototypeRepeat, | ||
| 9 | + StringPrototypeSlice, | ||
| 10 | + StringPrototypeSplit, | ||
| 6 | 11 | StringPrototypeStartsWith, | |
| 7 | 12 | } = primordials; | |
| 8 | 13 | ||
@@ -21,7 +26,6 @@ const { fileURLToPath } = require('internal/url'); | |||
| 21 | 26 | ||
| 22 | 27 | // Create a prettified stacktrace, inserting context from source maps | |
| 23 | 28 | // if possible. | |
| 24 | - const ErrorToString = Error.prototype.toString; // Capture original toString. | ||
| 25 | 29 | const prepareStackTrace = (globalThis, error, trace) => { | |
| 26 | 30 | // API for node internals to override error stack formatting | |
| 27 | 31 | // without interfering with userland code. | |
@@ -36,7 +40,7 @@ const prepareStackTrace = (globalThis, error, trace) => { | |||
| 36 | 40 | maybeOverridePrepareStackTrace(globalThis, error, trace); | |
| 37 | 41 | if (globalOverride !== kNoOverride) return globalOverride; | |
| 38 | 42 | ||
| 39 | - const errorString = ErrorToString.call(error); | ||
| 43 | + const errorString = ErrorPrototypeToString(error); | ||
| 40 | 44 | ||
| 41 | 45 | if (trace.length === 0) { | |
| 42 | 46 | return errorString; | |
@@ -45,7 +49,7 @@ const prepareStackTrace = (globalThis, error, trace) => { | |||
| 45 | 49 | let errorSource = ''; | |
| 46 | 50 | let firstLine; | |
| 47 | 51 | let firstColumn; | |
| 48 | - const preparedTrace = trace.map((t, i) => { | ||
| 52 | + const preparedTrace = ArrayPrototypeJoin(ArrayPrototypeMap(trace, (t, i) => { | ||
| 49 | 53 | if (i === 0) { | |
| 50 | 54 | firstLine = t.getLineNumber(); | |
| 51 | 55 | firstColumn = t.getColumnNumber(); | |
@@ -88,8 +92,8 @@ const prepareStackTrace = (globalThis, error, trace) => { | |||
| 88 | 92 | debug(err.stack); | |
| 89 | 93 | } | |
| 90 | 94 | return str; | |
| 91 | - }); | ||
| 92 | - return `${errorSource}${errorString}\n at ${preparedTrace.join('')}`; | ||
| 95 | + }), ''); | ||
| 96 | + return `${errorSource}${errorString}\n at ${preparedTrace}`; | ||
| 93 | 97 | }; | |
| 94 | 98 | ||
| 95 | 99 | // Places a snippet of code from where the exception was originally thrown | |
@@ -118,18 +122,18 @@ function getErrorSource(payload, originalSource, firstLine, firstColumn) { | |||
| 118 | 122 | } | |
| 119 | 123 | } | |
| 120 | 124 | ||
| 121 | - const lines = source.split(/\r?\n/, firstLine); | ||
| 125 | + const lines = StringPrototypeSplit(source, /\r?\n/, firstLine); | ||
| 122 | 126 | const line = lines[firstLine - 1]; | |
| 123 | 127 | if (!line) return exceptionLine; | |
| 124 | 128 | ||
| 125 | 129 | // Display ^ in appropriate position, regardless of whether tabs or | |
| 126 | 130 | // spaces are used: | |
| 127 | 131 | let prefix = ''; | |
| 128 | - for (const character of line.slice(0, firstColumn)) { | ||
| 132 | + for (const character of StringPrototypeSlice(line, 0, firstColumn)) { | ||
| 129 | 133 | prefix += (character === '\t') ? '\t' : | |
| 130 | - ' '.repeat(getStringWidth(character)); | ||
| 134 | + StringPrototypeRepeat(' ', getStringWidth(character)); | ||
| 131 | 135 | } | |
| 132 | - prefix = prefix.slice(0, -1); // The last character is the '^'. | ||
| 136 | + prefix = StringPrototypeSlice(prefix, 0, -1); // The last character is '^'. | ||
| 133 | 137 | ||
| 134 | 138 | exceptionLine = | |
| 135 | 139 | `${originalSourceNoScheme}:${firstLine}\n${line}\n${prefix}^\n\n`; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments