Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ jobs:
browser64.test_pthread_*
browser64.test_wget_*
browser64.test_emscripten_async_wget_*
browser64.test_wasm_worker_*
"
test-browser-firefox:
executor: bionic
Expand Down
7 changes: 5 additions & 2 deletions src/library_wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
* SPDX-License-Identifier: MIT
*/

#if WASM_WORKERS == 2
// Helpers for _wasmWorkerBlobUrl used in WASM_WORKERS == 2 mode
{{{
global.captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
global.instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
global.instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);r(n,d[`wasm`]);return n.exports};';
global.instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need .exports here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The r argument to instantiateWasm which is the recieveInstance function takes the exports and can optionally wrap them, afterwhich it return the new exports object.

Without this change the workers we never seeing the wrapped exports.

null;
}}}
#endif

#if WASM_WORKERS

Expand Down Expand Up @@ -262,7 +265,7 @@ if (ENVIRONMENT_IS_WASM_WORKER) {
emscripten_lock_async_acquire: (lock, asyncWaitFinished, userData, maxWaitMilliseconds) => {
let dispatch = (val, ret) => {
setTimeout(() => {
{{{ makeDynCall('viiii', 'asyncWaitFinished') }}}(lock, val, /*waitResult=*/ret, userData);
{{{ makeDynCall('vpiip', 'asyncWaitFinished') }}}(lock, val, /*waitResult=*/ret, userData);
}, 0);
};
let tryAcquireLock = () => {
Expand Down
24 changes: 22 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def also_with_wasm2js(f):
def metafunc(self, with_wasm2js):
assert self.get_setting('WASM') is None
if with_wasm2js:
if self.is_wasm64():
self.skipTest('wasm2js is not compatible with MEMORY64')
self.require_wasm2js()
self.set_setting('WASM', 0)
f(self)
else:
Expand Down Expand Up @@ -166,6 +165,7 @@ def is_jspi(args):
def no_swiftshader(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
if is_chrome() and '--use-gl=swiftshader' in EMTEST_BROWSER:
self.skipTest('not compatible with swiftshader')
Expand All @@ -177,6 +177,7 @@ def decorated(self, *args, **kwargs):
def requires_threads(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
if os.environ.get('EMTEST_LACKS_THREAD_SUPPORT'):
self.skipTest('EMTEST_LACKS_THREAD_SUPPORT is set')
Expand All @@ -185,14 +186,28 @@ def decorated(self, *args, **kwargs):
return decorated


def requires_wasm2js(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
self.require_wasm2js()
return f(self, *args, **kwargs)

return decorated


def also_with_threads(f):
assert callable(f)

@wraps(f)
def decorated(self, *args, **kwargs):
f(self, *args, **kwargs)
if not os.environ.get('EMTEST_LACKS_THREAD_SUPPORT'):
print('(threads)')
self.emcc_args += ['-pthread']
f(self, *args, **kwargs)

return decorated


Expand Down Expand Up @@ -223,6 +238,10 @@ def require_wasm64(self):
# All the browsers we run on support wasm64 (Chrome and Firefox).
return True

def require_wasm2js(self):
if self.is_wasm64():
self.skipTest('wasm2js is not compatible with MEMORY64')

def require_jspi(self):
if not is_chrome():
self.skipTest(f'Current browser ({EMTEST_BROWSER}) does not support JSPI. Only chromium-based browsers ({CHROMIUM_BASED_BROWSERS}) support JSPI today.')
Expand Down Expand Up @@ -5218,6 +5237,7 @@ def test_wasm_worker_hello_minimal_runtime_2(self):
self.btest('wasm_worker/hello_wasm_worker.c', expected='0', args=['-sWASM_WORKERS', '-sMINIMAL_RUNTIME=2'])

# Tests Wasm Workers build in Wasm2JS mode.
@requires_wasm2js
@also_with_minimal_runtime
def test_wasm_worker_hello_wasm2js(self):
self.btest('wasm_worker/hello_wasm_worker.c', expected='0', args=['-sWASM_WORKERS', '-sWASM=0'])
Expand Down
6 changes: 5 additions & 1 deletion test/wasm_worker/lock_async_acquire.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ void schedule_work(void *userData)
}
}

void start_worker(int arg) {
schedule_work(0);
}

int main()
{
#define NUM_THREADS 10
for(int i = 0; i < NUM_THREADS; ++i)
{
emscripten_wasm_worker_t worker = emscripten_malloc_wasm_worker(1024);
emscripten_wasm_worker_post_function_vi(worker, (void (*)(int))schedule_work, 0);
emscripten_wasm_worker_post_function_vi(worker, start_worker, 0);
}

schedule_work(0);
Expand Down
2 changes: 1 addition & 1 deletion test/wasm_worker/no_proxied_js_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int should_throw(void(*func)())
}
console.error('Function was expected to throw, but did not!');
return 0;
}, (int)func);
}, func);
return threw;
}

Expand Down
2 changes: 1 addition & 1 deletion test/wasm_worker/terminate_all_wasm_workers.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int should_throw(void(*func)(emscripten_wasm_worker_t worker), emscripten_wasm_w
}
console.error('Function was expected to throw, but did not!');
return 0;
}, (int)func, worker);
}, func, worker);
return threw;
}

Expand Down
4 changes: 2 additions & 2 deletions test/wasm_worker/terminate_wasm_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ int should_throw(void(*func)())
{
int threw = EM_ASM_INT({
try {
dynCall('v', $0);
dynCall('v', Number($0));
} catch(e) {
console.error('Threw an exception like expected: ' + e);
return 1;
}
console.error('Function was expected to throw, but did not!');
return 0;
}, (int)func);
}, func);
return threw;
}

Expand Down