Giter VIP home page Giter VIP logo

js-bind's People

Contributors

daminetreg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

js-bind's Issues

Error When bind function with 0 args.

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.

image

image

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)"}

Memory management

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.