Grammalecte  Check-in [4124e27218]

Overview
Comment:[fx][bug] JS sucks: don’t store Map object in storage
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 4124e272180a7b81f0b73add05c045ccd802138b30f8f8ecbf97390dfbfac5f1
User & Date: olr on 2018-03-07 15:23:55
Other Links: manifest | tags
Context
2018-03-07
16:01
[fx] new version for WebExtension check-in: 23d108bf86 user: olr tags: trunk, fx
15:23
[fx][bug] JS sucks: don’t store Map object in storage check-in: 4124e27218 user: olr tags: trunk, fx
13:57
[fx] main panel: better functions name check-in: 07d0ec19f5 user: olr tags: trunk, fx
Changes

Modified gc_lang/fr/webext/background.js from [b1af0b858f] to [716a2f0752].

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

97
98
99
100
101
102
103
104
105
106
107
108
109
54
55
56
57
58
59
60



61
62
63
64
65
66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

94
95
96




97
98
99
100
101
102
103







-
-
-














-
-
+
+
+
















-
+


-
-
-
-







                browser.runtime.sendMessage(e.data);
                break;
            case "getOptions":
            case "getDefaultOptions":
            case "resetOptions":
                // send result to panel
                storeGCOptions(result);
                if (bChrome) {
                    e.data.result = helpers.mapToObject(e.data.result);
                }
                browser.runtime.sendMessage(e.data);
                break;
            case "setOptions":
            case "setOption":
                storeGCOptions(result);
                break;
            case "setDictionary":
                console.log("[background] " + sActionDone + ": " + result);
                break;
            default:
                console.log("[background] Unknown command: " + sActionDone);
                console.log(e.data);
        }
    }
    catch (e) {
        showError(e);
    catch (error) {
        showError(error);
        console.log(e.data);
    }
};

function initUIOptions (dSavedOptions) {
    if (!dSavedOptions.hasOwnProperty("ui_options")) {
        browser.storage.local.set({"ui_options": {
            textarea: true,
            editablenode: true
        }});
    }
}

function initGrammarChecker (dSavedOptions) {
    try {
        let dOptions = (dSavedOptions.hasOwnProperty("gc_options")) ? dSavedOptions.gc_options : null;
        if (dOptions !== null && Object.getOwnPropertyNames(dOptions).length == 0) {
            console.log("# Error: the saved options was an empty object");
            console.log("# Error: the saved options was an empty object.");
            dOptions = null;
        }
        if (bChrome) {
            // JS crap again. Chrome can’t store Map object.
            dOptions = helpers.objectToMap(dOptions);
        }
        xGCEWorker.postMessage({
            sCommand: "init",
            dParam: {sExtensionPath: browser.extension.getURL(""), dOptions: dOptions, sContext: "Firefox"},
            dInfo: {}
        });
    }
    catch (e) {
323
324
325
326
327
328
329
330

331
332
333
334
335
336
337
338
317
318
319
320
321
322
323

324

325
326
327
328
329
330
331







-
+
-









/*
    Actions
*/

function storeGCOptions (dOptions) {
    if (bChrome) {
    if (dOptions instanceof Map) {
        // JS crap again. Chrome can’t store Map object.
        dOptions = helpers.mapToObject(dOptions);
    }
    browser.storage.local.set({"gc_options": dOptions});
}

function sendCommandToTab (sCommand, iTab) {
    let xTabPort = dConnx.get(iTab);

Modified gc_lang/fr/webext/gce_worker.js from [0220235f9e] to [42760d524d].

167
168
169
170
171
172
173



174
175
176
177
178
179
180
181

182

183
184
185
186
187
188
189
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

186
187
188
189
190
191
192
193







+
+
+








+
-
+







            gc_engine.load(sContext, sExtensionPath+"grammalecte/graphspell/_dictionaries");
            oSpellChecker = gc_engine.getSpellChecker();
            oTest = new TestGrammarChecking(gc_engine, sExtensionPath+"/grammalecte/fr/tests_data.json");
            oTokenizer = new Tokenizer("fr");
            oLocution =  helpers.loadFile(sExtensionPath + "/grammalecte/fr/locutions_data.json");
            oLxg = new Lexicographe(oSpellChecker, oTokenizer, oLocution);
            if (dOptions !== null) {
                if (!(dOptions instanceof Map)) {
                    dOptions = helpers.objectToMap(dOptions);
                }
                gc_engine.setOptions(dOptions);
            }
            //tests();
            bInitDone = true;
        } else {
            console.log("[Worker] Already initialized…")
        }
        // we always retrieve options from the gc_engine, for setOptions filters obsolete options
        dOptions = helpers.mapToObject(gc_engine.getOptions());
        postMessage(createResponse("init", gc_engine.getOptions(), dInfo, true));
        postMessage(createResponse("init", dOptions, dInfo, true));
    }
    catch (e) {
        helpers.logerror(e);
        postMessage(createResponse("init", createErrorResult(e, "init failed"), dInfo, true, true));
    }
}

213
214
215
216
217
218
219

220

221
222
223

224

225
226
227



228

229

230
231
232
233
234
235

236

237
238
239
240
241

242

243
244
245
246
247
248
249
217
218
219
220
221
222
223
224

225
226
227
228
229

230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246

247
248
249
250
251
252
253

254
255
256
257
258
259
260
261







+
-
+



+
-
+



+
+
+

+
-
+






+
-
+





+
-
+







    sParagraph = sParagraph.replace(/­/g, "").normalize("NFC");
    let aGrammErr = gc_engine.parse(sParagraph, sCountry, bDebug, bContext);
    let aSpellErr = oSpellChecker.parseParagraph(sParagraph);
    postMessage(createResponse("parseAndSpellcheck1", {sParagraph: sParagraph, aGrammErr: aGrammErr, aSpellErr: aSpellErr}, dInfo, true));
}

function getOptions (dInfo={}) {
    let dOptions = helpers.mapToObject(gc_engine.getOptions());
    postMessage(createResponse("getOptions", gc_engine.getOptions(), dInfo, true));
    postMessage(createResponse("getOptions", dOptions, dInfo, true));
}

function getDefaultOptions (dInfo={}) {
    let dOptions = helpers.mapToObject(gc_engine.getDefaultOptions());
    postMessage(createResponse("getDefaultOptions", gc_engine.getDefaultOptions(), dInfo, true));
    postMessage(createResponse("getDefaultOptions", dOptions, dInfo, true));
}

function setOptions (dOptions, dInfo={}) {
    if (!(dOptions instanceof Map)) {
        dOptions = helpers.objectToMap(dOptions);
    }
    gc_engine.setOptions(dOptions);
    dOptions = helpers.mapToObject(gc_engine.getOptions());
    postMessage(createResponse("setOptions", gc_engine.getOptions(), dInfo, true));
    postMessage(createResponse("setOptions", dOptions, dInfo, true));
}

function setOption (sOptName, bValue, dInfo={}) {
    console.log(sOptName+": "+bValue);
    if (sOptName) {
        gc_engine.setOption(sOptName, bValue);
        let dOptions = helpers.mapToObject(gc_engine.getOptions());
        postMessage(createResponse("setOption", gc_engine.getOptions(), dInfo, true));
        postMessage(createResponse("setOption", dOptions, dInfo, true));
    }
}

function resetOptions (dInfo={}) {
    gc_engine.resetOptions();
    let dOptions = helpers.mapToObject(gc_engine.getOptions());
    postMessage(createResponse("resetOptions", gc_engine.getOptions(), dInfo, true));
    postMessage(createResponse("resetOptions", dOptions, dInfo, true));
}

function tests () {
    console.log(conj.getConj("devenir", ":E", ":2s"));
    console.log(mfsp.getMasForm("emmerdeuse", true));
    console.log(mfsp.getMasForm("pointilleuse", false));
    console.log(phonet.getSimil("est"));

Modified gc_lang/fr/webext/panel/main.js from [3a6b7ee35a] to [c3e1902233].

207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223



224
225
226
227
228
229

230
231
207
208
209
210
211
212
213

214
215








216
217
218
219
220
221
222
223

224
225
226







-
+

-
-
-
-
-
-
-
-
+
+
+





-
+



function _displayGCOptions (dSavedOptions) {
    if (dSavedOptions.hasOwnProperty("gc_options")) {
        displayGCOptions(dSavedOptions.gc_options);
    }
}

function displayGCOptions (dOptions) {
function displayGCOptions (oOptions) {
    try {
        // dOptions is supposed to be a Map
        if (bChrome) {
            // JS crap again. Chrome can’t store/send Map object.
            dOptions = helpers.objectToMap(dOptions);
        }
        for (let [sOpt, bVal] of dOptions) {
            if (document.getElementById("option_"+sOpt)) {
                document.getElementById("option_"+sOpt).checked = bVal;
        for (let sParam in oOptions) {
            if (document.getElementById("option_"+sParam)) {
                document.getElementById("option_"+sParam).checked = oOptions[sParam];
            }
        }
    }
    catch (e) {
        showError(e);
        console.log(dOptions);
        console.log(oOptions);
    }
}