emscripten-core / emscripten-core/emscripten
Embind fails to update the property of an object if the object is a property of another object
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Modifying the value of a C++ class instance property via Embind fails silently when this instance is the property of another class instance:
```C++
class A {
public:
int i = 42;
};
class B {
public:
A a;
};
EMSCRIPTEN_BINDINGS(test) {
using namespace emscripten;
class_("A").constructor().property("i", &A::i);
class_("B").constructor().property("a", &B::a);
}
void workingReferenceCFunction() {
B b;
b.a.i = 2;
printf("b.a.i = %d\n", b.a.i); // 2, correct
}
```
```javascript
function failingJavascriptTestFunction() {
const b = new test.B();
b.a.i = 2;
console.log("b.a.i = %d", b.a.i); // 42, wrong, should be 2, b.a.i was not modified
}
```
**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.18 (d5ca9bba6513763d5bdddbd0efff759332bd85d7)
clang version 16.0.0 (https://github.com/llvm/llvm-project 48129cf0ed5053ed3fdf4f928180635e84892614)
Target: wasm32-unknown-emscripten
Thread model: posix
**Full link command:**
em++ -sEXPORT_NAME=TestEmbind -sMODULARIZE=1 -sEXPORT_ES6=1 -lembind -o testEmbind.js --no-entry main.cpp
Contributor guide
Assessment
This issue has not been assessed yet.