Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions taking userdata and registered via bind() never complete in the JS script? #923

Open
g40 opened this issue Mar 22, 2023 · 0 comments

Comments

@g40
Copy link

g40 commented Mar 22, 2023

Another question re binding (slightly different to #922)

TL;DR. C++ functions registered via bind() with userdata can be called from Javascript, but the promise they return never completes.

Any thoughts? MTIA.

Much more detail:

2 different C++ functions are registered using bind().

// C++
// 1st variety
// sync appears to work in both directions, so JS -> C++ -> JS
std::string callout1(const std::string& arg)
{
	std::string ret = std::string("{ \"status\": true }");
	std::printf("%s => %s\n", arg.c_str(), ret.c_str());
	// JSON status message
	return ret;
}

// 3rd variety
std::string callout3(const std::string& arg, const std::string& arg2, void* data)
{
	webview::webview* pwv = reinterpret_cast<webview::webview*>(data);
	std::string ret = std::string("{ \"status\": true }");
	std::printf("%s %s (%p) => %s\n", arg.c_str(), arg2.c_str(), pwv, ret.c_str());
	// JSON status message
	return ret;
}

// both get invoked, but the 2nd form never completes in the .JS script
w.bind("callout1", callout1);
w.bind("callout3", callout3, userdata);

Log detail from the console (Edge on Windows 10 21H2). The line annoted with *** => shows success

callit called  callout1 ƒ () {
        var seq = RPC.nextSeq++;
        var promise = new Promise(function(resolve, reject) {
          RPC[seq] = {
            resolve: resolve,
            reject: reject,
          };
ret =>  Promise {<pending>}

*** => index.html:36 success:  {status: true}

callit  called  callout3 ƒ () {
        var seq = RPC.nextSeq++;
        var promise = new Promise(function(resolve, reject) {
          RPC[seq] = {
            resolve: resolve,
            reject: reject,
          };
ret =>  Promise {<pending>}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant