(domElement: Element, tag: string, value: any)
| 8 | */ |
| 9 | |
| 10 | export function setSrcObject(domElement: Element, tag: string, value: any) { |
| 11 | // We optimistically create the URL regardless of object type. This lets us |
| 12 | // support cross-realms and any type that the browser supports like new types. |
| 13 | const url = URL.createObjectURL((value: any)); |
| 14 | const loadEvent = tag === 'img' ? 'load' : 'loadstart'; |
| 15 | const cleanUp = () => { |
| 16 | // Once the object has started loading, then it's already collected by the |
| 17 | // browser and it won't refer to it by the URL anymore so we can now revoke it. |
| 18 | URL.revokeObjectURL(url); |
| 19 | domElement.removeEventListener(loadEvent, cleanUp); |
| 20 | domElement.removeEventListener('error', cleanUp); |
| 21 | }; |
| 22 | domElement.addEventListener(loadEvent, cleanUp); |
| 23 | domElement.addEventListener('error', cleanUp); |
| 24 | domElement.setAttribute('src', url); |
| 25 | } |
no outgoing calls
no test coverage detected