emscripten-core / emscripten-core/emscripten

Smart pointer has empty PTR and COUNT properties

Open
#18,498 6 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

Hi,

I have a problem with smart-pointer. When i pass it for a JS function, the PTR is undefined and COUNT is undefined.

image

The class that receive the smart-ptr is OK, but the method that receive a smart-ptr is wrong.

The bind code is:

```
EMSCRIPTEN_BINDINGS(xplpc_proxy_platform_proxy_callback)
{
em::class_("PlatformProxyCallback")
.constructor &&>()
.smart_ptr>("shared_ptr")
.function("call", &xplpc::proxy::PlatformProxyCallback::call);
}
```

File: https://github.com/xplpc/xplpc/blob/wasm-mapping/wasm/lib/src/bind.cpp#L33-L39

The javascript function is:

```
onRemoteProxyCallAsync: function (data: string, callback: XWebPlatformProxyCallback) {
console.log("[XWebPlatformProxy : onRemoteProxyCallAsync] This: ", this);
console.log("[XWebPlatformProxy : onRemoteProxyCallAsync] Callback: ", callback);
}
```

File: https://github.com/xplpc/xplpc/blob/wasm-mapping/wasm/sample/src/xplpc/proxy/platform-proxy.ts#L31-L33

The C++ code that call the JS function is:

```
void callProxyAsync(const std::string &data, std::shared_ptr callback)
{
// the count is 2
spdlog::info("[callProxyAsync 1] Callback Smart Ptr Count: {}", callback.use_count());

call("onRemoteProxyCallAsync", data, callback);

spdlog::info("[callProxyAsync 2]");
}
```

If need build my sample only need do this:

```
git clone https://github.com/xplpc/xplpc.git -b wasm-mapping
cd wasm-mapping
python3 xplpc.py wasm-build
```

Requirements: python3, cmake, emsdk, node-js, npm

What im doing wrong? Thanks.

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.