A "RangeError: Maximum call stack size exceeded" error occurred when large array was passed in String.fromCharCode.apply. So I am trying to modify the code as follows. How do I create a large ArrayBuffer to test a modified function?
Original code:
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
}
Modified code:
function ab2str(buf) {
let str = '';
new Uint8Array(ab).forEach((data) => {
str += String.fromCharCode(data);
});
return str;
}
Test code:
let data;
beforeAll(() => {
data = createLargeArrayBuffer();
});
test('ab2str', () => {
const str = ab2str(data);
const result = str2ab(data);
expect(result).toStictEqual(data);
});
Aucun commentaire:
Enregistrer un commentaire