emscripten-core / emscripten-core/emscripten
Bug in generated C++ wrapper for overriding C++ classes in JS when using WebIDL_Binder
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hello,
Noticed a potential bug in webidl_binder. When generating the glue code for two abstract classes and returning a `const char *` (`[Const] DOMString` in WebIDL ) variable, the glue code treats it as an `int` - return type and doesn't type cast it to a `char *` , which leads to a compilation error. Below is a small example to illustrate the issue
Files provided:
`Foo.h` - provides struct definitions for Foo and Bar, the two abstract structs used.
`Full.idl` - WebIDL Interfaces of Foo and Bar
`Glue.cpp, Glue.js` - files generated by the WebIDL Binder (using emcc version 2.0.21)
`Wrapper.cpp` - a Wrapper file needed for the compilation step
Commands used:
```
- tools/webidl_binder Full.idl Glue
- emcc Wrapper.cpp --post-js Glue.js -o EMCCOutput.js
```
The error is:
cannot initialize return object of type '`char *`' with an rvalue of type '`int`' , and refers to this piece of code in Glue.cpp:
```
char* getString() const {
return EM_ASM_INT({
var self = Module['getCache'](Module['JSFoo'])[$0];
if (!self.hasOwnProperty('getString')) throw 'a JSImplementation must implement all functions, you forgot JSFoo::getString.';
return self['getString']();
}, (int)this);
}
```
As you can see, the return type is an integer that is not being type cast into a char pointer, causing a compilation error.
Contributor guide
Assessment
This issue has not been assessed yet.