Skip to content

Commit df5b37d

Browse files
authored
[wasm64] Fix wget and run wget browser tests (#20544)
Split out from #20516
1 parent 680ae34 commit df5b37d

File tree

4 files changed

+42
-44
lines changed

4 files changed

+42
-44
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,8 @@ jobs:
821821
browser64.test_fetch_sync_xhr
822822
browser64.test_fetch_implicit_append
823823
browser64.test_pthread_*
824+
browser64.test_wget_*
825+
browser64.test_emscripten_async_wget_*
824826
"
825827
test-browser-firefox:
826828
executor: bionic

src/library_wget.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ var LibraryWget = {
3333
function doCallback(callback) {
3434
if (callback) {
3535
{{{ runtimeKeepalivePop() }}}
36-
callUserCallback(function() {
37-
withStackSave(function() {
38-
{{{ makeDynCall('vi', 'callback') }}}(stringToUTF8OnStack(_file));
36+
callUserCallback(() => {
37+
withStackSave(() => {
38+
{{{ makeDynCall('vp', 'callback') }}}(stringToUTF8OnStack(_file));
3939
});
4040
});
4141
}
@@ -45,15 +45,11 @@ var LibraryWget = {
4545
destinationDirectory,
4646
PATH.basename(_file),
4747
_url, true, true,
48-
function() {
49-
doCallback(onload);
50-
},
51-
function() {
52-
doCallback(onerror);
53-
},
48+
() => doCallback(onload),
49+
() => doCallback(onerror),
5450
false, // dontCreateFile
5551
false, // canOwn
56-
function() { // preFinish
52+
() => { // preFinish
5753
// if a file exists there, we overwrite it
5854
try {
5955
FS_unlink(_file);
@@ -66,29 +62,29 @@ var LibraryWget = {
6662

6763
emscripten_async_wget_data__deps: ['$asyncLoad', 'malloc', 'free', '$callUserCallback'],
6864
emscripten_async_wget_data__proxy: 'sync',
69-
emscripten_async_wget_data: (url, arg, onload, onerror) => {
65+
emscripten_async_wget_data: (url, userdata, onload, onerror) => {
7066
{{{ runtimeKeepalivePush() }}}
71-
asyncLoad(UTF8ToString(url), function(byteArray) {
67+
asyncLoad(UTF8ToString(url), (byteArray) => {
7268
{{{ runtimeKeepalivePop() }}}
73-
callUserCallback(function() {
69+
callUserCallback(() => {
7470
var buffer = _malloc(byteArray.length);
7571
HEAPU8.set(byteArray, buffer);
76-
{{{ makeDynCall('viii', 'onload') }}}(arg, buffer, byteArray.length);
72+
{{{ makeDynCall('vppi', 'onload') }}}(userdata, buffer, byteArray.length);
7773
_free(buffer);
7874
});
79-
}, function() {
75+
}, () => {
8076
if (onerror) {
8177
{{{ runtimeKeepalivePop() }}}
82-
callUserCallback(function() {
83-
{{{ makeDynCall('vi', 'onerror') }}}(arg);
78+
callUserCallback(() => {
79+
{{{ makeDynCall('vp', 'onerror') }}}(userdata);
8480
});
8581
}
8682
}, true /* no need for run dependency, this is async but will not do any prepare etc. step */ );
8783
},
8884

8985
emscripten_async_wget2__deps: ['$PATH_FS', '$wget', '$withStackSave', '$stringToUTF8OnStack'],
9086
emscripten_async_wget2__proxy: 'sync',
91-
emscripten_async_wget2: (url, file, request, param, arg, onload, onerror, onprogress) => {
87+
emscripten_async_wget2: (url, file, request, param, userdata, onload, onerror, onprogress) => {
9288
{{{ runtimeKeepalivePush() }}}
9389

9490
var _url = UTF8ToString(url);
@@ -107,7 +103,7 @@ var LibraryWget = {
107103
var destinationDirectory = PATH.dirname(_file);
108104

109105
// LOAD
110-
http.onload = function http_onload(e) {
106+
http.onload = (e) => {
111107
{{{ runtimeKeepalivePop() }}}
112108
if (http.status >= 200 && http.status < 300) {
113109
// if a file exists there, we overwrite it
@@ -119,34 +115,34 @@ var LibraryWget = {
119115

120116
FS.createDataFile( _file.substr(0, index), _file.substr(index + 1), new Uint8Array(/** @type{ArrayBuffer}*/(http.response)), true, true, false);
121117
if (onload) {
122-
withStackSave(function() {
123-
{{{ makeDynCall('viii', 'onload') }}}(handle, arg, stringToUTF8OnStack(_file));
118+
withStackSave(() => {
119+
{{{ makeDynCall('vipp', 'onload') }}}(handle, userdata, stringToUTF8OnStack(_file));
124120
});
125121
}
126122
} else {
127-
if (onerror) {{{ makeDynCall('viii', 'onerror') }}}(handle, arg, http.status);
123+
if (onerror) {{{ makeDynCall('vipi', 'onerror') }}}(handle, userdata, http.status);
128124
}
129125

130126
delete wget.wgetRequests[handle];
131127
};
132128

133129
// ERROR
134-
http.onerror = function http_onerror(e) {
130+
http.onerror = (e) => {
135131
{{{ runtimeKeepalivePop() }}}
136-
if (onerror) {{{ makeDynCall('viii', 'onerror') }}}(handle, arg, http.status);
132+
if (onerror) {{{ makeDynCall('vipi', 'onerror') }}}(handle, userdata, http.status);
137133
delete wget.wgetRequests[handle];
138134
};
139135

140136
// PROGRESS
141-
http.onprogress = function http_onprogress(e) {
137+
http.onprogress = (e) => {
142138
if (e.lengthComputable || (e.lengthComputable === undefined && e.total != 0)) {
143139
var percentComplete = (e.loaded / e.total)*100;
144-
if (onprogress) {{{ makeDynCall('viii', 'onprogress') }}}(handle, arg, percentComplete);
140+
if (onprogress) {{{ makeDynCall('vipi', 'onprogress') }}}(handle, userdata, percentComplete);
145141
}
146142
};
147143

148144
// ABORT
149-
http.onabort = function http_onabort(e) {
145+
http.onabort = (e) => {
150146
{{{ runtimeKeepalivePop() }}}
151147
delete wget.wgetRequests[handle];
152148
};
@@ -166,7 +162,7 @@ var LibraryWget = {
166162

167163
emscripten_async_wget2_data__deps: ['$wget', 'malloc', 'free'],
168164
emscripten_async_wget2_data__proxy: 'sync',
169-
emscripten_async_wget2_data: (url, request, param, arg, free, onload, onerror, onprogress) => {
165+
emscripten_async_wget2_data: (url, request, param, userdata, free, onload, onerror, onprogress) => {
170166
var _url = UTF8ToString(url);
171167
var _request = UTF8ToString(request);
172168
var _param = UTF8ToString(param);
@@ -184,18 +180,18 @@ var LibraryWget = {
184180
if (http.statusText) {
185181
statusText = stringToUTF8OnStack(http.statusText);
186182
}
187-
{{{ makeDynCall('viiii', 'onerror') }}}(handle, arg, http.status, statusText);
183+
{{{ makeDynCall('vipip', 'onerror') }}}(handle, userdata, http.status, statusText);
188184
});
189185
}
190186
}
191187

192188
// LOAD
193-
http.onload = function http_onload(e) {
189+
http.onload = (e) => {
194190
if (http.status >= 200 && http.status < 300 || (http.status === 0 && _url.substr(0,4).toLowerCase() != "http")) {
195191
var byteArray = new Uint8Array(/** @type{ArrayBuffer} */(http.response));
196192
var buffer = _malloc(byteArray.length);
197193
HEAPU8.set(byteArray, buffer);
198-
if (onload) {{{ makeDynCall('viiii', 'onload') }}}(handle, arg, buffer, byteArray.length);
194+
if (onload) {{{ makeDynCall('vippi', 'onload') }}}(handle, userdata, buffer, byteArray.length);
199195
if (free) _free(buffer);
200196
} else {
201197
onerrorjs();
@@ -204,18 +200,18 @@ var LibraryWget = {
204200
};
205201

206202
// ERROR
207-
http.onerror = function http_onerror(e) {
203+
http.onerror = (e) => {
208204
onerrorjs();
209205
delete wget.wgetRequests[handle];
210206
};
211207

212208
// PROGRESS
213-
http.onprogress = function http_onprogress(e) {
214-
if (onprogress) {{{ makeDynCall('viiii', 'onprogress') }}}(handle, arg, e.loaded, e.lengthComputable || e.lengthComputable === undefined ? e.total : 0);
209+
http.onprogress = (e) => {
210+
if (onprogress) {{{ makeDynCall('viiii', 'onprogress') }}}(handle, userdata, e.loaded, e.lengthComputable || e.lengthComputable === undefined ? e.total : 0);
215211
};
216212

217213
// ABORT
218-
http.onabort = function http_onabort(e) {
214+
http.onabort = (e) => {
219215
delete wget.wgetRequests[handle];
220216
};
221217

system/include/emscripten/wget.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ extern "C" {
1717

1818
void emscripten_async_wget(const char* url, const char* file, em_str_callback_func onload, em_str_callback_func onerror);
1919

20-
typedef void (*em_async_wget_onload_func)(void*, void*, int);
21-
void emscripten_async_wget_data(const char* url, void *arg, em_async_wget_onload_func onload, em_arg_callback_func onerror);
20+
typedef void (*em_async_wget_onload_func)(void* userdata, void* data, int size);
21+
void emscripten_async_wget_data(const char* url, void *userdata, em_async_wget_onload_func onload, em_arg_callback_func onerror);
2222

23-
typedef void (*em_async_wget2_onload_func)(unsigned, void*, const char*);
24-
typedef void (*em_async_wget2_onstatus_func)(unsigned, void*, int);
23+
typedef void (*em_async_wget2_onload_func)(unsigned handle, void* userdata, const char* data);
24+
typedef void (*em_async_wget2_onstatus_func)(unsigned handle, void* userdata, int status);
2525

26-
int emscripten_async_wget2(const char* url, const char* file, const char* requesttype, const char* param, void *arg, em_async_wget2_onload_func onload, em_async_wget2_onstatus_func onerror, em_async_wget2_onstatus_func onprogress);
26+
int emscripten_async_wget2(const char* url, const char* file, const char* requesttype, const char* param, void *userdata, em_async_wget2_onload_func onload, em_async_wget2_onstatus_func onerror, em_async_wget2_onstatus_func onprogress);
2727

28-
typedef void (*em_async_wget2_data_onload_func)(unsigned, void*, void*, unsigned);
29-
typedef void (*em_async_wget2_data_onerror_func)(unsigned, void*, int, const char*);
30-
typedef void (*em_async_wget2_data_onprogress_func)(unsigned, void*, int, int);
28+
typedef void (*em_async_wget2_data_onload_func)(unsigned handle, void* userdata, void* data, unsigned size);
29+
typedef void (*em_async_wget2_data_onerror_func)(unsigned handle, void* userdata, int status, const char* status_text);
30+
typedef void (*em_async_wget2_data_onprogress_func)(unsigned handle, void* userdata, int loaded, int total);
3131

3232
int emscripten_async_wget2_data(const char* url, const char* requesttype, const char* param, void *arg, int free, em_async_wget2_data_onload_func onload, em_async_wget2_data_onerror_func onerror, em_async_wget2_data_onprogress_func onprogress);
3333

test/test_browser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2547,7 +2547,7 @@ def test_emscripten_async_wget2_data(self):
25472547
self.btest('test_emscripten_async_wget2_data.cpp', expected='0')
25482548

25492549
def test_emscripten_async_wget_side_module(self):
2550-
self.run_process([EMCC, test_file('browser_module.c'), '-o', 'lib.wasm', '-O2', '-sSIDE_MODULE'])
2550+
self.emcc(test_file('browser_module.c'), ['-o', 'lib.wasm', '-O2', '-sSIDE_MODULE'])
25512551
self.btest_exit('browser_main.c', args=['-O2', '-sMAIN_MODULE=2'])
25522552

25532553
@parameterized({

0 commit comments

Comments
 (0)