Skip to content

Commit

Permalink
Updated the utfDecodeString() method to avoid a RangeError
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brian Vaughn committed Sep 17, 2021
1 parent a8cabb5 commit 03518ad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/react-devtools-shared/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ export function getUID(): number {
}

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

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

0 comments on commit 03518ad

Please sign in to comment.