MCPcopy Index your code
hub / github.com/blueimp/JavaScript-Load-Image / executor

Function executor

js/load-image.js:110–189  ·  view source on GitHub ↗

* Promise executor * * @param {Function} resolve Resolution function * @param {Function} reject Rejection function * @returns {HTMLImageElement|FileReader} Object

(resolve, reject)

Source from the content-addressed store, hash-verified

108 * @returns {HTMLImageElement|FileReader} Object
109 */
110 function executor(resolve, reject) {
111 var img = document.createElement('img')
112 var url
113 /**
114 * Callback for the fetchBlob call.
115 *
116 * @param {HTMLImageElement|HTMLCanvasElement} img Error object
117 * @param {object} data Data object
118 * @returns {undefined} Undefined
119 */
120 function resolveWrapper(img, data) {
121 if (resolve === reject) {
122 // Not using Promises
123 if (resolve) resolve(img, data)
124 return
125 } else if (img instanceof Error) {
126 reject(img)
127 return
128 }
129 data = data || {} // eslint-disable-line no-param-reassign
130 data.image = img
131 resolve(data)
132 }
133 /**
134 * Callback for the fetchBlob call.
135 *
136 * @param {Blob} blob Blob object
137 * @param {Error} err Error object
138 */
139 function fetchBlobCallback(blob, err) {
140 if (err && $.console) console.log(err) // eslint-disable-line no-console
141 if (blob && isInstanceOf('Blob', blob)) {
142 file = blob // eslint-disable-line no-param-reassign
143 url = createObjectURL(file)
144 } else {
145 url = file
146 if (options && options.crossOrigin) {
147 img.crossOrigin = options.crossOrigin
148 }
149 }
150 img.src = url
151 }
152 img.onerror = function (event) {
153 revokeHelper(url, options)
154 if (reject) reject.call(img, event)
155 }
156 img.onload = function () {
157 revokeHelper(url, options)
158 var data = {
159 originalWidth: img.naturalWidth || img.width,
160 originalHeight: img.naturalHeight || img.height
161 }
162 try {
163 loadImage.transform(img, options, resolveWrapper, file, data)
164 } catch (error) {
165 if (reject) reject(error)
166 }
167 }

Callers 1

loadImageFunction · 0.70

Calls 5

revokeHelperFunction · 0.85
fetchBlobCallbackFunction · 0.85
isInstanceOfFunction · 0.85
createObjectURLFunction · 0.85
readFileFunction · 0.85

Tested by

no test coverage detected