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