emscripten-core / emscripten-core/emscripten

In ASYNCIFY=2 build mode function arguments come in as nulls

Open
#20,490 14 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

`a.cpp`

```c++
#include
struct options
{
int x;
};

extern "C" int navigator_gpu_request_adapter_sync(options *opts);

int main()
{
options opts = { 100 };
int adapter = navigator_gpu_request_adapter_sync(&opts);
EM_ASM(console.log(`Got adapter ${0}`), adapter);
}
```

`lib_a.js`
```js
mergeInto(LibraryManager.library, {
navigator_gpu_request_adapter_sync__sig: 'ip',
navigator_gpu_request_adapter_sync__async: true,
navigator_gpu_request_adapter_sync: function(opts) {
console.error(`navigator_gpu_request_adapter_sync: opts: ${opts}`);
if (!opts) throw 'opts cannot be null';
var promise = navigator.gpu.requestAdapter().then(a => { return 42; });
return Asyncify.handleAsync(() => {
return promise;
});
}
});
```

```
em++ a.cpp --js-library lib_a.js -sASYNCIFY=1 -sASYNCIFY_IMPORTS=['navigator_gpu_request_adapter_sync'] -o a.html
```
works as expected, but
```
em++ a.cpp --js-library lib_a.js -sASYNCIFY=2 -sASYNCIFY_IMPORTS=['navigator_gpu_request_adapter_sync'] -o a.html
```
doesn't, and instead raises the exception `opts cannot be null`.

Tested in Chrome Canary 120.0.6076.0 (Official Build) canary (64-bit) on Windows.

I find there's not much documentation on JSPI, but based on the test suite code, it looks like it should work by just replacing `-sASYNCIFY=1` with `-sASYNCIFY=2` (and adding the `__sig` directives)?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.