daminetreg / js-bind Goto Github PK
View Code? Open in Web Editor NEWjs::bind makes any C++ function, member function or lambda as a Javascript callback.
License: Boost Software License 1.0
js::bind makes any C++ function, member function or lambda as a Javascript callback.
License: Boost Software License 1.0
Hello.
I convert LoadScript function from Js to C++, set events onload and onerror all ok , but I get following error when onload event is launched.
Summary: Script is loaded but when onload is executed get error.
C++ Function
emscripten::val LoadScript(emscripten::val scriptpath)
{
using namespace emscripten;
String hash = scriptpath.as<String>();
if(!val::global("VMain")["Loaded"][hash].isUndefined())
{
auto promiseCallback = [&](val resolve, val reject){
resolve(hash);
};
return val::global("Promise").new_(js::bind(promiseCallback, std::placeholders::_1, std::placeholders::_2));
}
auto promiseCallback = [&](val resolve, val reject) -> void{
resolve();
val script = val::global("document").call<val>("createElement", val("script"));
auto onloadCallback = [&]() -> void{ //NOT EXECUTED - check errors
emscripten_console_log("On load");
resolve(hash);
};
script.set("onload", js::bind(onloadCallback)); //No errors here
auto onerrorCallback = [&]() -> void{ //NOT EXECUTED - check errors
emscripten_console_log("On error");
reject(hash);
};
script.set("onerror", js::bind(onerrorCallback)); //No errors here
script.set("src",scriptpath);
script.set("type", val("text/javascript"));
val::global("VMain")["Loaded"].set(hash, val(true));
val::global("document")["body"].call<val>("appendChild", script);
};
return val::global("window")["Promise"].new_(js::bind(promiseCallback, std::placeholders::_1, std::placeholders::_2));
}
Original JS Code.
window.VMain = {};
window.VMain.Loaded = [];
window.VMain.LoadScript = function (scriptPath) {
if (window.VMain.Loaded[scriptPath]) {
return new this.Promise(function (resolve, reject) {
resolve();
});
}
return new Promise(function (resolve, reject) {
var script = document.createElement("script");
script.src = scriptPath;
script.type = "text/javascript";
window.VMain.Loaded[scriptPath] = true;
script.onload = function () {
resolve(scriptPath);
};
script.onerror = function () {
reject(scriptPath);
};
document["body"].appendChild(script);
});
};
Thanks for your help.
EXTRAS
Full error text
VModule.js:9 Uncaught BindingError {name: "BindingError", message: "function void0ArgsFunctor.opcall called with 1 arguments, expected 0 args!", stack: "BindingError: function void0ArgsFunctor.opcall cal…alhost:8082/VModule.js:9:95572), <anonymous>:5:1)"}
throwBindingError @ VModule.js:9
void0ArgsFunctor$opcall @ VM1906:5
load (asincrónico)
__emval_set_property @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_viii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_viii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
Module.dynCall_viiii @ VModule.js:9
dynCall_viiii_36 @ VM1759:4
void2ArgsFunctor$opcall @ VM1916:10
emval_allocator_1 @ VM1979:7
__emval_new @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_iiiii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_vii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
dynCall_iii_17 @ VM1744:4
Property @ VM1912:8
eval @ VM1976:3
_emscripten_run_script @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
Module._main @ VModule.js:9
callMain @ VModule.js:9
doRun @ VModule.js:9
run @ VModule.js:9
runCaller @ VModule.js:9
removeRunDependency @ VModule.js:9
receiveInstance @ VModule.js:9
receiveInstantiatedSource @ VModule.js:9
Promise.then (asincrónico)
(anónimo) @ VModule.js:9
Promise.then (asincrónico)
instantiateAsync @ VModule.js:9
createWasm @ VModule.js:9
(anónimo) @ VModule.js:9
(anónimo) @ Instance.js:1
Mostrar 14 fotogramas más del código de biblioteca
VModule.js:9 Uncaught BindingError {name: "BindingError", message: "function void0ArgsFunctor.opcall called with 1 arguments, expected 0 args!", stack: "BindingError: function void0ArgsFunctor.opcall cal…alhost:8082/VModule.js:9:95572), <anonymous>:5:1)"}message: "function void0ArgsFunctor.opcall called with 1 arguments, expected 0 args!"name: "BindingError"stack: "BindingError: function void0ArgsFunctor.opcall called with 1 arguments, expected 0 args!↵ at BindingError.<anonymous> (http://localhost:8082/VModule.js:9:75971)↵ at new BindingError (eval at createNamedFunction (http://localhost:8082/VModule.js:9:75680), <anonymous>:4:34)↵ at throwBindingError (http://localhost:8082/VModule.js:9:76412)↵ at void0ArgsFunctor$opcall [as opcall] (eval at new_ (http://localhost:8082/VModule.js:9:95572), <anonymous>:5:1)"__proto__: Errorconstructor: ƒ BindingError()arguments: (...)caller: (...)length: 0name: "BindingError"prototype: Error {constructor: ƒ, toString: ƒ}__proto__: ƒ ()[[FunctionLocation]]: VM1735:3[[Scopes]]: Scopes[2]toString: ƒ ()arguments: nullcaller: nulllength: 0name: ""prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: VModule.js:9[[Scopes]]: Scopes[4]__proto__: constructor: ƒ Error()message: ""name: "Error"toString: ƒ toString()arguments: (...)caller: (...)length: 0name: "toString"__proto__: ƒ ()[[Scopes]]: Scopes[0]__proto__: Object
throwBindingError @ VModule.js:9
void0ArgsFunctor$opcall @ VM1906:5
load (asincrónico)
__emval_set_property @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_viii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_viii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
Module.dynCall_viiii @ VModule.js:9
dynCall_viiii_36 @ VM1759:4
void2ArgsFunctor$opcall @ VM1916:10
emval_allocator_1 @ VM1979:7
__emval_new @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_iiiii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
invoke_vii @ VModule.js:9
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
dynCall_iii_17 @ VM1744:4
Property @ VM1912:8
eval @ VM1976:8
Promise.then (asincrónico)
eval @ VM1976:7
_emscripten_run_script @ VModule.js:9
(anónimo) @ VModule.wasm:1
ret.<computed> @ VModule.js:9
Module._main @ VModule.js:9
callMain @ VModule.js:9
doRun @ VModule.js:9
run @ VModule.js:9
runCaller @ VModule.js:9
removeRunDependency @ VModule.js:9
receiveInstance @ VModule.js:9
receiveInstantiatedSource @ VModule.js:9
Promise.then (asincrónico)
(anónimo) @ VModule.js:9
Promise.then (asincrónico)
instantiateAsync @ VModule.js:9
createWasm @ VModule.js:9
(anónimo) @ VModule.js:9
(anónimo) @ Instance.js:1
VModule.js:9 Uncaught BindingError {name: "BindingError", message: "function void0ArgsFunctor.opcall called with 1 arguments, expected 0 args!", stack: "BindingError: function void0ArgsFunctor.opcall cal…alhost:8082/VModule.js:9:95572), <anonymous>:5:1)"}
What is the memory management approach of this library? Are the C++ callbacks freed? Can I free them explicitly? This is important because they might be holding onto e. g. heavyweight objects through capture.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.