PHP Classes

File: FrontEndScripts/libs/codemirror/addon/tern/worker.js

Recommend this page to a friend!
  Classes of Aleksey Nemiro  >  PHP Small Server Administrator  >  FrontEndScripts/libs/codemirror/addon/tern/worker.js  >  Download  
File: FrontEndScripts/libs/codemirror/addon/tern/worker.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Small Server Administrator
Web panel for small Debian and Ubuntu servers
Author: By
Last change:
Date: 6 years ago
Size: 1,208 bytes


Class file image Download
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license:

// declare global: tern, server

var server;

this.onmessage = function(e) {
  var data =;
  switch (data.type) {
  case "init": return startServer(data.defs, data.plugins, data.scripts);
  case "add": return server.addFile(, data.text);
  case "del": return server.delFile(;
  case "req": return server.request(data.body, function(err, reqData) {
    postMessage({id:, body: reqData, err: err && String(err)});
  case "getFile":
    var c = pending[];
    delete pending[];
    return c(data.err, data.text);
  default: throw new Error("Unknown message type: " + data.type);

var nextId = 0, pending = {};
function getFile(file, c) {
  postMessage({type: "getFile", name: file, id: ++nextId});
  pending[nextId] = c;

function startServer(defs, plugins, scripts) {
  if (scripts) importScripts.apply(null, scripts);

  server = new tern.Server({
    getFile: getFile,
    async: true,
    defs: defs,
    plugins: plugins

this.console = {
  log: function(v) { postMessage({type: "debug", message: v}); }
For more information send a message to info at phpclasses dot org.