emscripten-core / emscripten-core/emscripten
Passing an exception into ccall as string sends empty string
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Version of emscripten/emsdk: 3.1.20-git (from homebrew)
This is user-error, but feels like it should have been caught higher up (maybe in the string/stack alloc?), and should be a simple UX fix
I passed an exception into ccall;
```
const ReturnType = null;
const ArgTypes = ['number','string'];
const ArgValues = [Handle,Error];
try
{
Module.ccall('OnStreamingDownloadFinished',ReturnType,ArgTypes,ArgValues);
}
catch(e)
{...}
```
Didn't twig it wasn't a string for a while as chrome's debugger shows it as a string, the type convertor doesn't error, (and debugger even makes it look like a string), and it manages to allocate & copy a string (of length 1) because
`var len = (str.length << 2) + 1; -->`
`var len = (undefined << 2) + 1; == 1`
Feels to me like either
a) convertor should throw if object has no length property (or just isn't a string!) thereby forcing users to pass strings if they said they would
b) force the input value to be a string `str = `${str}` (so type takes precedent)

(Screenshot to highlight UX)
Contributor guide
Assessment
This issue has not been assessed yet.