Skip to content

Commit

Permalink
ensure imag datauri is released (#10118)
Browse files Browse the repository at this point in the history

Co-authored-by: Vladimir Agafonkin <agafonkin@gmail.com>
  • Loading branch information
Arindam Bose and mourner authored Nov 18, 2020
1 parent ee6136c commit 59c5425
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/util/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ function arrayBufferToImage(data: ArrayBuffer, callback: (err: ?Error, image: ?H
img.onload = () => {
callback(null, img);
URL.revokeObjectURL(img.src);
// prevent image dataURI memory leak in Safari
img.onload = null;
img.src = transparentPngUrl;
};
img.onerror = () => callback(new Error('Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.'));
const blob: Blob = new window.Blob([new Uint8Array(data)], {type: 'image/png'});
Expand Down
8 changes: 6 additions & 2 deletions test/unit/util/ajax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ test('ajax', (t) => {
const jsdomImage = window.Image;
window.Image = class {
set src(src) {
setTimeout(() => this.onload());
setTimeout(() => {
if (this.onload) this.onload();
});
}
};

Expand Down Expand Up @@ -200,7 +202,9 @@ test('ajax', (t) => {
// jsdom doesn't call image onload; fake it https://github.com/jsdom/jsdom/issues/1816
window.Image = class {
set src(src) {
setTimeout(() => this.onload());
setTimeout(() => {
if (this.onload) this.onload();
});
}
};

Expand Down

0 comments on commit 59c5425

Please sign in to comment.