Grammalecte  Check-in [51af80e942]

Overview
Comment:[core] [js] avoid avoid functions overriding in common objects prototypes
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | core
Files: files | file ages | folders
SHA3-256: 51af80e9429d234c73a79e11c9b9c0768f7870797abbec3f20bfefdce8c64343
User & Date: olr on 2017-04-28 15:00:22
Original Comment: [js] avoid avoid functions overriding in common objects prototypes
Other Links: manifest | tags
Context
2017-04-30
12:23
[fr] confusion son / sont check-in: c6acd80ef5 user: olr tags: fr, trunk
2017-04-28
15:00
[core] [js] avoid avoid functions overriding in common objects prototypes check-in: 51af80e942 user: olr tags: core, trunk
2017-04-27
11:24
[fr] faux positif: si nécessaire check-in: b32cdfdbe2 user: olr tags: fr, trunk
Changes

Modified gc_core/js/jsex_map.js from [975706110f] to [181b814a6e].

1
2
3

4
5
6
7
8
9
10
..
37
38
39
40
41
42
43




// Map


Map.prototype._shallowCopy = function () {
    let oNewMap = new Map();
    for (let [key, val] of this.entries()) {
        oNewMap.set(key, val);
    }
    return oNewMap;
}
................................................................................
Map.prototype._updateOnlyExistingKeys = function (dDict) {
    for (let [k, v] of dDict.entries()) {
        if (this.has(k)){
            this.set(k, v);
        }
    }
}






>







 







>
>
>
1
2
3
4
5
6
7
8
9
10
11
..
38
39
40
41
42
43
44
45
46
47

// Map

if (Map.prototype.__grammalecte__ === undefined) {
    Map.prototype._shallowCopy = function () {
        let oNewMap = new Map();
        for (let [key, val] of this.entries()) {
            oNewMap.set(key, val);
        }
        return oNewMap;
    }
................................................................................
    Map.prototype._updateOnlyExistingKeys = function (dDict) {
        for (let [k, v] of dDict.entries()) {
            if (this.has(k)){
                this.set(k, v);
            }
        }
    }

    Map.prototype.__grammalecte__ = true;
}

Modified gc_core/js/jsex_regex.js from [35ff67872c] to [de380ed036].

1
2
3

4
5
6
7
8
9
10
..
70
71
72
73
74
75
76




// regex


RegExp.prototype._exec2 = function (sText, aGroupsPos, aNegLookBefore=null) {
    let m;
    while ((m = this.exec(sText)) !== null) {
        // we have to iterate over sText here too
        // because first match doesn’t imply it’s a valid match according to negative lookbefore assertions,
        // and even if first match is finally invalid, it doesn’t mean the following eligible matchs would be invalid too.
        if (aNegLookBefore !== null) {
................................................................................
                m.start.push(iPos);
                m.end.push(iPos + subm.length);
            }
        }
    }
    return m;
}






>







 







>
>
>
1
2
3
4
5
6
7
8
9
10
11
..
71
72
73
74
75
76
77
78
79
80

// regex

if (RegExp.prototype.__grammalecte__ === undefined) {
    RegExp.prototype._exec2 = function (sText, aGroupsPos, aNegLookBefore=null) {
        let m;
        while ((m = this.exec(sText)) !== null) {
            // we have to iterate over sText here too
            // because first match doesn’t imply it’s a valid match according to negative lookbefore assertions,
            // and even if first match is finally invalid, it doesn’t mean the following eligible matchs would be invalid too.
            if (aNegLookBefore !== null) {
................................................................................
                    m.start.push(iPos);
                    m.end.push(iPos + subm.length);
                }
            }
        }
        return m;
    }

    RegExp.prototype.__grammalecte__ = true;
}

Modified gc_core/js/jsex_string.js from [c771aa921e] to [adf06fbda5].

1
2
3

4
5
6
7
8
9
10
..
47
48
49
50
51
52
53




// String


String.prototype._count = function (sSearch, bOverlapping) {
    // http://jsperf.com/string-ocurrence-split-vs-match/8
    if (sSearch.length <= 0) {
        return this.length + 1;
    }
    let nOccur = 0;
    let iPos = 0;
................................................................................
    return this.replace(z, "");
}
String.prototype._trim = function (sChars) {
    let z1 = new RegExp("^["+sChars+"]+");
    let z2 = new RegExp("["+sChars+"]+$");
    return this.replace(z1, "").replace(z2, "");
}






>







 







>
>
>
1
2
3
4
5
6
7
8
9
10
11
..
48
49
50
51
52
53
54
55
56
57

// String

if (String.prototype.__grammalecte__ === undefined) {
    String.prototype._count = function (sSearch, bOverlapping) {
        // http://jsperf.com/string-ocurrence-split-vs-match/8
        if (sSearch.length <= 0) {
            return this.length + 1;
        }
        let nOccur = 0;
        let iPos = 0;
................................................................................
        return this.replace(z, "");
    }
    String.prototype._trim = function (sChars) {
        let z1 = new RegExp("^["+sChars+"]+");
        let z2 = new RegExp("["+sChars+"]+$");
        return this.replace(z1, "").replace(z2, "");
    }

    String.prototype.__grammalecte__ = true;
}