Skip to content

Commit 03518ad

Browse files
author
Brian Vaughn
committed
Updated the utfDecodeString() method to avoid a RangeError
Previously we were spreading the array of encoded values into String.fromCodePoint(...array). Functions arguments are first placed on the stack before the function is called though, which caused an error to be thrown for very large encoded strings.
1 parent a8cabb5 commit 03518ad

File tree

1 file changed

+10
-1
lines changed
  • packages/react-devtools-shared/src

1 file changed

+10
-1
lines changed

packages/react-devtools-shared/src/utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,16 @@ export function getUID(): number {
126126
}
127127

128128
export function utfDecodeString(array: Array<number>): string {
129-
return String.fromCodePoint(...array);
129+
// Avoid spreading the array (e.g. String.fromCodePoint(...array))
130+
// Functions arguments are first placed on the stack before the function is called
131+
// which throws a RangeError for large arrays.
132+
// See github.com/facebook/react/issues/22293
133+
let string = '';
134+
for (let i = 0; i < array.length; i++) {
135+
const char = array[i];
136+
string += String.fromCodePoint(char);
137+
}
138+
return string;
130139
}
131140

132141
export function utfEncodeString(string: string): Array<number> {

0 commit comments

Comments
 (0)