Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50672 views
1
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2
// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4
// Glue code between CodeMirror and Tern.
5
//
6
// Create a CodeMirror.TernServer to wrap an actual Tern server,
7
// register open documents (CodeMirror.Doc instances) with it, and
8
// call its methods to activate the assisting functions that Tern
9
// provides.
10
//
11
// Options supported (all optional):
12
// * defs: An array of JSON definition data structures.
13
// * plugins: An object mapping plugin names to configuration
14
// options.
15
// * getFile: A function(name, c) that can be used to access files in
16
// the project that haven't been loaded yet. Simply do c(null) to
17
// indicate that a file is not available.
18
// * fileFilter: A function(value, docName, doc) that will be applied
19
// to documents before passing them on to Tern.
20
// * switchToDoc: A function(name, doc) that should, when providing a
21
// multi-file view, switch the view or focus to the named file.
22
// * showError: A function(editor, message) that can be used to
23
// override the way errors are displayed.
24
// * completionTip: Customize the content in tooltips for completions.
25
// Is passed a single argument—the completion's data as returned by
26
// Tern—and may return a string, DOM node, or null to indicate that
27
// no tip should be shown. By default the docstring is shown.
28
// * typeTip: Like completionTip, but for the tooltips shown for type
29
// queries.
30
// * responseFilter: A function(doc, query, request, error, data) that
31
// will be applied to the Tern responses before treating them
32
//
33
//
34
// It is possible to run the Tern server in a web worker by specifying
35
// these additional options:
36
// * useWorker: Set to true to enable web worker mode. You'll probably
37
// want to feature detect the actual value you use here, for example
38
// !!window.Worker.
39
// * workerScript: The main script of the worker. Point this to
40
// wherever you are hosting worker.js from this directory.
41
// * workerDeps: An array of paths pointing (relative to workerScript)
42
// to the Acorn and Tern libraries and any Tern plugins you want to
43
// load. Or, if you minified those into a single script and included
44
// them in the workerScript, simply leave this undefined.
45
46
(function(mod) {
47
if (typeof exports == "object" && typeof module == "object") // CommonJS
48
mod(require("../../lib/codemirror"));
49
else if (typeof define == "function" && define.amd) // AMD
50
define(["../../lib/codemirror"], mod);
51
else // Plain browser env
52
mod(CodeMirror);
53
})(function(CodeMirror) {
54
"use strict";
55
// declare global: tern
56
57
CodeMirror.TernServer = function(options) {
58
var self = this;
59
this.options = options || {};
60
var plugins = this.options.plugins || (this.options.plugins = {});
61
if (!plugins.doc_comment) plugins.doc_comment = true;
62
if (this.options.useWorker) {
63
this.server = new WorkerServer(this);
64
} else {
65
this.server = new tern.Server({
66
getFile: function(name, c) { return getFile(self, name, c); },
67
async: true,
68
defs: this.options.defs || [],
69
plugins: plugins
70
});
71
}
72
this.docs = Object.create(null);
73
this.trackChange = function(doc, change) { trackChange(self, doc, change); };
74
75
this.cachedArgHints = null;
76
this.activeArgHints = null;
77
this.jumpStack = [];
78
79
this.getHint = function(cm, c) { return hint(self, cm, c); };
80
this.getHint.async = true;
81
};
82
83
CodeMirror.TernServer.prototype = {
84
addDoc: function(name, doc) {
85
var data = {doc: doc, name: name, changed: null};
86
this.server.addFile(name, docValue(this, data));
87
CodeMirror.on(doc, "change", this.trackChange);
88
return this.docs[name] = data;
89
},
90
91
delDoc: function(id) {
92
var found = resolveDoc(this, id);
93
if (!found) return;
94
CodeMirror.off(found.doc, "change", this.trackChange);
95
delete this.docs[found.name];
96
this.server.delFile(found.name);
97
},
98
99
hideDoc: function(id) {
100
closeArgHints(this);
101
var found = resolveDoc(this, id);
102
if (found && found.changed) sendDoc(this, found);
103
},
104
105
complete: function(cm) {
106
cm.showHint({hint: this.getHint});
107
},
108
109
showType: function(cm, pos, c) { showContextInfo(this, cm, pos, "type", c); },
110
111
showDocs: function(cm, pos, c) { showContextInfo(this, cm, pos, "documentation", c); },
112
113
updateArgHints: function(cm) { updateArgHints(this, cm); },
114
115
jumpToDef: function(cm) { jumpToDef(this, cm); },
116
117
jumpBack: function(cm) { jumpBack(this, cm); },
118
119
rename: function(cm) { rename(this, cm); },
120
121
selectName: function(cm) { selectName(this, cm); },
122
123
request: function (cm, query, c, pos) {
124
var self = this;
125
var doc = findDoc(this, cm.getDoc());
126
var request = buildRequest(this, doc, query, pos);
127
128
this.server.request(request, function (error, data) {
129
if (!error && self.options.responseFilter)
130
data = self.options.responseFilter(doc, query, request, error, data);
131
c(error, data);
132
});
133
}
134
};
135
136
var Pos = CodeMirror.Pos;
137
var cls = "CodeMirror-Tern-";
138
var bigDoc = 250;
139
140
function getFile(ts, name, c) {
141
var buf = ts.docs[name];
142
if (buf)
143
c(docValue(ts, buf));
144
else if (ts.options.getFile)
145
ts.options.getFile(name, c);
146
else
147
c(null);
148
}
149
150
function findDoc(ts, doc, name) {
151
for (var n in ts.docs) {
152
var cur = ts.docs[n];
153
if (cur.doc == doc) return cur;
154
}
155
if (!name) for (var i = 0;; ++i) {
156
n = "[doc" + (i || "") + "]";
157
if (!ts.docs[n]) { name = n; break; }
158
}
159
return ts.addDoc(name, doc);
160
}
161
162
function resolveDoc(ts, id) {
163
if (typeof id == "string") return ts.docs[id];
164
if (id instanceof CodeMirror) id = id.getDoc();
165
if (id instanceof CodeMirror.Doc) return findDoc(ts, id);
166
}
167
168
function trackChange(ts, doc, change) {
169
var data = findDoc(ts, doc);
170
171
var argHints = ts.cachedArgHints;
172
if (argHints && argHints.doc == doc && cmpPos(argHints.start, change.to) <= 0)
173
ts.cachedArgHints = null;
174
175
var changed = data.changed;
176
if (changed == null)
177
data.changed = changed = {from: change.from.line, to: change.from.line};
178
var end = change.from.line + (change.text.length - 1);
179
if (change.from.line < changed.to) changed.to = changed.to - (change.to.line - end);
180
if (end >= changed.to) changed.to = end + 1;
181
if (changed.from > change.from.line) changed.from = change.from.line;
182
183
if (doc.lineCount() > bigDoc && change.to - changed.from > 100) setTimeout(function() {
184
if (data.changed && data.changed.to - data.changed.from > 100) sendDoc(ts, data);
185
}, 200);
186
}
187
188
function sendDoc(ts, doc) {
189
ts.server.request({files: [{type: "full", name: doc.name, text: docValue(ts, doc)}]}, function(error) {
190
if (error) window.console.error(error);
191
else doc.changed = null;
192
});
193
}
194
195
// Completion
196
197
function hint(ts, cm, c) {
198
ts.request(cm, {type: "completions", types: true, docs: true, urls: true}, function(error, data) {
199
if (error) return showError(ts, cm, error);
200
var completions = [], after = "";
201
var from = data.start, to = data.end;
202
if (cm.getRange(Pos(from.line, from.ch - 2), from) == "[\"" &&
203
cm.getRange(to, Pos(to.line, to.ch + 2)) != "\"]")
204
after = "\"]";
205
206
for (var i = 0; i < data.completions.length; ++i) {
207
var completion = data.completions[i], className = typeToIcon(completion.type);
208
if (data.guess) className += " " + cls + "guess";
209
completions.push({text: completion.name + after,
210
displayText: completion.name,
211
className: className,
212
data: completion});
213
}
214
215
var obj = {from: from, to: to, list: completions};
216
var tooltip = null;
217
CodeMirror.on(obj, "close", function() { remove(tooltip); });
218
CodeMirror.on(obj, "update", function() { remove(tooltip); });
219
CodeMirror.on(obj, "select", function(cur, node) {
220
remove(tooltip);
221
var content = ts.options.completionTip ? ts.options.completionTip(cur.data) : cur.data.doc;
222
if (content) {
223
tooltip = makeTooltip(node.parentNode.getBoundingClientRect().right + window.pageXOffset,
224
node.getBoundingClientRect().top + window.pageYOffset, content);
225
tooltip.className += " " + cls + "hint-doc";
226
}
227
});
228
c(obj);
229
});
230
}
231
232
function typeToIcon(type) {
233
var suffix;
234
if (type == "?") suffix = "unknown";
235
else if (type == "number" || type == "string" || type == "bool") suffix = type;
236
else if (/^fn\(/.test(type)) suffix = "fn";
237
else if (/^\[/.test(type)) suffix = "array";
238
else suffix = "object";
239
return cls + "completion " + cls + "completion-" + suffix;
240
}
241
242
// Type queries
243
244
function showContextInfo(ts, cm, pos, queryName, c) {
245
ts.request(cm, queryName, function(error, data) {
246
if (error) return showError(ts, cm, error);
247
if (ts.options.typeTip) {
248
var tip = ts.options.typeTip(data);
249
} else {
250
var tip = elt("span", null, elt("strong", null, data.type || "not found"));
251
if (data.doc)
252
tip.appendChild(document.createTextNode(" — " + data.doc));
253
if (data.url) {
254
tip.appendChild(document.createTextNode(" "));
255
tip.appendChild(elt("a", null, "[docs]")).href = data.url;
256
}
257
}
258
tempTooltip(cm, tip);
259
if (c) c();
260
}, pos);
261
}
262
263
// Maintaining argument hints
264
265
function updateArgHints(ts, cm) {
266
closeArgHints(ts);
267
268
if (cm.somethingSelected()) return;
269
var state = cm.getTokenAt(cm.getCursor()).state;
270
var inner = CodeMirror.innerMode(cm.getMode(), state);
271
if (inner.mode.name != "javascript") return;
272
var lex = inner.state.lexical;
273
if (lex.info != "call") return;
274
275
var ch, argPos = lex.pos || 0, tabSize = cm.getOption("tabSize");
276
for (var line = cm.getCursor().line, e = Math.max(0, line - 9), found = false; line >= e; --line) {
277
var str = cm.getLine(line), extra = 0;
278
for (var pos = 0;;) {
279
var tab = str.indexOf("\t", pos);
280
if (tab == -1) break;
281
extra += tabSize - (tab + extra) % tabSize - 1;
282
pos = tab + 1;
283
}
284
ch = lex.column - extra;
285
if (str.charAt(ch) == "(") {found = true; break;}
286
}
287
if (!found) return;
288
289
var start = Pos(line, ch);
290
var cache = ts.cachedArgHints;
291
if (cache && cache.doc == cm.getDoc() && cmpPos(start, cache.start) == 0)
292
return showArgHints(ts, cm, argPos);
293
294
ts.request(cm, {type: "type", preferFunction: true, end: start}, function(error, data) {
295
if (error || !data.type || !(/^fn\(/).test(data.type)) return;
296
ts.cachedArgHints = {
297
start: pos,
298
type: parseFnType(data.type),
299
name: data.exprName || data.name || "fn",
300
guess: data.guess,
301
doc: cm.getDoc()
302
};
303
showArgHints(ts, cm, argPos);
304
});
305
}
306
307
function showArgHints(ts, cm, pos) {
308
closeArgHints(ts);
309
310
var cache = ts.cachedArgHints, tp = cache.type;
311
var tip = elt("span", cache.guess ? cls + "fhint-guess" : null,
312
elt("span", cls + "fname", cache.name), "(");
313
for (var i = 0; i < tp.args.length; ++i) {
314
if (i) tip.appendChild(document.createTextNode(", "));
315
var arg = tp.args[i];
316
tip.appendChild(elt("span", cls + "farg" + (i == pos ? " " + cls + "farg-current" : ""), arg.name || "?"));
317
if (arg.type != "?") {
318
tip.appendChild(document.createTextNode(":\u00a0"));
319
tip.appendChild(elt("span", cls + "type", arg.type));
320
}
321
}
322
tip.appendChild(document.createTextNode(tp.rettype ? ") ->\u00a0" : ")"));
323
if (tp.rettype) tip.appendChild(elt("span", cls + "type", tp.rettype));
324
var place = cm.cursorCoords(null, "page");
325
ts.activeArgHints = makeTooltip(place.right + 1, place.bottom, tip);
326
}
327
328
function parseFnType(text) {
329
var args = [], pos = 3;
330
331
function skipMatching(upto) {
332
var depth = 0, start = pos;
333
for (;;) {
334
var next = text.charAt(pos);
335
if (upto.test(next) && !depth) return text.slice(start, pos);
336
if (/[{\[\(]/.test(next)) ++depth;
337
else if (/[}\]\)]/.test(next)) --depth;
338
++pos;
339
}
340
}
341
342
// Parse arguments
343
if (text.charAt(pos) != ")") for (;;) {
344
var name = text.slice(pos).match(/^([^, \(\[\{]+): /);
345
if (name) {
346
pos += name[0].length;
347
name = name[1];
348
}
349
args.push({name: name, type: skipMatching(/[\),]/)});
350
if (text.charAt(pos) == ")") break;
351
pos += 2;
352
}
353
354
var rettype = text.slice(pos).match(/^\) -> (.*)$/);
355
356
return {args: args, rettype: rettype && rettype[1]};
357
}
358
359
// Moving to the definition of something
360
361
function jumpToDef(ts, cm) {
362
function inner(varName) {
363
var req = {type: "definition", variable: varName || null};
364
var doc = findDoc(ts, cm.getDoc());
365
ts.server.request(buildRequest(ts, doc, req), function(error, data) {
366
if (error) return showError(ts, cm, error);
367
if (!data.file && data.url) { window.open(data.url); return; }
368
369
if (data.file) {
370
var localDoc = ts.docs[data.file], found;
371
if (localDoc && (found = findContext(localDoc.doc, data))) {
372
ts.jumpStack.push({file: doc.name,
373
start: cm.getCursor("from"),
374
end: cm.getCursor("to")});
375
moveTo(ts, doc, localDoc, found.start, found.end);
376
return;
377
}
378
}
379
showError(ts, cm, "Could not find a definition.");
380
});
381
}
382
383
if (!atInterestingExpression(cm))
384
dialog(cm, "Jump to variable", function(name) { if (name) inner(name); });
385
else
386
inner();
387
}
388
389
function jumpBack(ts, cm) {
390
var pos = ts.jumpStack.pop(), doc = pos && ts.docs[pos.file];
391
if (!doc) return;
392
moveTo(ts, findDoc(ts, cm.getDoc()), doc, pos.start, pos.end);
393
}
394
395
function moveTo(ts, curDoc, doc, start, end) {
396
doc.doc.setSelection(start, end);
397
if (curDoc != doc && ts.options.switchToDoc) {
398
closeArgHints(ts);
399
ts.options.switchToDoc(doc.name, doc.doc);
400
}
401
}
402
403
// The {line,ch} representation of positions makes this rather awkward.
404
function findContext(doc, data) {
405
var before = data.context.slice(0, data.contextOffset).split("\n");
406
var startLine = data.start.line - (before.length - 1);
407
var start = Pos(startLine, (before.length == 1 ? data.start.ch : doc.getLine(startLine).length) - before[0].length);
408
409
var text = doc.getLine(startLine).slice(start.ch);
410
for (var cur = startLine + 1; cur < doc.lineCount() && text.length < data.context.length; ++cur)
411
text += "\n" + doc.getLine(cur);
412
if (text.slice(0, data.context.length) == data.context) return data;
413
414
var cursor = doc.getSearchCursor(data.context, 0, false);
415
var nearest, nearestDist = Infinity;
416
while (cursor.findNext()) {
417
var from = cursor.from(), dist = Math.abs(from.line - start.line) * 10000;
418
if (!dist) dist = Math.abs(from.ch - start.ch);
419
if (dist < nearestDist) { nearest = from; nearestDist = dist; }
420
}
421
if (!nearest) return null;
422
423
if (before.length == 1)
424
nearest.ch += before[0].length;
425
else
426
nearest = Pos(nearest.line + (before.length - 1), before[before.length - 1].length);
427
if (data.start.line == data.end.line)
428
var end = Pos(nearest.line, nearest.ch + (data.end.ch - data.start.ch));
429
else
430
var end = Pos(nearest.line + (data.end.line - data.start.line), data.end.ch);
431
return {start: nearest, end: end};
432
}
433
434
function atInterestingExpression(cm) {
435
var pos = cm.getCursor("end"), tok = cm.getTokenAt(pos);
436
if (tok.start < pos.ch && (tok.type == "comment" || tok.type == "string")) return false;
437
return /\w/.test(cm.getLine(pos.line).slice(Math.max(pos.ch - 1, 0), pos.ch + 1));
438
}
439
440
// Variable renaming
441
442
function rename(ts, cm) {
443
var token = cm.getTokenAt(cm.getCursor());
444
if (!/\w/.test(token.string)) return showError(ts, cm, "Not at a variable");
445
dialog(cm, "New name for " + token.string, function(newName) {
446
ts.request(cm, {type: "rename", newName: newName, fullDocs: true}, function(error, data) {
447
if (error) return showError(ts, cm, error);
448
applyChanges(ts, data.changes);
449
});
450
});
451
}
452
453
function selectName(ts, cm) {
454
var name = findDoc(ts, cm.doc).name;
455
ts.request(cm, {type: "refs"}, function(error, data) {
456
if (error) return showError(ts, cm, error);
457
var ranges = [], cur = 0;
458
for (var i = 0; i < data.refs.length; i++) {
459
var ref = data.refs[i];
460
if (ref.file == name) {
461
ranges.push({anchor: ref.start, head: ref.end});
462
if (cmpPos(cur, ref.start) >= 0 && cmpPos(cur, ref.end) <= 0)
463
cur = ranges.length - 1;
464
}
465
}
466
cm.setSelections(ranges, cur);
467
});
468
}
469
470
var nextChangeOrig = 0;
471
function applyChanges(ts, changes) {
472
var perFile = Object.create(null);
473
for (var i = 0; i < changes.length; ++i) {
474
var ch = changes[i];
475
(perFile[ch.file] || (perFile[ch.file] = [])).push(ch);
476
}
477
for (var file in perFile) {
478
var known = ts.docs[file], chs = perFile[file];;
479
if (!known) continue;
480
chs.sort(function(a, b) { return cmpPos(b.start, a.start); });
481
var origin = "*rename" + (++nextChangeOrig);
482
for (var i = 0; i < chs.length; ++i) {
483
var ch = chs[i];
484
known.doc.replaceRange(ch.text, ch.start, ch.end, origin);
485
}
486
}
487
}
488
489
// Generic request-building helper
490
491
function buildRequest(ts, doc, query, pos) {
492
var files = [], offsetLines = 0, allowFragments = !query.fullDocs;
493
if (!allowFragments) delete query.fullDocs;
494
if (typeof query == "string") query = {type: query};
495
query.lineCharPositions = true;
496
if (query.end == null) {
497
query.end = pos || doc.doc.getCursor("end");
498
if (doc.doc.somethingSelected())
499
query.start = doc.doc.getCursor("start");
500
}
501
var startPos = query.start || query.end;
502
503
if (doc.changed) {
504
if (doc.doc.lineCount() > bigDoc && allowFragments !== false &&
505
doc.changed.to - doc.changed.from < 100 &&
506
doc.changed.from <= startPos.line && doc.changed.to > query.end.line) {
507
files.push(getFragmentAround(doc, startPos, query.end));
508
query.file = "#0";
509
var offsetLines = files[0].offsetLines;
510
if (query.start != null) query.start = Pos(query.start.line - -offsetLines, query.start.ch);
511
query.end = Pos(query.end.line - offsetLines, query.end.ch);
512
} else {
513
files.push({type: "full",
514
name: doc.name,
515
text: docValue(ts, doc)});
516
query.file = doc.name;
517
doc.changed = null;
518
}
519
} else {
520
query.file = doc.name;
521
}
522
for (var name in ts.docs) {
523
var cur = ts.docs[name];
524
if (cur.changed && cur != doc) {
525
files.push({type: "full", name: cur.name, text: docValue(ts, cur)});
526
cur.changed = null;
527
}
528
}
529
530
return {query: query, files: files};
531
}
532
533
function getFragmentAround(data, start, end) {
534
var doc = data.doc;
535
var minIndent = null, minLine = null, endLine, tabSize = 4;
536
for (var p = start.line - 1, min = Math.max(0, p - 50); p >= min; --p) {
537
var line = doc.getLine(p), fn = line.search(/\bfunction\b/);
538
if (fn < 0) continue;
539
var indent = CodeMirror.countColumn(line, null, tabSize);
540
if (minIndent != null && minIndent <= indent) continue;
541
minIndent = indent;
542
minLine = p;
543
}
544
if (minLine == null) minLine = min;
545
var max = Math.min(doc.lastLine(), end.line + 20);
546
if (minIndent == null || minIndent == CodeMirror.countColumn(doc.getLine(start.line), null, tabSize))
547
endLine = max;
548
else for (endLine = end.line + 1; endLine < max; ++endLine) {
549
var indent = CodeMirror.countColumn(doc.getLine(endLine), null, tabSize);
550
if (indent <= minIndent) break;
551
}
552
var from = Pos(minLine, 0);
553
554
return {type: "part",
555
name: data.name,
556
offsetLines: from.line,
557
text: doc.getRange(from, Pos(endLine, 0))};
558
}
559
560
// Generic utilities
561
562
var cmpPos = CodeMirror.cmpPos;
563
564
function elt(tagname, cls /*, ... elts*/) {
565
var e = document.createElement(tagname);
566
if (cls) e.className = cls;
567
for (var i = 2; i < arguments.length; ++i) {
568
var elt = arguments[i];
569
if (typeof elt == "string") elt = document.createTextNode(elt);
570
e.appendChild(elt);
571
}
572
return e;
573
}
574
575
function dialog(cm, text, f) {
576
if (cm.openDialog)
577
cm.openDialog(text + ": <input type=text>", f);
578
else
579
f(prompt(text, ""));
580
}
581
582
// Tooltips
583
584
function tempTooltip(cm, content) {
585
var where = cm.cursorCoords();
586
var tip = makeTooltip(where.right + 1, where.bottom, content);
587
function clear() {
588
if (!tip.parentNode) return;
589
cm.off("cursorActivity", clear);
590
fadeOut(tip);
591
}
592
setTimeout(clear, 1700);
593
cm.on("cursorActivity", clear);
594
}
595
596
function makeTooltip(x, y, content) {
597
var node = elt("div", cls + "tooltip", content);
598
node.style.left = x + "px";
599
node.style.top = y + "px";
600
document.body.appendChild(node);
601
return node;
602
}
603
604
function remove(node) {
605
var p = node && node.parentNode;
606
if (p) p.removeChild(node);
607
}
608
609
function fadeOut(tooltip) {
610
tooltip.style.opacity = "0";
611
setTimeout(function() { remove(tooltip); }, 1100);
612
}
613
614
function showError(ts, cm, msg) {
615
if (ts.options.showError)
616
ts.options.showError(cm, msg);
617
else
618
tempTooltip(cm, String(msg));
619
}
620
621
function closeArgHints(ts) {
622
if (ts.activeArgHints) { remove(ts.activeArgHints); ts.activeArgHints = null; }
623
}
624
625
function docValue(ts, doc) {
626
var val = doc.doc.getValue();
627
if (ts.options.fileFilter) val = ts.options.fileFilter(val, doc.name, doc.doc);
628
return val;
629
}
630
631
// Worker wrapper
632
633
function WorkerServer(ts) {
634
var worker = new Worker(ts.options.workerScript);
635
worker.postMessage({type: "init",
636
defs: ts.options.defs,
637
plugins: ts.options.plugins,
638
scripts: ts.options.workerDeps});
639
var msgId = 0, pending = {};
640
641
function send(data, c) {
642
if (c) {
643
data.id = ++msgId;
644
pending[msgId] = c;
645
}
646
worker.postMessage(data);
647
}
648
worker.onmessage = function(e) {
649
var data = e.data;
650
if (data.type == "getFile") {
651
getFile(ts, data.name, function(err, text) {
652
send({type: "getFile", err: String(err), text: text, id: data.id});
653
});
654
} else if (data.type == "debug") {
655
window.console.log(data.message);
656
} else if (data.id && pending[data.id]) {
657
pending[data.id](data.err, data.body);
658
delete pending[data.id];
659
}
660
};
661
worker.onerror = function(e) {
662
for (var id in pending) pending[id](e);
663
pending = {};
664
};
665
666
this.addFile = function(name, text) { send({type: "add", name: name, text: text}); };
667
this.delFile = function(name) { send({type: "del", name: name}); };
668
this.request = function(body, c) { send({type: "req", body: body}, c); };
669
}
670
});
671
672