| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -242,6 +242,9 @@ primordials.SafeWeakSet = makeSafe( | |||
| 242 | 242 | // Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object | |
| 243 | 243 | [ | |
| 244 | 244 | { name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) }, | |
| 245 | + { name: 'StringIterator', original: { | ||
| 246 | + prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()), | ||
| 247 | + } }, | ||
| 245 | 248 | ].forEach(({ name, original }) => { | |
| 246 | 249 | primordials[name] = original; | |
| 247 | 250 | // The static %TypedArray% methods require a valid `this`, but can't be bound, | |
@@ -250,5 +253,10 @@ primordials.SafeWeakSet = makeSafe( | |||
| 250 | 253 | copyPrototype(original.prototype, primordials, `${name}Prototype`); | |
| 251 | 254 | }); | |
| 252 | 255 | ||
| 256 | + primordials.SafeStringIterator = createSafeIterator( | ||
| 257 | + primordials.StringPrototypeSymbolIterator, | ||
| 258 | + primordials.StringIteratorPrototypeNext | ||
| 259 | + ); | ||
| 260 | + | ||
| 253 | 261 | Object.setPrototypeOf(primordials, null); | |
| 254 | 262 | Object.freeze(primordials); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ const { | |||
| 9 | 9 | MathMin, | |
| 10 | 10 | RegExpPrototypeTest, | |
| 11 | 11 | SafeSet, | |
| 12 | + SafeStringIterator, | ||
| 12 | 13 | StringPrototypeEndsWith, | |
| 13 | 14 | StringPrototypeIndexOf, | |
| 14 | 15 | StringPrototypeLastIndexOf, | |
@@ -425,7 +426,7 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { | |||
| 425 | 426 | getStringWidth(inspected) > maxColumns) { | |
| 426 | 427 | maxColumns -= 4 + (repl.useColors ? 0 : 3); | |
| 427 | 428 | let res = ''; | |
| 428 | - for (const char of inspected) { | ||
| 429 | + for (const char of new SafeStringIterator(inspected)) { | ||
| 429 | 430 | maxColumns -= getStringWidth(char); | |
| 430 | 431 | if (maxColumns < 0) | |
| 431 | 432 | break; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,7 @@ const { | |||
| 9 | 9 | StringPrototypeSlice, | |
| 10 | 10 | StringPrototypeSplit, | |
| 11 | 11 | StringPrototypeStartsWith, | |
| 12 | + SafeStringIterator, | ||
| 12 | 13 | } = primordials; | |
| 13 | 14 | ||
| 14 | 15 | let debug = require('internal/util/debuglog').debuglog('source_map', (fn) => { | |
@@ -144,7 +145,8 @@ function getErrorSource( | |||
| 144 | 145 | // Display ^ in appropriate position, regardless of whether tabs or | |
| 145 | 146 | // spaces are used: | |
| 146 | 147 | let prefix = ''; | |
| 147 | - for (const character of StringPrototypeSlice(line, 0, originalColumn + 1)) { | ||
| 148 | + for (const character of new SafeStringIterator( | ||
| 149 | + StringPrototypeSlice(line, 0, originalColumn + 1))) { | ||
| 148 | 150 | prefix += (character === '\t') ? '\t' : | |
| 149 | 151 | StringPrototypeRepeat(' ', getStringWidth(character)); | |
| 150 | 152 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,7 @@ const { | |||
| 42 | 42 | ReflectApply, | |
| 43 | 43 | RegExp, | |
| 44 | 44 | RegExpPrototypeToString, | |
| 45 | + SafeStringIterator, | ||
| 45 | 46 | Set, | |
| 46 | 47 | SetPrototypeGetSize, | |
| 47 | 48 | SetPrototypeValues, | |
@@ -2005,7 +2006,7 @@ if (internalBinding('config').hasIntl) { | |||
| 2005 | 2006 | if (removeControlChars) | |
| 2006 | 2007 | str = stripVTControlCharacters(str); | |
| 2007 | 2008 | str = str.normalize('NFC'); | |
| 2008 | - for (const char of str) { | ||
| 2009 | + for (const char of new SafeStringIterator(str)) { | ||
| 2009 | 2010 | const code = char.codePointAt(0); | |
| 2010 | 2011 | if (isFullWidthCodePoint(code)) { | |
| 2011 | 2012 | width += 2; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,7 @@ const { | |||
| 59 | 59 | StringPrototypeTrim, | |
| 60 | 60 | Symbol, | |
| 61 | 61 | SymbolAsyncIterator, | |
| 62 | + SafeStringIterator, | ||
| 62 | 63 | } = primordials; | |
| 63 | 64 | ||
| 64 | 65 | const { | |
@@ -752,7 +753,7 @@ Interface.prototype._getDisplayPos = function(str) { | |||
| 752 | 753 | const col = this.columns; | |
| 753 | 754 | let rows = 0; | |
| 754 | 755 | str = stripVTControlCharacters(str); | |
| 755 | - for (const char of str) { | ||
| 756 | + for (const char of new SafeStringIterator(str)) { | ||
| 756 | 757 | if (char === '\n') { | |
| 757 | 758 | // Rows must be incremented by 1 even if offset = 0 or col = +Infinity. | |
| 758 | 759 | rows += MathCeil(offset / col) || 1; | |
@@ -1168,7 +1169,7 @@ function emitKeypressEvents(stream, iface = {}) { | |||
| 1168 | 1169 | iface.isCompletionEnabled = false; | |
| 1169 | 1170 | ||
| 1170 | 1171 | let length = 0; | |
| 1171 | - for (const character of string) { | ||
| 1172 | + for (const character of new SafeStringIterator(string)) { | ||
| 1172 | 1173 | length += character.length; | |
| 1173 | 1174 | if (length === string.length) { | |
| 1174 | 1175 | iface.isCompletionEnabled = true; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments