| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | 4 | Array, | |
| 5 | + ArrayPrototypeJoin, | ||
| 6 | + ArrayPrototypeMap, | ||
| 7 | + ArrayPrototypePush, | ||
| 8 | + ArrayPrototypeReduce, | ||
| 9 | + ArrayPrototypeSlice, | ||
| 10 | + FunctionPrototypeBind, | ||
| 5 | 11 | Int8Array, | |
| 6 | 12 | Number, | |
| 7 | 13 | ObjectCreate, | |
@@ -10,9 +16,17 @@ const { | |||
| 10 | 16 | ObjectGetOwnPropertySymbols, | |
| 11 | 17 | ObjectGetPrototypeOf, | |
| 12 | 18 | ObjectKeys, | |
| 19 | + ReflectApply, | ||
| 13 | 20 | ReflectGetOwnPropertyDescriptor, | |
| 14 | 21 | ReflectOwnKeys, | |
| 22 | + RegExpPrototypeExec, | ||
| 15 | 23 | String, | |
| 24 | + StringPrototypeCharCodeAt, | ||
| 25 | + StringPrototypeIncludes, | ||
| 26 | + StringPrototypeReplace, | ||
| 27 | + StringPrototypeSlice, | ||
| 28 | + StringPrototypeSplit, | ||
| 29 | + StringPrototypeStartsWith, | ||
| 16 | 30 | Symbol, | |
| 17 | 31 | SymbolIterator, | |
| 18 | 32 | SymbolToStringTag, | |
@@ -101,7 +115,7 @@ function toUSVString(val) { | |||
| 101 | 115 | const str = `${val}`; | |
| 102 | 116 | // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are | |
| 103 | 117 | // slower than `unpairedSurrogateRe.exec()`. | |
| 104 | - const match = unpairedSurrogateRe.exec(str); | ||
| 118 | + const match = RegExpPrototypeExec(unpairedSurrogateRe, str); | ||
| 105 | 119 | if (!match) | |
| 106 | 120 | return str; | |
| 107 | 121 | return _toUSVString(str, match.index); | |
@@ -166,16 +180,16 @@ class URLSearchParams { | |||
| 166 | 180 | } | |
| 167 | 181 | const convertedPair = []; | |
| 168 | 182 | for (const element of pair) | |
| 169 | - convertedPair.push(toUSVString(element)); | ||
| 170 | - pairs.push(convertedPair); | ||
| 183 | + ArrayPrototypePush(convertedPair, toUSVString(element)); | ||
| 184 | + ArrayPrototypePush(pairs, convertedPair); | ||
| 171 | 185 | } | |
| 172 | 186 | ||
| 173 | 187 | this[searchParams] = []; | |
| 174 | 188 | for (const pair of pairs) { | |
| 175 | 189 | if (pair.length !== 2) { | |
| 176 | 190 | throw new ERR_INVALID_TUPLE('Each query pair', '[name, value]'); | |
| 177 | 191 | } | |
| 178 | - this[searchParams].push(pair[0], pair[1]); | ||
| 192 | + ArrayPrototypePush(this[searchParams], pair[0], pair[1]); | ||
| 179 | 193 | } | |
| 180 | 194 | } else { | |
| 181 | 195 | // Record<USVString, USVString> | |
@@ -221,16 +235,21 @@ class URLSearchParams { | |||
| 221 | 235 | const list = this[searchParams]; | |
| 222 | 236 | const output = []; | |
| 223 | 237 | for (let i = 0; i < list.length; i += 2) | |
| 224 | - output.push(`${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`); | ||
| 238 | + ArrayPrototypePush( | ||
| 239 | + output, | ||
| 240 | + `${innerInspect(list[i])} => ${innerInspect(list[i + 1])}`); | ||
| 225 | 241 | ||
| 226 | - const length = output.reduce( | ||
| 242 | + const length = ArrayPrototypeReduce( | ||
| 243 | + output, | ||
| 227 | 244 | (prev, cur) => prev + removeColors(cur).length + separator.length, | |
| 228 | 245 | -separator.length | |
| 229 | 246 | ); | |
| 230 | 247 | if (length > ctx.breakLength) { | |
| 231 | - return `${this.constructor.name} {\n ${output.join(',\n ')} }`; | ||
| 248 | + return `${this.constructor.name} {\n` + | ||
| 249 | + ` ${ArrayPrototypeJoin(output, ',\n ')} }`; | ||
| 232 | 250 | } else if (output.length) { | |
| 233 | - return `${this.constructor.name} { ${output.join(separator)} }`; | ||
| 251 | + return `${this.constructor.name} { ` + | ||
| 252 | + `${ArrayPrototypeJoin(output, separator)} }`; | ||
| 234 | 253 | } | |
| 235 | 254 | return `${this.constructor.name} {}`; | |
| 236 | 255 | } | |
@@ -290,9 +309,9 @@ function onParsePortComplete(flags, protocol, username, password, | |||
| 290 | 309 | ||
| 291 | 310 | function onParseHostComplete(flags, protocol, username, password, | |
| 292 | 311 | host, port, path, query, fragment) { | |
| 293 | - onParseHostnameComplete.apply(this, arguments); | ||
| 312 | + ReflectApply(onParseHostnameComplete, this, arguments); | ||
| 294 | 313 | if (port !== null || ((flags & URL_FLAGS_IS_DEFAULT_SCHEME_PORT) !== 0)) | |
| 295 | - onParsePortComplete.apply(this, arguments); | ||
| 314 | + ReflectApply(onParsePortComplete, this, arguments); | ||
| 296 | 315 | } | |
| 297 | 316 | ||
| 298 | 317 | function onParsePathComplete(flags, protocol, username, password, | |
@@ -332,8 +351,8 @@ class URL { | |||
| 332 | 351 | base_context = new URL(base)[context]; | |
| 333 | 352 | } | |
| 334 | 353 | this[context] = new URLContext(); | |
| 335 | - parse(input, -1, base_context, undefined, onParseComplete.bind(this), | ||
| 336 | - onParseError); | ||
| 354 | + parse(input, -1, base_context, undefined, | ||
| 355 | + FunctionPrototypeBind(onParseComplete, this), onParseError); | ||
| 337 | 356 | } | |
| 338 | 357 | ||
| 339 | 358 | get [special]() { | |
@@ -461,8 +480,8 @@ ObjectDefineProperties(URL.prototype, { | |||
| 461 | 480 | set(input) { | |
| 462 | 481 | // toUSVString is not needed. | |
| 463 | 482 | input = `${input}`; | |
| 464 | - parse(input, -1, undefined, undefined, onParseComplete.bind(this), | ||
| 465 | - onParseError); | ||
| 483 | + parse(input, -1, undefined, undefined, | ||
| 484 | + FunctionPrototypeBind(onParseComplete, this), onParseError); | ||
| 466 | 485 | } | |
| 467 | 486 | }, | |
| 468 | 487 | origin: { // readonly | |
@@ -504,7 +523,7 @@ ObjectDefineProperties(URL.prototype, { | |||
| 504 | 523 | return; | |
| 505 | 524 | const ctx = this[context]; | |
| 506 | 525 | parse(scheme, kSchemeStart, null, ctx, | |
| 507 | - onParseProtocolComplete.bind(this)); | ||
| 526 | + FunctionPrototypeBind(onParseProtocolComplete, this)); | ||
| 508 | 527 | } | |
| 509 | 528 | }, | |
| 510 | 529 | username: { | |
@@ -567,7 +586,8 @@ ObjectDefineProperties(URL.prototype, { | |||
| 567 | 586 | // Cannot set the host if cannot-be-base is set | |
| 568 | 587 | return; | |
| 569 | 588 | } | |
| 570 | - parse(host, kHost, null, ctx, onParseHostComplete.bind(this)); | ||
| 589 | + parse(host, kHost, null, ctx, | ||
| 590 | + FunctionPrototypeBind(onParseHostComplete, this)); | ||
| 571 | 591 | } | |
| 572 | 592 | }, | |
| 573 | 593 | hostname: { | |
@@ -604,7 +624,8 @@ ObjectDefineProperties(URL.prototype, { | |||
| 604 | 624 | ctx.port = null; | |
| 605 | 625 | return; | |
| 606 | 626 | } | |
| 607 | - parse(port, kPort, null, ctx, onParsePortComplete.bind(this)); | ||
| 627 | + parse(port, kPort, null, ctx, | ||
| 628 | + FunctionPrototypeBind(onParsePortComplete, this)); | ||
| 608 | 629 | } | |
| 609 | 630 | }, | |
| 610 | 631 | pathname: { | |
@@ -616,7 +637,7 @@ ObjectDefineProperties(URL.prototype, { | |||
| 616 | 637 | return ctx.path[0]; | |
| 617 | 638 | if (ctx.path.length === 0) | |
| 618 | 639 | return ''; | |
| 619 | - return `/${ctx.path.join('/')}`; | ||
| 640 | + return `/${ArrayPrototypeJoin(ctx.path, '/')}`; | ||
| 620 | 641 | }, | |
| 621 | 642 | set(path) { | |
| 622 | 643 | // toUSVString is not needed. | |
@@ -643,11 +664,12 @@ ObjectDefineProperties(URL.prototype, { | |||
| 643 | 664 | ctx.query = null; | |
| 644 | 665 | ctx.flags &= ~URL_FLAGS_HAS_QUERY; | |
| 645 | 666 | } else { | |
| 646 | - if (search[0] === '?') search = search.slice(1); | ||
| 667 | + if (search[0] === '?') search = StringPrototypeSlice(search, 1); | ||
| 647 | 668 | ctx.query = ''; | |
| 648 | 669 | ctx.flags |= URL_FLAGS_HAS_QUERY; | |
| 649 | 670 | if (search) { | |
| 650 | - parse(search, kQuery, null, ctx, onParseSearchComplete.bind(this)); | ||
| 671 | + parse(search, kQuery, null, ctx, | ||
| 672 | + FunctionPrototypeBind(onParseSearchComplete, this)); | ||
| 651 | 673 | } | |
| 652 | 674 | } | |
| 653 | 675 | initSearchParams(this[searchParams], search); | |
@@ -678,10 +700,11 @@ ObjectDefineProperties(URL.prototype, { | |||
| 678 | 700 | ctx.flags &= ~URL_FLAGS_HAS_FRAGMENT; | |
| 679 | 701 | return; | |
| 680 | 702 | } | |
| 681 | - if (hash[0] === '#') hash = hash.slice(1); | ||
| 703 | + if (hash[0] === '#') hash = StringPrototypeSlice(hash, 1); | ||
| 682 | 704 | ctx.fragment = ''; | |
| 683 | 705 | ctx.flags |= URL_FLAGS_HAS_FRAGMENT; | |
| 684 | - parse(hash, kFragment, null, ctx, onParseHashComplete.bind(this)); | ||
| 706 | + parse(hash, kFragment, null, ctx, | ||
| 707 | + FunctionPrototypeBind(onParseHashComplete, this)); | ||
| 685 | 708 | } | |
| 686 | 709 | }, | |
| 687 | 710 | toJSON: { | |
@@ -730,7 +753,7 @@ function parseParams(qs) { | |||
| 730 | 753 | let encodeCheck = 0; | |
| 731 | 754 | let i; | |
| 732 | 755 | for (i = 0; i < qs.length; ++i) { | |
| 733 | - const code = qs.charCodeAt(i); | ||
| 756 | + const code = StringPrototypeCharCodeAt(qs, i); | ||
| 734 | 757 | ||
| 735 | 758 | // Try matching key/value pair separator | |
| 736 | 759 | if (code === CHAR_AMPERSAND) { | |
@@ -778,7 +801,7 @@ function parseParams(qs) { | |||
| 778 | 801 | // Handle + and percent decoding. | |
| 779 | 802 | if (code === CHAR_PLUS) { | |
| 780 | 803 | if (lastPos < i) | |
| 781 | - buf += qs.slice(lastPos, i); | ||
| 804 | + buf += StringPrototypeSlice(qs, lastPos, i); | ||
| 782 | 805 | buf += ' '; | |
| 783 | 806 | lastPos = i + 1; | |
| 784 | 807 | } else if (!encoded) { | |
@@ -806,14 +829,14 @@ function parseParams(qs) { | |||
| 806 | 829 | return out; | |
| 807 | 830 | ||
| 808 | 831 | if (lastPos < i) | |
| 809 | - buf += qs.slice(lastPos, i); | ||
| 832 | + buf += StringPrototypeSlice(qs, lastPos, i); | ||
| 810 | 833 | if (encoded) | |
| 811 | 834 | buf = querystring.unescape(buf); | |
| 812 | - out.push(buf); | ||
| 835 | + ArrayPrototypePush(out, buf); | ||
| 813 | 836 | ||
| 814 | 837 | // If `buf` is the key, add an empty value. | |
| 815 | 838 | if (!seenSep) | |
| 816 | - out.push(''); | ||
| 839 | + ArrayPrototypePush(out, ''); | ||
| 817 | 840 | ||
| 818 | 841 | return out; | |
| 819 | 842 | } | |
@@ -927,7 +950,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { | |||
| 927 | 950 | ||
| 928 | 951 | name = toUSVString(name); | |
| 929 | 952 | value = toUSVString(value); | |
| 930 | - this[searchParams].push(name, value); | ||
| 953 | + ArrayPrototypePush(this[searchParams], name, value); | ||
| 931 | 954 | update(this[context], this); | |
| 932 | 955 | }, | |
| 933 | 956 | ||
@@ -1041,7 +1064,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { | |||
| 1041 | 1064 | // Otherwise, append a new name-value pair whose name is `name` and value | |
| 1042 | 1065 | // is `value`, to `list`. | |
| 1043 | 1066 | if (!found) { | |
| 1044 | - list.push(name, value); | ||
| 1067 | + ArrayPrototypePush(list, name, value); | ||
| 1045 | 1068 | } | |
| 1046 | 1069 | ||
| 1047 | 1070 | update(this[context], this); | |
@@ -1227,24 +1250,28 @@ defineIDLClass(URLSearchParamsIteratorPrototype, 'URLSearchParams Iterator', { | |||
| 1227 | 1250 | kind, | |
| 1228 | 1251 | index | |
| 1229 | 1252 | } = this[context]; | |
| 1230 | - const output = target[searchParams].slice(index).reduce((prev, cur, i) => { | ||
| 1231 | - const key = i % 2 === 0; | ||
| 1232 | - if (kind === 'key' && key) { | ||
| 1233 | - prev.push(cur); | ||
| 1234 | - } else if (kind === 'value' && !key) { | ||
| 1235 | - prev.push(cur); | ||
| 1236 | - } else if (kind === 'key+value' && !key) { | ||
| 1237 | - prev.push([target[searchParams][index + i - 1], cur]); | ||
| 1238 | - } | ||
| 1239 | - return prev; | ||
| 1240 | - }, []); | ||
| 1253 | + const output = ArrayPrototypeReduce( | ||
| 1254 | + ArrayPrototypeSlice(target[searchParams], index), | ||
| 1255 | + (prev, cur, i) => { | ||
| 1256 | + const key = i % 2 === 0; | ||
| 1257 | + if (kind === 'key' && key) { | ||
| 1258 | + ArrayPrototypePush(prev, cur); | ||
| 1259 | + } else if (kind === 'value' && !key) { | ||
| 1260 | + ArrayPrototypePush(prev, cur); | ||
| 1261 | + } else if (kind === 'key+value' && !key) { | ||
| 1262 | + ArrayPrototypePush(prev, [target[searchParams][index + i - 1], cur]); | ||
| 1263 | + } | ||
| 1264 | + return prev; | ||
| 1265 | + }, | ||
| 1266 | + [] | ||
| 1267 | + ); | ||
| 1241 | 1268 | const breakLn = inspect(output, innerOpts).includes('\n'); | |
| 1242 | - const outputStrs = output.map((p) => inspect(p, innerOpts)); | ||
| 1269 | + const outputStrs = ArrayPrototypeMap(output, (p) => inspect(p, innerOpts)); | ||
| 1243 | 1270 | let outputStr; | |
| 1244 | 1271 | if (breakLn) { | |
| 1245 | - outputStr = `\n ${outputStrs.join(',\n ')}`; | ||
| 1272 | + outputStr = `\n ${ArrayPrototypeJoin(outputStrs, ',\n ')}`; | ||
| 1246 | 1273 | } else { | |
| 1247 | - outputStr = ` ${outputStrs.join(', ')}`; | ||
| 1274 | + outputStr = ` ${ArrayPrototypeJoin(outputStrs, ', ')}`; | ||
| 1248 | 1275 | } | |
| 1249 | 1276 | return `${this[SymbolToStringTag]} {${outputStr} }`; | |
| 1250 | 1277 | } | |
@@ -1272,8 +1299,9 @@ function domainToUnicode(domain) { | |||
| 1272 | 1299 | function urlToOptions(url) { | |
| 1273 | 1300 | const options = { | |
| 1274 | 1301 | protocol: url.protocol, | |
| 1275 | - hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ? | ||
| 1276 | - url.hostname.slice(1, -1) : | ||
| 1302 | + hostname: typeof url.hostname === 'string' && | ||
| 1303 | + StringPrototypeStartsWith(url.hostname, '[') ? | ||
| 1304 | + StringPrototypeSlice(url.hostname, 1, -1) : | ||
| 1277 | 1305 | url.hostname, | |
| 1278 | 1306 | hash: url.hash, | |
| 1279 | 1307 | search: url.search, | |
@@ -1373,25 +1401,25 @@ const carriageReturnRegEx = /\r/g; | |||
| 1373 | 1401 | const tabRegEx = /\t/g; | |
| 1374 | 1402 | ||
| 1375 | 1403 | function encodePathChars(filepath) { | |
| 1376 | - if (filepath.includes('%')) | ||
| 1377 | - filepath = filepath.replace(percentRegEx, '%25'); | ||
| 1404 | + if (StringPrototypeIncludes(filepath, '%')) | ||
| 1405 | + filepath = StringPrototypeReplace(filepath, percentRegEx, '%25'); | ||
| 1378 | 1406 | // In posix, backslash is a valid character in paths: | |
| 1379 | - if (!isWindows && filepath.includes('\\')) | ||
| 1380 | - filepath = filepath.replace(backslashRegEx, '%5C'); | ||
| 1381 | - if (filepath.includes('\n')) | ||
| 1382 | - filepath = filepath.replace(newlineRegEx, '%0A'); | ||
| 1383 | - if (filepath.includes('\r')) | ||
| 1384 | - filepath = filepath.replace(carriageReturnRegEx, '%0D'); | ||
| 1385 | - if (filepath.includes('\t')) | ||
| 1386 | - filepath = filepath.replace(tabRegEx, '%09'); | ||
| 1407 | + if (!isWindows && StringPrototypeIncludes(filepath, '\\')) | ||
| 1408 | + filepath = StringPrototypeReplace(filepath, backslashRegEx, '%5C'); | ||
| 1409 | + if (StringPrototypeIncludes(filepath, '\n')) | ||
| 1410 | + filepath = StringPrototypeReplace(filepath, newlineRegEx, '%0A'); | ||
| 1411 | + if (StringPrototypeIncludes(filepath, '\r')) | ||
| 1412 | + filepath = StringPrototypeReplace(filepath, carriageReturnRegEx, '%0D'); | ||
| 1413 | + if (StringPrototypeIncludes(filepath, '\t')) | ||
| 1414 | + filepath = StringPrototypeReplace(filepath, tabRegEx, '%09'); | ||
| 1387 | 1415 | return filepath; | |
| 1388 | 1416 | } | |
| 1389 | 1417 | ||
| 1390 | 1418 | function pathToFileURL(filepath) { | |
| 1391 | 1419 | const outURL = new URL('file://'); | |
| 1392 | - if (isWindows && filepath.startsWith('\\\\')) { | ||
| 1420 | + if (isWindows && StringPrototypeStartsWith(filepath, '\\\\')) { | ||
| 1393 | 1421 | // UNC path format: \\server\share\resource | |
| 1394 | - const paths = filepath.split('\\'); | ||
| 1422 | + const paths = StringPrototypeSplit(filepath, '\\'); | ||
| 1395 | 1423 | if (paths.length <= 3) { | |
| 1396 | 1424 | throw new ERR_INVALID_ARG_VALUE( | |
| 1397 | 1425 | 'filepath', | |
@@ -1408,11 +1436,13 @@ function pathToFileURL(filepath) { | |||
| 1408 | 1436 | ); | |
| 1409 | 1437 | } | |
| 1410 | 1438 | outURL.hostname = domainToASCII(hostname); | |
| 1411 | - outURL.pathname = encodePathChars(paths.slice(3).join('/')); | ||
| 1439 | + outURL.pathname = encodePathChars( | ||
| 1440 | + ArrayPrototypeJoin(ArrayPrototypeSlice(paths, 3), '/')); | ||
| 1412 | 1441 | } else { | |
| 1413 | 1442 | let resolved = path.resolve(filepath); | |
| 1414 | 1443 | // path.resolve strips trailing slashes so we must add them back | |
| 1415 | - const filePathLast = filepath.charCodeAt(filepath.length - 1); | ||
| 1444 | + const filePathLast = StringPrototypeCharCodeAt(filepath, | ||
| 1445 | + filepath.length - 1); | ||
| 1416 | 1446 | if ((filePathLast === CHAR_FORWARD_SLASH || | |
| 1417 | 1447 | (isWindows && filePathLast === CHAR_BACKWARD_SLASH)) && | |
| 1418 | 1448 | resolved[resolved.length - 1] !== path.sep) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments