Skip to content

Commit fcfc013

Browse files
authored
Fix emrun_file_dump() to work in multithreaded builds. (#26698)
1 parent 9bc2797 commit fcfc013

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/emrun_postjs.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ if (globalThis.window && (typeof ENVIRONMENT_IS_PTHREAD == 'undefined' || !ENVIR
8686
var http = new XMLHttpRequest();
8787
out(`Dumping out file "${filename}" with ${data.length} bytes of data.`);
8888
http.open("POST", "stdio.html?file=" + filename, true);
89-
http.send(data); // XXX this does not work in workers, for some odd reason (issue #2681)
89+
if (ArrayBuffer.isView(data) && typeof SharedArrayBuffer !== "undefined" && data.buffer instanceof SharedArrayBuffer) {
90+
data = new data.constructor(data); // Make a clone of the typed array of the same type, since http.send() does not allow SharedArrayBuffer backing.
91+
}
92+
http.send(data);
9093
};
9194

9295
if (globalThis.document) {

test/test_browser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5754,6 +5754,7 @@ def test_program_arg_separator(self):
57545754
self.assertContained('error: unrecognized arguments: --foo', err)
57555755
self.assertContained('remember to add `--` between arguments', err)
57565756

5757+
@also_with_threads
57575758
def test_emrun(self):
57585759
self.emcc('test_emrun.c', ['--emrun', '-o', 'test_emrun.html'])
57595760
if not has_browser():

0 commit comments

Comments
 (0)