File tree Expand file tree Collapse file tree 1 file changed +22
-4
lines changed
Expand file tree Collapse file tree 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 11import { Cache } from './Cache.js' ;
22import { Loader } from './Loader.js' ;
33
4+ const _errorMap = new WeakMap ( ) ;
5+
46/**
57 * A loader for loading images as an [ImageBitmap]{@link https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap}.
68 * An `ImageBitmap` provides an asynchronous and resource efficient pathway to prepare
@@ -111,13 +113,27 @@ class ImageBitmapLoader extends Loader {
111113
112114 cached . then ( imageBitmap => {
113115
114- if ( onLoad ) onLoad ( imageBitmap ) ;
116+ // The code checks if there is an error for the cached promise. If so, throw
117+ // a new error to force the code flow into the catch() block.
115118
116- scope . manager . itemEnd ( url ) ;
119+ if ( _errorMap . has ( cached ) === true ) {
120+
121+ throw new Error ( ) ;
122+
123+ } else {
124+
125+ if ( onLoad ) onLoad ( imageBitmap ) ;
117126
118- } ) . catch ( e => {
127+ scope . manager . itemEnd ( url ) ;
119128
120- if ( onError ) onError ( e ) ;
129+ }
130+
131+ } ) . catch ( ( ) => {
132+
133+ if ( onError ) onError ( _errorMap . get ( cached ) ) ;
134+
135+ scope . manager . itemError ( url ) ;
136+ scope . manager . itemEnd ( url ) ;
121137
122138 } ) ;
123139 return ;
@@ -163,6 +179,8 @@ class ImageBitmapLoader extends Loader {
163179
164180 if ( onError ) onError ( e ) ;
165181
182+ _errorMap . set ( promise , e ) ;
183+
166184 Cache . remove ( url ) ;
167185
168186 scope . manager . itemError ( url ) ;
You can’t perform that action at this time.
0 commit comments