@@ -83,8 +83,9 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
83
83
}
84
84
85
85
var fetch_attr = fetch + { { { C_STRUCTS . emscripten_fetch_t . __attributes } } } ;
86
- var path = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . destinationPath } } } >> 2 ] ;
87
- path ||= HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . url } } } >> 2 ] ;
86
+ var path = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . destinationPath , '*' ) } } } ;
87
+ path ||= { { { makeGetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . url , '*' ) } } } ;
88
+
88
89
var pathStr = UTF8ToString ( path ) ;
89
90
90
91
try {
@@ -96,21 +97,23 @@ function fetchDeleteCachedData(db, fetch, onsuccess, onerror) {
96
97
#if FETCH_DEBUG
97
98
dbg ( `fetch: Deleted file ${ pathStr } from IndexedDB` ) ;
98
99
#endif
99
- HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . data } } } >> 2 ] = 0 ;
100
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . data , 0 , '*' ) } } } ;
100
101
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . numBytes } } } , 0 ) ;
101
102
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . dataOffset } } } , 0 ) ;
102
103
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . totalBytes } } } , 0 ) ;
103
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
104
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 200 ; // Mimic XHR HTTP status code 200 "OK"
104
+ // Mimic XHR readyState 4 === 'DONE: The operation is complete'
105
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } ;
106
+ // Mimic XHR HTTP status code 200 "OK"
107
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 200 , 'i16' ) } } } ;
105
108
stringToUTF8 ( "OK" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
106
109
onsuccess ( fetch , 0 , value ) ;
107
110
} ;
108
111
request . onerror = ( error ) => {
109
112
#if FETCH_DEBUG
110
113
dbg ( `fetch: Failed to delete file ${ pathStr } from IndexedDB! error: ${ error } ` ) ;
111
114
#endif
112
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
113
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 404 ; // Mimic XHR HTTP status code 404 "Not Found"
115
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
116
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 404 , 'i16' ) } } } // Mimic XHR HTTP status code 404 "Not Found"
114
117
stringToUTF8 ( "Not Found" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
115
118
onerror ( fetch , 0 , error ) ;
116
119
} ;
@@ -132,8 +135,8 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
132
135
}
133
136
134
137
var fetch_attr = fetch + { { { C_STRUCTS . emscripten_fetch_t . __attributes } } } ;
135
- var path = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . destinationPath } } } >> 2 ] ;
136
- path ||= HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . url } } } >> 2 ] ;
138
+ var path = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . destinationPath , '*' ) } } } ;
139
+ path ||= { { { makeGetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . url , '*' ) } } } ;
137
140
var pathStr = UTF8ToString ( path ) ;
138
141
139
142
try {
@@ -151,21 +154,21 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
151
154
// freed when emscripten_fetch_close() is called.
152
155
var ptr = _malloc ( len ) ;
153
156
HEAPU8 . set ( new Uint8Array ( value ) , ptr ) ;
154
- HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . data } } } >> 2 ] = ptr ;
157
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . data , 'ptr' , '*' ) } } } ;
155
158
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . numBytes } } } , len ) ;
156
159
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . dataOffset } } } , 0 ) ;
157
160
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . totalBytes } } } , len ) ;
158
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
159
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 200 ; // Mimic XHR HTTP status code 200 "OK"
161
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
162
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 200 , 'i16' ) } } } // Mimic XHR HTTP status code 200 "OK"
160
163
stringToUTF8 ( "OK" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
161
164
onsuccess ( fetch , 0 , value ) ;
162
165
} else {
163
166
// Succeeded to load, but the load came back with the value of undefined, treat that as an error since we never store undefined in db.
164
167
#if FETCH_DEBUG
165
168
dbg ( `fetch: File ${ pathStr } not found in IndexedDB` ) ;
166
169
#endif
167
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
168
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 404 ; // Mimic XHR HTTP status code 404 "Not Found"
170
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
171
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 404 , 'i16' ) } } } // Mimic XHR HTTP status code 404 "Not Found"
169
172
stringToUTF8 ( "Not Found" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
170
173
onerror ( fetch , 0 , 'no data' ) ;
171
174
}
@@ -174,8 +177,8 @@ function fetchLoadCachedData(db, fetch, onsuccess, onerror) {
174
177
#if FETCH_DEBUG
175
178
dbg ( `fetch: Failed to load file ${ pathStr } from IndexedDB!` ) ;
176
179
#endif
177
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
178
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 404 ; // Mimic XHR HTTP status code 404 "Not Found"
180
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
181
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 404 , 'i16' ) } } } // Mimic XHR HTTP status code 404 "Not Found"
179
182
stringToUTF8 ( "Not Found" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
180
183
onerror ( fetch , 0 , error ) ;
181
184
} ;
@@ -197,8 +200,8 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
197
200
}
198
201
199
202
var fetch_attr = fetch + { { { C_STRUCTS . emscripten_fetch_t . __attributes } } } ;
200
- var destinationPath = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . destinationPath } } } >> 2 ] ;
201
- destinationPath ||= HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . url } } } >> 2 ] ;
203
+ var destinationPath = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . destinationPath , '*' ) } } } ;
204
+ destinationPath ||= { { { makeGetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . url , '*' ) } } } ;
202
205
var destinationPathStr = UTF8ToString ( destinationPath ) ;
203
206
204
207
try {
@@ -209,8 +212,8 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
209
212
#if FETCH_DEBUG
210
213
dbg ( `fetch: Stored file "${ destinationPathStr } " to IndexedDB cache.` ) ;
211
214
#endif
212
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
213
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 200 ; // Mimic XHR HTTP status code 200 "OK"
215
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
216
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 200 , 'i16' ) } } } // Mimic XHR HTTP status code 200 "OK"
214
217
stringToUTF8 ( "OK" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
215
218
onsuccess ( fetch , 0 , destinationPathStr ) ;
216
219
} ;
@@ -221,8 +224,8 @@ function fetchCacheData(/** @type {IDBDatabase} */ db, fetch, data, onsuccess, o
221
224
// Most likely we got an error if IndexedDB is unwilling to store any more data for this page.
222
225
// TODO: Can we identify and break down different IndexedDB-provided errors and convert those
223
226
// to more HTTP status codes for more information?
224
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = 4 ; // Mimic XHR readyState 4 === 'DONE: The operation is complete'
225
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = 413 ; // Mimic XHR HTTP status code 413 "Payload Too Large"
227
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , 4 , 'i16' ) } } } // Mimic XHR readyState 4 === 'DONE: The operation is complete'
228
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , 413 , 'i16' ) } } } // Mimic XHR HTTP status code 413 "Payload Too Large"
226
229
stringToUTF8 ( "Payload Too Large" , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
227
230
onerror ( fetch , 0 , error ) ;
228
231
} ;
@@ -329,7 +332,7 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
329
332
ptr = _malloc ( ptrLen ) ;
330
333
HEAPU8 . set ( new Uint8Array ( /** @type {Array<number> } */ ( xhr . response ) ) , ptr ) ;
331
334
}
332
- HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . data } } } >> 2 ] = ptr ;
335
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . data , 'ptr' , '*' ) } } }
333
336
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . numBytes } } } , ptrLen ) ;
334
337
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . dataOffset } } } , 0 ) ;
335
338
var len = xhr . response ? xhr . response . byteLength : 0 ;
@@ -339,8 +342,8 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
339
342
// the most recent XHR.onprogress handler.
340
343
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . totalBytes } } } , len ) ;
341
344
}
342
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = xhr . readyState ;
343
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = xhr . status ;
345
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , ' xhr.readyState' , 'i16' ) } } }
346
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , ' xhr.status' , 'i16' ) } } }
344
347
if ( xhr . statusText ) stringToUTF8 ( xhr . statusText , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
345
348
}
346
349
@@ -401,14 +404,14 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
401
404
ptr = _malloc ( ptrLen ) ;
402
405
HEAPU8 . set ( new Uint8Array ( /** @type {Array<number> } */ ( xhr . response ) ) , ptr ) ;
403
406
}
404
- HEAPU32 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . data } } } >> 2 ] = ptr ;
407
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . data , 'ptr' , '*' ) } } }
405
408
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . numBytes } } } , ptrLen ) ;
406
409
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . dataOffset } } } , e . loaded - ptrLen ) ;
407
410
writeI53ToI64 ( fetch + { { { C_STRUCTS . emscripten_fetch_t . totalBytes } } } , e . total ) ;
408
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = xhr . readyState ;
411
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , ' xhr.readyState' , 'i16' ) } } }
409
412
// If loading files from a source that does not give HTTP status code, assume success if we get data bytes
410
413
if ( xhr . readyState >= 3 && xhr . status === 0 && e . loaded > 0 ) xhr . status = 200 ;
411
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = xhr . status ;
414
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , ' xhr.status' , 'i16' ) } } }
412
415
if ( xhr . statusText ) stringToUTF8 ( xhr . statusText , fetch + { { { C_STRUCTS . emscripten_fetch_t . statusText } } } , 64 ) ;
413
416
onprogress ?. ( fetch , xhr , e ) ;
414
417
if ( ptr ) {
@@ -421,9 +424,9 @@ function fetchXHR(fetch, onsuccess, onerror, onprogress, onreadystatechange) {
421
424
{ { { runtimeKeepalivePop ( ) } } }
422
425
return ;
423
426
}
424
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . readyState } } } >> 1 ] = xhr . readyState ;
427
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . readyState , ' xhr.readyState' , 'i16' ) } } }
425
428
if ( xhr . readyState >= 2 ) {
426
- HEAPU16 [ fetch + { { { C_STRUCTS . emscripten_fetch_t . status } } } >> 1 ] = xhr . status ;
429
+ { { { makeSetValue ( 'fetch' , C_STRUCTS . emscripten_fetch_t . status , ' xhr.status' , 'i16' ) } } }
427
430
}
428
431
onreadystatechange ?. ( fetch , xhr , e ) ;
429
432
} ;
@@ -446,11 +449,11 @@ function startFetch(fetch, successcb, errorcb, progresscb, readystatechangecb) {
446
449
{ { { runtimeKeepalivePush ( ) } } }
447
450
448
451
var fetch_attr = fetch + { { { C_STRUCTS . emscripten_fetch_t . __attributes } } } ;
449
- var onsuccess = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . onsuccess } } } >> 2 ] ;
450
- var onerror = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . onerror } } } >> 2 ] ;
451
- var onprogress = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . onprogress } } } >> 2 ] ;
452
- var onreadystatechange = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . onreadystatechange } } } >> 2 ] ;
453
- var fetchAttributes = HEAPU32 [ fetch_attr + { { { C_STRUCTS . emscripten_fetch_attr_t . attributes } } } >> 2 ] ;
452
+ var onsuccess = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . onsuccess , '*' ) } } } ;
453
+ var onerror = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . onerror , '*' ) } } } ;
454
+ var onprogress = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . onprogress , '*' ) } } } ;
455
+ var onreadystatechange = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . onreadystatechange , '*' ) } } } ;
456
+ var fetchAttributes = { { { makeGetValue ( 'fetch_attr' , C_STRUCTS . emscripten_fetch_attr_t . attributes , '*' ) } } } ;
454
457
var fetchAttrSynchronous = ! ! ( fetchAttributes & { { { cDefs . EMSCRIPTEN_FETCH_SYNCHRONOUS } } } ) ;
455
458
456
459
function doCallback ( f ) {
0 commit comments