Skip to content

Commit b5f9697

Browse files
authored
Simplify test_async_compile. NFC (#24047)
No need to custom shell code, we can perhaps this test just using `--pre-js`.
1 parent 9004180 commit b5f9697

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

test/browser/test_async_compile.c

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
int main() {
1313
printf("hello, world!\n");
14-
int result = EM_ASM_INT({
15-
return Module.sawAsyncCompilation | 0;
16-
});
14+
int result = EM_ASM_INT(return Module.sawAsyncCompilation);
1715
printf("sawAsyncCompilation => %d\n", result);
1816
return result;
1917
}

test/test_browser.py

+9-17
Original file line numberDiff line numberDiff line change
@@ -4197,39 +4197,31 @@ def test_vanilla_html_when_proxying(self, args):
41974197
})
41984198
def test_async_compile(self, opts, returncode):
41994199
# notice when we use async compilation
4200-
script = '''
4201-
<script>
4200+
create_file('pre.js', '''
42024201
// note if we do async compilation
42034202
var real_wasm_instantiate = WebAssembly.instantiate;
42044203
var real_wasm_instantiateStreaming = WebAssembly.instantiateStreaming;
42054204
if (typeof real_wasm_instantiateStreaming === 'function') {
42064205
WebAssembly.instantiateStreaming = (a, b) => {
4206+
err('instantiateStreaming called');
42074207
console.log('instantiateStreaming called');
42084208
Module.sawAsyncCompilation = true;
42094209
return real_wasm_instantiateStreaming(a, b);
42104210
};
42114211
} else {
42124212
WebAssembly.instantiate = (a, b) => {
4213-
console.log('instantiate called');
4213+
err('instantiate called');
42144214
Module.sawAsyncCompilation = true;
42154215
return real_wasm_instantiate(a, b);
42164216
};
42174217
}
4218-
// show stderr for the viewer's fun
4219-
err = (x) => {
4220-
out('<<< ' + x + ' >>>');
4221-
console.log(x);
4222-
};
4223-
</script>
4224-
{{{ SCRIPT }}}
4225-
'''
4226-
shell_with_script('shell.html', 'shell.html', script)
4227-
common_args = ['--shell-file', 'shell.html']
4228-
self.btest_exit('test_async_compile.c', assert_returncode=returncode, emcc_args=common_args + opts)
4218+
''')
4219+
self.emcc_args.append('--pre-js=pre.js')
4220+
self.btest_exit('test_async_compile.c', assert_returncode=returncode, emcc_args=opts)
42294221
# Ensure that compilation still works and is async without instantiateStreaming available
4230-
no_streaming = '<script>WebAssembly.instantiateStreaming = undefined;</script>'
4231-
shell_with_script('shell.html', 'shell.html', no_streaming + script)
4232-
self.btest_exit('test_async_compile.c', assert_returncode=1, emcc_args=common_args)
4222+
create_file('pre0.js', 'WebAssembly.instantiateStreaming = undefined;')
4223+
self.emcc_args.insert(0, '--pre-js=pre0.js')
4224+
self.btest_exit('test_async_compile.c', assert_returncode=1)
42334225

42344226
# Test that implementing Module.instantiateWasm() callback works.
42354227
@also_with_asan

0 commit comments

Comments
 (0)