rename host.js to worker.js

This commit is contained in:
Fabian Jakobs 2011-01-27 20:05:05 +01:00
commit ed763c17bd
3 changed files with 5 additions and 5 deletions

View file

@ -91,7 +91,7 @@ copy({
{
root: aceHome + '/lib',
include: /.*\.js$/,
exclude: /tests?\/|theme\/|mode\/|ace\/worker\/host\.js/
exclude: /tests?\/|theme\/|mode\/|ace\/worker\/worker\.js/
},
{ base: aceHome + '/lib/', path: 'ace/theme/textmate.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/text.js' },
@ -148,11 +148,11 @@ copy({
// Create worker bootstrap code
copy({
source: "lib/ace/worker/host.js",
source: "lib/ace/worker/worker.js",
filter: [function(data) {
return data + "\nimportScripts('ace-uncompressed.js')";
}],
dest: 'build/host.js'
dest: 'build/worker.js'
});

106
lib/ace/worker/worker.js Normal file
View file

@ -0,0 +1,106 @@
var console = {
log: function(msg) {
postMessage({type: "log", data: msg});
}
};
var window = {
console: console
};
var require = function(id) {
var module = require.modules[id];
if (module) {
if (!module.initialized) {
module.exports = module.factory().exports;
module.initialized = true;
}
return module.exports;
}
var chunks = id.split("/");
chunks[0] = require.tlns[chunks[0]] || chunks[0];
path = require.baseUrl + "/" + chunks.join("/") + ".js"
require.id = id;
importScripts(path);
return require(id);
};
require.modules = {};
require.tlns = {};
require.baseUrl;
var define = function(id, factory) {
if (!factory) {
factory = id;
id = require.id;
}
if (id.indexOf("text!") == 0)
return;
require.modules[id] = {
factory: function() {
var module = {
exports: {}
};
var returnExports = factory(require, module.exports, module);
if (returnExports)
module.exports = exports;
return module;
}
};
};
function initBaseUrls(baseUrl, topLevelNamespaces) {
require.baseUrl = baseUrl;
require.tlns = topLevelNamespaces;
}
function initSender() {
var EventEmitter = require("pilot/event_emitter").EventEmitter;
var oop = require("pilot/oop");
var Sender = function() {};
(function() {
oop.implement(this, EventEmitter);
this.callback = function(data, callbackId) {
postMessage({
type: "call",
id: callbackId,
data: data
});
},
this.emit = function(name, data) {
postMessage({
type: "event",
name: name,
data: data
});
}
}).call(Sender.prototype);
return new Sender();
}
var main;
var sender;
onmessage = function(e) {
var msg = e.data;
if (msg.command)
main[msg.command].apply(main, msg.args);
else if (msg.init) {
initBaseUrls(msg.base, msg.tlns);
require("pilot/fixoldbrowsers");
sender = initSender();
var clazz = require(msg.module)[msg.classname];
main = new clazz(sender);
} else if (msg.event) {
sender._dispatchEvent(msg.event, msg.data);
}
};

View file

@ -16,10 +16,10 @@ var WorkerClient = function(baseUrl, topLevelNamespaces, module, classname) {
this.callbacks = [];
if (require.packaged) {
var worker = this.$worker = new Worker("host.js");
var worker = this.$worker = new Worker("worker.js");
}
else {
var workerUrl = require.nameToUrl("ace/worker/host", null, "_");
var workerUrl = require.nameToUrl("ace/worker/worker", null, "_");
var worker = this.$worker = new Worker(workerUrl);
var tlns = {};