Grammalecte  Check-in [a5d2fe7405]

Overview
Comment:[core][js] helpers as object
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core | webext
Files: files | file ages | folders
SHA3-256: a5d2fe7405fc3181fbe5adff283d87ce113ff5a219a2360acee8e0e7aa4e4192
User & Date: olr on 2017-07-29 09:13:30
Other Links: branch diff | manifest | tags
Context
2017-07-29
09:25
[core][js] str_transform as object check-in: 856cdd76cb user: olr tags: core, webext
09:13
[core][js] helpers as object check-in: a5d2fe7405 user: olr tags: core, webext
08:06
[core][js] test if <exports> exists check-in: c55ae247e7 user: olr tags: core, webext
Changes

Modified gc_core/js/helpers.js from [da0905c944] to [df207a3682].

     1      1   
     2      2   // HELPERS
     3      3   
     4      4   "use strict";
     5      5   
     6         -// In Firefox, there is no console.log in PromiseWorker, but there is worker.log.
     7         -// In Thunderbird, you can’t access to console directly. So it’s required to pass a log function.
     8         -let funcOutput = null;
            6  +const helpers = {
            7  +    // In Firefox, there is no console.log in PromiseWorker, but there is worker.log.
            8  +    // In Thunderbird, you can’t access to console directly. So it’s required to pass a log function.
            9  +    _funcOutput: null,
           10  +
           11  +    setLogOutput: function (func) {
           12  +        this._funcOutput = func;
           13  +    },
           14  +
           15  +    echo: function (obj) {
           16  +        if (this._funcOutput !== null) {
           17  +            this._funcOutput(obj);
           18  +        } else {
           19  +            console.log(obj);
           20  +        }
           21  +        return true;
           22  +    },
     9     23   
    10         -function setLogOutput (func) {
    11         -    funcOutput = func;
    12         -}
           24  +    logerror: function (e, bStack=false) {
           25  +        let sMsg = "\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message;
           26  +        if (bStack) {
           27  +            sMsg += "\n--- Stack ---\n" + e.stack;
           28  +        }
           29  +        if (this._funcOutput !== null) {
           30  +            this._funcOutput(sMsg);
           31  +        } else {
           32  +            console.error(sMsg);
           33  +        }
           34  +    },
    13     35   
    14         -function echo (obj) {
    15         -    if (funcOutput !== null) {
    16         -        funcOutput(obj);
    17         -    } else {
    18         -        console.log(obj);
    19         -    }
    20         -    return true;
    21         -}
           36  +    inspect: function (o) {
           37  +        let sMsg = "__inspect__: " + typeof o;
           38  +        for (let sParam in o) {
           39  +            sMsg += "\n" + sParam + ": " + o.sParam;
           40  +        }
           41  +        sMsg += "\n" + JSON.stringify(o) + "\n__end__";
           42  +        this.echo(sMsg);
           43  +    },
    22     44   
    23         -function logerror (e, bStack=false) {
    24         -    let sMsg = "\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message;
    25         -    if (bStack) {
    26         -        sMsg += "\n--- Stack ---\n" + e.stack;
    27         -    }
    28         -    if (funcOutput !== null) {
    29         -        funcOutput(sMsg);
    30         -    } else {
    31         -        console.error(sMsg);
    32         -    }
    33         -}
           45  +    loadFile: function (spf) {
           46  +        // load ressources in workers (suggested by Mozilla extensions reviewers)
           47  +        // for more options have a look here: https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed
           48  +        // if not in workers, use sdk/data.load() instead
           49  +        try {
           50  +            let xRequest;
           51  +            if (typeof XMLHttpRequest !== "undefined") {
           52  +                xRequest = new XMLHttpRequest();
           53  +            }
           54  +            else {
           55  +                // JS bullshit again… necessary for Thunderbird
           56  +                let { Cc, Ci } = require("chrome");
           57  +                xRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
           58  +                xRequest.QueryInterface(Ci.nsIXMLHttpRequest);
           59  +            }
           60  +            xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
           61  +            xRequest.send();
           62  +            return xRequest.responseText;
           63  +        }
           64  +        catch (e) {
           65  +            this.logerror(e);
           66  +            return null
           67  +        }
           68  +    },
    34     69   
    35         -function inspect (o) {
    36         -    let sMsg = "__inspect__: " + typeof o;
    37         -    for (let sParam in o) {
    38         -        sMsg += "\n" + sParam + ": " + o.sParam;
    39         -    }
    40         -    sMsg += "\n" + JSON.stringify(o) + "\n__end__";
    41         -    echo(sMsg);
    42         -}
           70  +    objectToMap: function (obj) {
           71  +        let m = new Map();
           72  +        for (let param in obj) {
           73  +            //console.log(param + " " + obj[param]);
           74  +            m.set(param, obj[param]);
           75  +        }
           76  +        return m;
           77  +    },
    43     78   
    44         -
    45         -// load ressources in workers (suggested by Mozilla extensions reviewers)
    46         -// for more options have a look here: https://gist.github.com/Noitidart/ec1e6b9a593ec7e3efed
    47         -// if not in workers, use sdk/data.load() instead
    48         -function loadFile (spf) {
    49         -    try {
    50         -        let xRequest;
    51         -        if (typeof XMLHttpRequest !== "undefined") {
    52         -            xRequest = new XMLHttpRequest();
           79  +    mapToObject: function (m) {
           80  +        let obj = {};
           81  +        for (let [k, v] of m) {
           82  +            obj[k] = v;
    53     83           }
    54         -        else {
    55         -            // JS bullshit again… necessary for Thunderbird
    56         -            let { Cc, Ci } = require("chrome");
    57         -            xRequest = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance();
    58         -            xRequest.QueryInterface(Ci.nsIXMLHttpRequest);
    59         -        }
    60         -        xRequest.open('GET', spf, false); // 3rd arg is false for synchronous, sync is acceptable in workers
    61         -        xRequest.send();
    62         -        return xRequest.responseText;
    63         -    }
    64         -    catch (e) {
    65         -        logerror(e);
    66         -        return null
           84  +        return obj;
    67     85       }
    68     86   }
    69     87   
    70         -
    71         -// conversions
    72         -function objectToMap (obj) {
    73         -    let m = new Map();
    74         -    for (let param in obj) {
    75         -        //console.log(param + " " + obj[param]);
    76         -        m.set(param, obj[param]);
    77         -    }
    78         -    return m;
    79         -}
    80         -
    81         -function mapToObject (m) {
    82         -    let obj = {};
    83         -    for (let [k, v] of m) {
    84         -        obj[k] = v;
    85         -    }
    86         -    return obj;
    87         -}
    88         -
    89     88   
    90     89   if (typeof(exports) !== 'undefined') {
    91         -    exports.setLogOutput = setLogOutput;
    92         -    exports.echo = echo;
    93         -    exports.logerror = logerror;
    94         -    exports.inspect = inspect;
    95         -    exports.loadFile = loadFile;
    96         -    exports.objectToMap = objectToMap;
    97         -    exports.mapToObject = mapToObject;
           90  +    exports.setLogOutput = helpers.setLogOutput;
           91  +    exports.echo = helpers.echo;
           92  +    exports.logerror = helpers.logerror;
           93  +    exports.inspect = helpers.inspect;
           94  +    exports.loadFile = helpers.loadFile;
           95  +    exports.objectToMap = helpers.objectToMap;
           96  +    exports.mapToObject = helpers.mapToObject;
    98     97   }

Modified gc_lang/fr/webext/gce_worker.js from [8fda2777a3] to [99453ec31a].

    10     10       });
    11     11       console.log("AFTER");
    12     12   }
    13     13   catch (e) {
    14     14       console.log("\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
    15     15       console.error(e);
    16     16   }*/
    17         -
    18         -echo("VA TE FAIRE FOUTRE");
    19         -
    20     17   
    21     18   
    22     19   let gce = null; // module: grammar checker engine
    23     20   let text = null;
    24     21   let tkz = null; // module: tokenizer
    25     22   let lxg = null; // module: lexicographer
    26     23   let helpers = null;