Revoke object URLs in two error cases

This commit is contained in:
Evan Hahn 2021-02-23 10:00:18 -06:00 committed by Josh Perez
parent 1ee47735d9
commit c4551ca7ca
2 changed files with 17 additions and 3 deletions

View file

@ -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;
});
},