| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abfd71b commit 8eb1135
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2468,6 +2468,18 @@ const util = require('util'); | |||
| 2468 | 2468 | util.log('Timestamped message.'); | |
| 2469 | 2469 | ``` | |
| 2470 | 2470 | ||
| 2471 | + | ||
| 2472 | + ### `util.toUSVString(string)` | ||
| 2473 | + <!-- YAML | ||
| 2474 | + added: REPLACEME | ||
| 2475 | + --> | ||
| 2476 | + | ||
| 2477 | + * `string` {string} | ||
| 2478 | + | ||
| 2479 | + Returns the `string` after replacing any surrogate code points | ||
| 2480 | + (or equivalently, any unpaired surrogate code units) with the | ||
| 2481 | + Unicode "replacement character" U+FFFD. | ||
| 2482 | + | ||
| 2471 | 2483 | [Common System Errors]: errors.md#errors_common_system_errors | |
| 2472 | 2484 | [Custom inspection functions on objects]: #util_custom_inspection_functions_on_objects | |
| 2473 | 2485 | [Custom promisified functions]: #util_custom_promisified_functions | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,7 +19,6 @@ const { | |||
| 19 | 19 | ReflectApply, | |
| 20 | 20 | ReflectGetOwnPropertyDescriptor, | |
| 21 | 21 | ReflectOwnKeys, | |
| 22 | - RegExpPrototypeExec, | ||
| 23 | 22 | String, | |
| 24 | 23 | StringPrototypeCharCodeAt, | |
| 25 | 24 | StringPrototypeIncludes, | |
@@ -40,7 +39,12 @@ const { | |||
| 40 | 39 | isHexTable | |
| 41 | 40 | } = require('internal/querystring'); | |
| 42 | 41 | ||
| 43 | - const { getConstructorOf, removeColors } = require('internal/util'); | ||
| 42 | + const { | ||
| 43 | + getConstructorOf, | ||
| 44 | + removeColors, | ||
| 45 | + toUSVString, | ||
| 46 | + } = require('internal/util'); | ||
| 47 | + | ||
| 44 | 48 | const { | |
| 45 | 49 | ERR_ARG_NOT_ITERABLE, | |
| 46 | 50 | ERR_INVALID_ARG_TYPE, | |
@@ -76,7 +80,6 @@ const { | |||
| 76 | 80 | domainToASCII: _domainToASCII, | |
| 77 | 81 | domainToUnicode: _domainToUnicode, | |
| 78 | 82 | encodeAuth, | |
| 79 | - toUSVString: _toUSVString, | ||
| 80 | 83 | parse, | |
| 81 | 84 | setURLConstructor, | |
| 82 | 85 | URL_FLAGS_CANNOT_BE_BASE, | |
@@ -110,18 +113,6 @@ const IteratorPrototype = ObjectGetPrototypeOf( | |||
| 110 | 113 | ObjectGetPrototypeOf([][SymbolIterator]()) | |
| 111 | 114 | ); | |
| 112 | 115 | ||
| 113 | - const unpairedSurrogateRe = | ||
| 114 | - /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/; | ||
| 115 | - function toUSVString(val) { | ||
| 116 | - const str = `${val}`; | ||
| 117 | - // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are | ||
| 118 | - // slower than `unpairedSurrogateRe.exec()`. | ||
| 119 | - const match = RegExpPrototypeExec(unpairedSurrogateRe, str); | ||
| 120 | - if (!match) | ||
| 121 | - return str; | ||
| 122 | - return _toUSVString(str, match.index); | ||
| 123 | - } | ||
| 124 | - | ||
| 125 | 116 | // Refs: https://html.spec.whatwg.org/multipage/browsers.html#concept-origin-opaque | |
| 126 | 117 | const kOpaqueOrigin = 'null'; | |
| 127 | 118 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,11 +14,16 @@ const { | |||
| 14 | 14 | ObjectSetPrototypeOf, | |
| 15 | 15 | Promise, | |
| 16 | 16 | ReflectConstruct, | |
| 17 | + RegExpPrototypeExec, | ||
| 17 | 18 | Set, | |
| 18 | 19 | Symbol, | |
| 19 | 20 | SymbolFor, | |
| 20 | 21 | } = primordials; | |
| 21 | 22 | ||
| 23 | + const { | ||
| 24 | + toUSVString: _toUSVString, | ||
| 25 | + } = internalBinding('url'); | ||
| 26 | + | ||
| 22 | 27 | const { | |
| 23 | 28 | codes: { | |
| 24 | 29 | ERR_INVALID_ARG_TYPE, | |
@@ -44,6 +49,18 @@ const experimentalWarnings = new Set(); | |||
| 44 | 49 | ||
| 45 | 50 | const colorRegExp = /\u001b\[\d\d?m/g; // eslint-disable-line no-control-regex | |
| 46 | 51 | ||
| 52 | + const unpairedSurrogateRe = | ||
| 53 | + /(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])/; | ||
| 54 | + function toUSVString(val) { | ||
| 55 | + const str = `${val}`; | ||
| 56 | + // As of V8 5.5, `str.search()` (and `unpairedSurrogateRe[@@search]()`) are | ||
| 57 | + // slower than `unpairedSurrogateRe.exec()`. | ||
| 58 | + const match = RegExpPrototypeExec(unpairedSurrogateRe, str); | ||
| 59 | + if (!match) | ||
| 60 | + return str; | ||
| 61 | + return _toUSVString(str, match.index); | ||
| 62 | + } | ||
| 63 | + | ||
| 47 | 64 | let uvBinding; | |
| 48 | 65 | ||
| 49 | 66 | function lazyUv() { | |
@@ -452,6 +469,7 @@ module.exports = { | |||
| 452 | 469 | promisify, | |
| 453 | 470 | sleep, | |
| 454 | 471 | spliceOne, | |
| 472 | + toUSVString, | ||
| 455 | 473 | removeColors, | |
| 456 | 474 | ||
| 457 | 475 | // Symbol used to customize promisify conversion | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,8 @@ const { | |||
| 60 | 60 | deprecate, | |
| 61 | 61 | getSystemErrorMap, | |
| 62 | 62 | getSystemErrorName: internalErrorName, | |
| 63 | - promisify | ||
| 63 | + promisify, | ||
| 64 | + toUSVString, | ||
| 64 | 65 | } = require('internal/util'); | |
| 65 | 66 | ||
| 66 | 67 | let internalDeepEqual; | |
@@ -358,6 +359,7 @@ module.exports = { | |||
| 358 | 359 | isPrimitive, | |
| 359 | 360 | log, | |
| 360 | 361 | promisify, | |
| 362 | + toUSVString, | ||
| 361 | 363 | TextDecoder, | |
| 362 | 364 | TextEncoder, | |
| 363 | 365 | types | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,6 +148,8 @@ assert.strictEqual(util.isFunction(function() {}), true); | |||
| 148 | 148 | assert.strictEqual(util.isFunction(), false); | |
| 149 | 149 | assert.strictEqual(util.isFunction('string'), false); | |
| 150 | 150 | ||
| 151 | + assert.strictEqual(util.toUSVString('string\ud801'), 'string\ufffd'); | ||
| 152 | + | ||
| 151 | 153 | { | |
| 152 | 154 | assert.strictEqual(util.types.isNativeError(new Error()), true); | |
| 153 | 155 | assert.strictEqual(util.types.isNativeError(new TypeError()), true); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments