Project

General

Profile

Best way to pass binary data from C++ to Javascript + possible JSlot bug?

Added by Jason Ferrara almost 5 years ago

Two questions...

First, what is the proper/best way to pass binary data or strings from C to JavaScript? It appears that the arguments to Wt::JSlot::exec are interpreted a JavaScript expressions, so to pass binary data or complex strings you would have to do a bunch of string encoding and escaping on the C side using JavaScript rules. Is there are easier/simpler way?

Second, I'm having a problem passing additional arguments via JSlot::exec. If I do something like

mySlot.setJavaScript("function(object, event, a1) { console.log("length \" + a1.length); }\", 1);

and then

mySlot.exec("null","null","'hello'");

in the browser when then JavaScript function is called a1 is undefined. Looking at the JavaScript stack when the call happens, the Wt generated code for doing the call looks like...

(function() {Wt.p.response(--395190142);Wt.p.setServerPush(false);{{var o=null,e=null,a1='hello';Wt.sf1(o,e);}}})();

a1 is defined, but then not passed to the function. Is this a bug, or am I misunderstanding how this is supposed to work?

Thanks

- Jason