-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Use fetch() for loading packages & shared libraries
#22002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
87743d1
3d38841
ffcaa3b
de79ead
139bcd4
893f361
0407112
24761b6
3ead8de
35b593f
5c2a7bb
5631928
ff2d142
9e06ef2
5899d3f
c09f2c5
2f43c20
c5ecce5
7e86b5b
6848055
0bf9b71
3f765bc
316aa8b
366b942
58ab5c6
5899e42
92ffd13
df4e1c3
bb9a69e
c8e9db9
272f093
6432c5a
e870667
ce4089e
4581d90
457ef2c
aeac94e
275388a
d4a6162
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,19 @@ | |
| return new Uint8Array(/** @type{!ArrayBuffer} */(xhr.response)); | ||
| }; | ||
| } | ||
|
|
||
| #if USE_FETCH | ||
| readAsync = (url, onload, onerror) => { | ||
| fetch(url) | ||
| .then(response => { | ||
| if(response.ok) { | ||
| return response.arrayBuffer(); | ||
| } | ||
| throw new Error(response.statusText + ' : ' + response.url); | ||
|
||
| }) | ||
| .then(onload) | ||
| .catch(onerror) | ||
| }; | ||
| #else | ||
| readAsync = (url, onload, onerror) => { | ||
| var xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', url, true); | ||
|
|
@@ -35,4 +47,4 @@ | |
| xhr.onerror = onerror; | ||
| xhr.send(null); | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "a.html": 354, | ||
| "a.html.gz": 266, | ||
| "a.js": 22181, | ||
| "a.js.gz": 11582, | ||
| "total": 22535, | ||
| "total_gz": 11848 | ||
| "a.js": 22196, | ||
| "a.js.gz": 11586, | ||
| "total": 22550, | ||
| "total_gz": 11852 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| { | ||
| "a.html": 354, | ||
| "a.html.gz": 266, | ||
| "a.js": 21683, | ||
| "a.js.gz": 11407, | ||
| "total": 22037, | ||
| "total_gz": 11673 | ||
| "a.js": 21698, | ||
| "a.js.gz": 11410, | ||
| "total": 22052, | ||
| "total_gz": 11676 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 55520 | ||
| 55518 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 31420 | ||
| 31418 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 54383 | ||
| 54381 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -290,8 +290,12 @@ def test_emscripten_log(self): | |
| self.btest_exit('emscripten_log/emscripten_log.cpp', | ||
| args=['-Wno-deprecated-pragma', '--pre-js', path_from_root('src/emscripten-source-map.min.js'), '-gsource-map']) | ||
|
|
||
| @parameterized({ | ||
| '': ([],), | ||
| 'use_fetch': (['-sUSE_FETCH'],), | ||
| }) | ||
| @also_with_wasmfs | ||
| def test_preload_file(self): | ||
| def test_preload_file(self, args): | ||
| create_file('somefile.txt', 'load me right before running the code please') | ||
| create_file('.somefile.txt', 'load me right before running the code please') | ||
| create_file('[email protected]', 'load me right before running the code please') | ||
|
|
@@ -344,7 +348,7 @@ def make_main(path): | |
| for srcpath, dstpath in test_cases: | ||
| print('Testing', srcpath, dstpath) | ||
| make_main(dstpath) | ||
| self.btest_exit('main.cpp', args=['--preload-file', srcpath]) | ||
| self.btest_exit('main.cpp', args=['--preload-file', srcpath] + args) | ||
| if WINDOWS: | ||
| # On Windows, the following non-alphanumeric non-control code ASCII characters are supported. | ||
| # The characters <, >, ", |, ?, * are not allowed, because the Windows filesystem doesn't support those. | ||
|
|
@@ -355,7 +359,7 @@ def make_main(path): | |
| create_file(tricky_filename, 'load me right before running the code please') | ||
| make_main(tricky_filename) | ||
| # As an Emscripten-specific feature, the character '@' must be escaped in the form '@@' to not confuse with the 'src@dst' notation. | ||
| self.btest_exit('main.cpp', args=['--preload-file', tricky_filename.replace('@', '@@')]) | ||
| self.btest_exit('main.cpp', args=['--preload-file', tricky_filename.replace('@', '@@')] + args) | ||
|
|
||
| # TODO: WASMFS doesn't support the rest of this test yet. Exit early. | ||
| if self.get_setting('WASMFS'): | ||
|
|
@@ -364,7 +368,7 @@ def make_main(path): | |
| # By absolute path | ||
|
|
||
| make_main('somefile.txt') # absolute becomes relative | ||
| self.btest_exit('main.cpp', args=['--preload-file', absolute_src_path]) | ||
| self.btest_exit('main.cpp', args=['--preload-file', absolute_src_path] + args) | ||
|
|
||
| # Test subdirectory handling with asset packaging. | ||
| delete_dir('assets') | ||
|
|
@@ -1405,13 +1409,17 @@ def test_fs_workerfs_read(self): | |
| ''' % (secret, secret2)) | ||
| self.btest_exit('fs/test_workerfs_read.c', args=['-lworkerfs.js', '--pre-js', 'pre.js', f'-DSECRET="{secret }"', f'-DSECRET2="{secret2}"', '--proxy-to-worker', '-lworkerfs.js']) | ||
|
|
||
| def test_fs_workerfs_package(self): | ||
| @parameterized({ | ||
| '': ([],), | ||
| 'use_fetch': (['-sUSE_FETCH'],), | ||
| }) | ||
| def test_fs_workerfs_package(self, args): | ||
| self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', '$ccall') | ||
| create_file('file1.txt', 'first') | ||
| ensure_dir('sub') | ||
| create_file('sub/file2.txt', 'second') | ||
| self.run_process([FILE_PACKAGER, 'files.data', '--preload', 'file1.txt', Path('sub/file2.txt'), '--separate-metadata', '--js-output=files.js']) | ||
| self.btest(Path('fs/test_workerfs_package.cpp'), '1', args=['-lworkerfs.js', '--proxy-to-worker', '-lworkerfs.js']) | ||
| self.btest(Path('fs/test_workerfs_package.cpp'), '1', args=['-lworkerfs.js', '--proxy-to-worker', '-lworkerfs.js'] + args) | ||
|
|
||
| def test_fs_lz4fs_package(self): | ||
| # generate data | ||
|
|
@@ -1470,14 +1478,17 @@ def test_fs_lz4fs_package(self): | |
| out = subprocess.check_output([FILE_PACKAGER, 'files.data', '--preload', 'files/file1.txt', 'files/file2.txt', 'files/file3.txt']) | ||
| create_file('files.js', out, binary=True) | ||
| self.btest_exit('fs/test_lz4fs.cpp', 2, args=['--pre-js', 'files.js'])''' | ||
|
|
||
| def test_separate_metadata_later(self): | ||
| @parameterized({ | ||
| '': ([], []), | ||
| 'use_fetch': (['-sUSE_FETCH'], ['--use-fetch']), | ||
| }) | ||
| def test_separate_metadata_later(self, args, packArgs): | ||
| # see issue #6654 - we need to handle separate-metadata both when we run before | ||
| # the main program, and when we are run later | ||
|
|
||
| create_file('data.dat', ' ') | ||
| self.run_process([FILE_PACKAGER, 'more.data', '--preload', 'data.dat', '--separate-metadata', '--js-output=more.js']) | ||
| self.btest(Path('browser/separate_metadata_later.cpp'), '1', args=['-sFORCE_FILESYSTEM']) | ||
| self.run_process([FILE_PACKAGER, 'more.data', '--preload', 'data.dat', '--separate-metadata', '--js-output=more.js'] + packArgs) | ||
| self.btest(Path('browser/separate_metadata_later.cpp'), '1', args=['-sFORCE_FILESYSTEM'] + args) | ||
|
|
||
| def test_idbstore(self): | ||
| secret = str(time.time()) | ||
|
|
@@ -2329,7 +2340,11 @@ def test_openal_capture_sanity(self): | |
| def test_openal_extensions(self): | ||
| self.btest_exit('openal_extensions.c') | ||
|
|
||
| def test_runtimelink(self): | ||
| @parameterized({ | ||
| '': ([],), | ||
| 'use_fetch': (['-sUSE_FETCH'],) | ||
| }) | ||
| def test_runtimelink(self, args): | ||
| create_file('header.h', r''' | ||
| struct point { | ||
| int x, y; | ||
|
|
@@ -2376,7 +2391,7 @@ def test_runtimelink(self): | |
| } | ||
| ''') | ||
| self.run_process([EMCC, 'supp.c', '-o', 'supp.wasm', '-sSIDE_MODULE', '-O2'] + self.get_emcc_args()) | ||
| self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'supp.wasm']) | ||
| self.btest_exit('main.c', args=['-sMAIN_MODULE=2', '-O2', 'supp.wasm'] + args) | ||
|
|
||
| @also_with_wasm2js | ||
| def test_pre_run_deps(self): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not call
onloadhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.arrayBuffer();returns a promise that resolves to a buffer, not a literal buffer.