Grammalecte  Check-in [51a209f202]

Overview
Comment:[core][fx] gc engine in a dedicated worker
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: 51a209f202acedcd09aedfcc5f6edf28351cb51b81963921285a4b1605c55fbb
User & Date: olr on 2017-08-04 08:18:42
Other Links: branch diff | manifest | tags
Context
2017-08-04
15:41
[fx][core] initialization in gce_worker.js check-in: 1f4195c966 user: olr tags: fx, webext2
08:18
[core][fx] gc engine in a dedicated worker check-in: 51a209f202 user: olr tags: fx, webext2
06:32
[core][js][py] nextWord and previousWord: only necessary groups + bug fix for JS check-in: 30b40b6153 user: olr tags: core, webext2
Changes

Added gc_lang/fr/webext/background.js version [67f47c2618].

            1  +// Background 
            2  +
            3  +"use strict";
            4  +
            5  +let xGCEWorker = new Worker("gce_worker.js");
            6  +
            7  +function handleMessage (oRequest, xSender, sendResponse) {
            8  +  console.log(`[background] received: ${oRequest.content}`);
            9  +  sendResponse({response: "response from background script"});
           10  +}
           11  +
           12  +browser.runtime.onMessage.addListener(handleMessage);

Modified gc_lang/fr/webext/gce_worker.js from [172934d86f] to [ea3f39a7e2].

     1      1   /*
     2         -    WARNING.
            2  +    WORKER:
            3  +    https://developer.mozilla.org/en-US/docs/Web/API/Worker
            4  +    https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope
            5  +
     3      6   
     4      7       JavaScript still sucks.
     5      8       No module available in WebExtension at the moment! :(
     6      9       No require, no import/export.
           10  +
           11  +    In Worker, we have importScripts() which imports everything in this scope.
     7     12   
     8     13       In order to use the same base of code with XUL-addon for Thunderbird and SDK-addon for Firefox,
     9     14       all modules have been “objectified”. And while they are still imported via “require”
    10     15       in the previous extensions, they are loaded as background scripts in WebExtension sharing
    11     16       the same memory space (it seems)…
    12     17   
    13     18       When JavaScript become a modern language, “deobjectify” the modules…
................................................................................
    18     23       — Edge 15 – behind the Experimental JavaScript Features setting in about:flags.
    19     24   
    20     25       https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
    21     26       https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export
    22     27   */
    23     28   
    24     29   
           30  +console.log("GC Engine Worker [start]");
           31  +console.log(self);
    25     32   
           33  +importScripts("grammalecte/helpers.js");
           34  +importScripts("grammalecte/str_transform.js");
           35  +importScripts("grammalecte/ibdawg.js");
           36  +importScripts("grammalecte/text.js");
           37  +importScripts("grammalecte/tokenizer.js");
           38  +importScripts("grammalecte/fr/conj.js");
           39  +importScripts("grammalecte/fr/mfsp.js");
           40  +importScripts("grammalecte/fr/phonet.js");
           41  +importScripts("grammalecte/fr/cregex.js");
           42  +importScripts("grammalecte/fr/gc_options.js");
           43  +importScripts("grammalecte/fr/gc_rules.js");
           44  +importScripts("grammalecte/fr/gc_engine.js");
           45  +importScripts("grammalecte/tests.js");
           46  +
           47  +
           48  +
           49  +helpers.echo("helpers echo");
    26     50   
    27     51   let oTokenizer = null;
    28     52   let oLxg = null;
    29     53   
    30     54   function loadGrammarChecker (sGCOptions="", sContext="JavaScript") {
    31     55       if (gc_engine === null) {
    32     56           try {
................................................................................
   119    143       catch (e) {
   120    144           helpers.logerror(e);
   121    145       }
   122    146       return JSON.stringify([]);
   123    147   }
   124    148   
   125    149   
   126         -function handleMessage (oRequest, xSender, sendResponse) {
   127         -  console.log(`[background] received: ${oRequest.content}`);
   128         -  sendResponse({response: "response from background script"});
   129         -}
   130         -
   131         -browser.runtime.onMessage.addListener(handleMessage);
   132         -
   133    150   helpers.echo("START");
   134    151   
   135    152   helpers.echo(conj.getConj("devenir", ":E", ":2s"));
   136    153   
   137    154   helpers.echo(mfsp.getMasForm("emmerdeuse", true));
   138    155   helpers.echo(mfsp.getMasForm("pointilleuse", false));
   139    156   
................................................................................
   143    160   helpers.echo(oDict.getMorph("merde"));
   144    161   
   145    162   gc_engine.load("JavaScript");
   146    163   let aRes = gc_engine.parse("Je suit...");
   147    164   for (let oErr of aRes) {
   148    165       helpers.echo(text.getReadableError(oErr));
   149    166   }
          167  +
   150    168   
   151    169   //fullTests();
          170  +
          171  +

Modified gc_lang/fr/webext/manifest.json from [dc30bec757] to [49413af971].

    26     26       "default_icon": "img/logo-32.png",
    27     27       "default_popup": "panel/main.html",
    28     28       "default_title": "Grammalecte [fr]",
    29     29       "browser_style": false
    30     30     },
    31     31     "background": {
    32     32       "scripts": [
    33         -      "grammalecte/helpers.js",
    34         -      "grammalecte/str_transform.js",
    35         -      "grammalecte/ibdawg.js",
    36         -      "grammalecte/text.js",
    37         -      "grammalecte/tokenizer.js",
    38         -      "grammalecte/fr/conj.js",
    39         -      "grammalecte/fr/mfsp.js",
    40         -      "grammalecte/fr/phonet.js",
    41         -      "grammalecte/fr/cregex.js",
    42         -      "grammalecte/fr/gc_options.js",
    43         -      "grammalecte/fr/gc_rules.js",
    44         -      "grammalecte/fr/gc_engine.js",
    45         -      "grammalecte/tests.js",
    46         -      "gce_worker.js"
           33  +      "background.js"
    47     34       ]
    48     35     },
    49     36     "web_accessible_resources": [
    50     37       "grammalecte/_dictionaries/French.json",
    51     38       "grammalecte/fr/conj_data.json",
    52     39       "grammalecte/fr/mfsp_data.json",
    53     40       "grammalecte/fr/phonet_data.json",
    54     41       "grammalecte/fr/tests_data.json"
    55     42     ],
    56     43     "permissions": [
    57     44       "activeTab"
    58     45     ]
    59     46   }