Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]: String.fromCharCode.apply Maximum call stack size exceeded #106

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/recorder/src/watchers/font.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,21 @@ export class FontWatcher extends Watcher<FontRecord> {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
// https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
function ab2str(buffer: ArrayBuffer) {
return String.fromCharCode.apply(null, buffer)
const buf = new Uint16Array(buffer)
const len = buf.byteLength

let gap = Math.pow(2, 16) - 1
let res = ''

for (let i = 0; i < len; i += gap) {
if (i + gap > len) {
gap = len - i
}

res += String.fromCharCode.apply(null, buf.subarray(i, i + gap))
}

return res
}

const font = new original(family, source)
Expand Down