Revoke object URLs in two error cases
This commit is contained in:
parent
1ee47735d9
commit
c4551ca7ca
2 changed files with 17 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015-2020 Signal Messenger, LLC
|
||||
// Copyright 2015-2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/* global Whisper, loadImage */
|
||||
|
@ -21,7 +21,7 @@
|
|||
const svg = new Blob([html], { type: 'image/svg+xml;charset=utf-8' });
|
||||
return URL.createObjectURL(svg);
|
||||
},
|
||||
getDataUrl() {
|
||||
getDataUrl() /* : Promise<string> */ {
|
||||
const svgurl = this.getSVGUrl();
|
||||
return new Promise(resolve => {
|
||||
const img = document.createElement('img');
|
||||
|
@ -36,6 +36,11 @@
|
|||
URL.revokeObjectURL(svgurl);
|
||||
resolve(canvas.toDataURL('image/png'));
|
||||
};
|
||||
img.onerror = () => {
|
||||
URL.revokeObjectURL(svgurl);
|
||||
// If this fails for some reason, we'd rather continue on than reject.
|
||||
resolve(undefined);
|
||||
};
|
||||
|
||||
img.src = svgurl;
|
||||
});
|
||||
|
|
|
@ -1805,7 +1805,6 @@ Whisper.ConversationView = Whisper.View.extend({
|
|||
return new Promise((resolve, reject) => {
|
||||
const url = URL.createObjectURL(file);
|
||||
const img = document.createElement('img');
|
||||
img.onerror = reject;
|
||||
img.onload = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
|
@ -1863,6 +1862,16 @@ Whisper.ConversationView = Whisper.View.extend({
|
|||
file: blob,
|
||||
});
|
||||
};
|
||||
img.onerror = (
|
||||
_event: unknown,
|
||||
_source: unknown,
|
||||
_lineno: unknown,
|
||||
_colno: unknown,
|
||||
error: Error = new Error('Failed to load image for auto-scaling')
|
||||
) => {
|
||||
URL.revokeObjectURL(url);
|
||||
reject(error);
|
||||
};
|
||||
img.src = url;
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue