fix loading of worker files from UIWorkerClient

This commit is contained in:
nightwing 2013-02-13 23:49:48 +04:00
commit 36f9b537cc
2 changed files with 16 additions and 16 deletions

View file

@ -1,9 +1,10 @@
"no use strict";
;(function(window) {
if (typeof window.window != "undefined" && window.document) {
return;
}
if (typeof window != "undefined" && window.document)
throw "atempt to load ace worker into main window instead of webWorker";
var console = {
window.console = {
log: function() {
var msgs = Array.prototype.slice.call(arguments, 0);
postMessage({type: "log", data: msgs});
@ -13,11 +14,9 @@ var console = {
postMessage({type: "log", data: msgs});
}
};
var window = {
console: console
};
window.window = window;
var normalizeModule = function(parentId, moduleName) {
window.normalizeModule = function(parentId, moduleName) {
// normalize plugin requires
if (moduleName.indexOf("!") !== -1) {
var chunks = moduleName.split("!");
@ -37,7 +36,7 @@ var normalizeModule = function(parentId, moduleName) {
return moduleName;
};
var require = function(parentId, id) {
window.require = function(parentId, id) {
if (!id.charAt)
throw new Error("worker.js require() accepts only (parentId, id) as arguments");
@ -64,7 +63,7 @@ var require = function(parentId, id) {
require.modules = {};
require.tlns = {};
var define = function(id, deps, factory) {
window.define = function(id, deps, factory) {
if (arguments.length == 2) {
factory = deps;
if (typeof id != "string") {
@ -96,11 +95,11 @@ var define = function(id, deps, factory) {
};
};
function initBaseUrls(topLevelNamespaces) {
window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
require.tlns = topLevelNamespaces;
}
function initSender() {
window.initSender = function initSender() {
var EventEmitter = require(null, "ace/lib/event_emitter").EventEmitter;
var oop = require(null, "ace/lib/oop");
@ -132,10 +131,10 @@ function initSender() {
return new Sender();
}
var main;
var sender;
window.main = null;
window.sender = null;
onmessage = function(e) {
window.onmessage = function(e) {
var msg = e.data;
if (msg.command) {
if (main[msg.command])
@ -154,3 +153,4 @@ onmessage = function(e) {
sender._emit(msg.event, msg.data);
}
};
})(this);

View file

@ -203,7 +203,7 @@ var UIWorkerClient = function(topLevelNamespaces, mod, classname) {
this.postMessage({type: "event", name: name, data: data});
};
require([mod], function(Main) {
config.loadModule(["worker", mod], function(Main) {
main = new Main[classname](sender);
while (_self.messageBuffer.length)
processNext();