1
 Follower
4
 Likes

Make sure _osjs.js isn't using globals

Frontend
New

This was a fun hard-to-trace issue with OutSystems fighting a Forge component we were trying to use :)

The example here is that OsExecuteTableRecordOperation has this for loop:

The issue here is that the i should be prefixed by a var or a let. If it is not, then if any JavaScript runs during the OsRefreshElement(...) code that happens to also have forgotten to put a var or a let in front of their i value - somewhat more likely with i, given its popularity as an index variable, it will overwrite the value of i OutSystems is using.

Usually, of course, it's harmless. In this case, it turned into a fun endless loop as soon as the number of rows exceeded what the component was doing in its own loop :)

If you want a way to expose this particular issue, just throw a const i = 999 (or whatever your favourite value is) at the top of _osjs.js and see what happens :)

Created on 23 Oct 2018
Comments (2)

Changed the category to Frontend


Never mind the const i = 999 test - you can't put constants on the global window object.

I wonder if this would work to catch it:

Object.defineProperty(window, 'i', {
    get: function() {
        debugger;
        return window._i;
    },
    set: function(value) {
        debugger;
        window._i = value;
    }
});

EDIT: Looks like this actually work to catch things - it found a spot using global i in OsValidatorCleanValidations as well:

function OsValidatorCleanValidations(a) {
    for (i = 0; i < OsPage_Validators.length; i++)
        OsValidatorCleanValidation(OsPage_Validators[i], a)
}

views
290
Followers
1