Promise exception is not pass to .catch method.



  • Hi, guys,

    I'm using QJSEngine in my product to run JS codes for some automation purpose on Qt 5.12.1. And there are some codes that leverages the Promise object provided by QJSEngine. And I got some strange result there.
    Here is my testing code:

    new Promise(function (resolve, reject) { resolve("OK")})
        .then(function(){JSON.parse("")});
    

    This above snippet code runs by QJSEngine::evaluate() method.
    The result I got is: [object Promise]
    The expected result should be: SyntaxError: JSON.parse: Parse error

    And when you run above code second time, you will get the error.
    But this is wrong. I want the first time run, it returns me the error message, not second time.

    If you run above code in chrome console, then it returns correct result.

    Also if you add a .catch (function(e) {console.log("JSON parse error.")}); at then end of above testing code to make it chained at the end of the promise. it will also not print the log message.

    Does anyone know what happened in the QJSEngine?