jaxon-php / jaxon-js

The Jaxon javascript library https://www.jaxon-php.org.
BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

Error signaling from executed js #3

Closed feuzeu closed 7 years ago

feuzeu commented 7 years ago

From @esteban-turnocheck on March 30, 2017 15:7

Hi! When you use the script method of the response object to execute js code on the client, if the code fails, the behaviour might be unpredictable and, more dangerously, the client never finds out (as opposed to regular js code which shows in the console). This is the eval function which runs the script

jaxon.js.execute = function(args) {
    args.fullName = 'execute Javascript';
    var returnValue = true;
    args.context = args.context ? args.context : {};
    args.context.jaxonDelegateCall = function() {
            eval(args.data);
    };
    args.context.jaxonDelegateCall();
    return returnValue;
}

That eval function, in such a case, throws an exception. But


        try {
            if (false == jaxon.executeCommand(obj)) 
                return false;
        } catch (
        }

Here, it is silently discarding it. This...

        try {
            if (false == jaxon.executeCommand(obj)) 
                return false;
        } catch (e) {
            alert(e);
        }

...would do. (or maybe console.log(e)) Of course, there might be better approaches (callbacks to some parameterized function o even to php?), but it would not hide potential errors in response->script() code. If you patch your code about it, please let me know to load the jaxon.core.js back from the cdn (now i'm using local copy with said patch) Thanks!!

Copied from original issue: jaxon-php/jaxon-core#14

feuzeu commented 7 years ago

I've submitted the new release to jsDeliver. I'll post an update when it will be deployed to the CDN.

feuzeu commented 7 years ago

The new version (1.2.0) is available on the jsDelivr CDN: https://www.jsdelivr.com/projects/jaxon. Don't use the 1.0.1 and 1.1.0 versions, they have missing files due to an error while updating the repo.