Use Image.prototype.decode only when src is already set
This commit is contained in:
+1
-1
@@ -159,7 +159,7 @@ class ImageWrapper extends ImageBase {
|
|||||||
export function listenImage(image, loadHandler, errorHandler) {
|
export function listenImage(image, loadHandler, errorHandler) {
|
||||||
const img = /** @type {HTMLImageElement} */ (image);
|
const img = /** @type {HTMLImageElement} */ (image);
|
||||||
|
|
||||||
if (IMAGE_DECODE) {
|
if (img.src && IMAGE_DECODE) {
|
||||||
const promise = img.decode();
|
const promise = img.decode();
|
||||||
let listening = true;
|
let listening = true;
|
||||||
const unlisten = function() {
|
const unlisten = function() {
|
||||||
|
|||||||
@@ -21,6 +21,17 @@ describe('HTML Image loading', function() {
|
|||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles load event when src is set later', function(done) {
|
||||||
|
listenImage(img, handleLoad, handleError);
|
||||||
|
img.src = 'spec/ol/data/dot.png';
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
expect(handleLoad).to.be.called();
|
||||||
|
expect(handleError).not.to.be.called();
|
||||||
|
done();
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
|
|
||||||
it('handles error event', function(done) {
|
it('handles error event', function(done) {
|
||||||
img.src = 'invalid.jpeg';
|
img.src = 'invalid.jpeg';
|
||||||
listenImage(img, handleLoad, handleError);
|
listenImage(img, handleLoad, handleError);
|
||||||
|
|||||||
Reference in New Issue
Block a user