emscripten-core / emscripten-core/emscripten
Fragile code generated from IDL (functions preceding constructor are not exposed)
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I just noticed the following issue generating Javascript bindings from WebIDL
My initial code in the IDL file:
```
interface AdaptEnvironment {
[Const] DOMString getStderrContents();
void AdaptEnvironment();
void Initialize( boolean test_mode );
... [snip]
}
```
Code in the generated javascript then goes as follows:
```
// AdaptEnvironment
AdaptEnvironment.prototype['getStderrContents'] = AdaptEnvironment.prototype.getStderrContents = /** @suppress {undefinedVars, duplicate} */function() {
var self = this.ptr;
return UTF8ToString(_emscripten_bind_AdaptEnvironment_getStderrContents_0(self));
};;
/** @suppress {undefinedVars, duplicate} */function AdaptEnvironment() {
this.ptr = _emscripten_bind_AdaptEnvironment_AdaptEnvironment_0();
getCache(AdaptEnvironment)[this.ptr] = this;
};;
AdaptEnvironment.prototype = Object.create(WrapperObject.prototype);
AdaptEnvironment.prototype.constructor = AdaptEnvironment;
AdaptEnvironment.prototype.__class__ = AdaptEnvironment;
AdaptEnvironment.__cache__ = {};
Module['AdaptEnvironment'] = AdaptEnvironment;
```
As you can see, the prototype is trampled after the code that binds the constructor is generated, which causes the function getStderrContents to disappear off of the javascript interface. This can obviously be fixed by moving the function getStderrErrContents() down in the IDL code and putting it after the constructor definition. However, this is obviously a bug, and it took me hours to figure out why my functions were not being exposed.
Emsdk version i'm using:
```
$ em++ --version
emcc (Emscripten gcc/clang-like replacement) 1.39.5 (commit c08015164e861fba388648f1547e0cd8a46d768c)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```
Contributor guide
Assessment
This issue has not been assessed yet.