From 94ea9a58451711412f1c7550c0313c81ed97fec9 Mon Sep 17 00:00:00 2001 From: nightwing Date: Tue, 7 Aug 2012 19:13:23 +0400 Subject: [PATCH 1/2] fix for loading of files generated by r.js from the worker --- lib/ace/worker/worker.js | 7 +++++++ lib/ace/worker/worker_client.js | 2 ++ 2 files changed, 9 insertions(+) diff --git a/lib/ace/worker/worker.js b/lib/ace/worker/worker.js index 295f90b3..b4c86649 100644 --- a/lib/ace/worker/worker.js +++ b/lib/ace/worker/worker.js @@ -56,6 +56,10 @@ require.tlns = {}; var define = function(id, deps, factory) { if (arguments.length == 2) { factory = deps; + if (typeof id != "string") { + deps = id; + id = require.id; + } } else if (arguments.length == 1) { factory = id; id = require.id; @@ -135,4 +139,7 @@ onmessage = function(e) { else if (msg.event && sender) { sender._emit(msg.event, msg.data); } + if (msg.eval) { + console.log(eval(msg.eval)); + } }; diff --git a/lib/ace/worker/worker_client.js b/lib/ace/worker/worker_client.js index 0ec7a6a3..ed1ada78 100644 --- a/lib/ace/worker/worker_client.js +++ b/lib/ace/worker/worker_client.js @@ -114,6 +114,8 @@ var WorkerClient = function(topLevelNamespaces, mod, classname) { oop.implement(this, EventEmitter); this.$normalizePath = function(path) { + if (!location.host) // needed for file:// protocol + return path; path = path.replace(/^[a-z]+:\/\/[^\/]+/, ""); // Remove domain name and rebuild it path = location.protocol + "//" + location.host // paths starting with a slash are relative to the root (host) From a69a9f12d4412bd927d5adddd01364159aa9cb88 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 11 Aug 2012 12:12:38 +0400 Subject: [PATCH 2/2] do not create infinite loop if module has circular dependencies + cleanup --- lib/ace/worker/worker.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/ace/worker/worker.js b/lib/ace/worker/worker.js index b4c86649..2e1853df 100644 --- a/lib/ace/worker/worker.js +++ b/lib/ace/worker/worker.js @@ -35,8 +35,8 @@ var require = function(parentId, id) { var module = require.modules[id]; if (module) { if (!module.initialized) { - module.exports = module.factory().exports; module.initialized = true; + module.exports = module.factory().exports; } return module.exports; } @@ -139,7 +139,4 @@ onmessage = function(e) { else if (msg.event && sender) { sender._emit(msg.event, msg.data); } - if (msg.eval) { - console.log(eval(msg.eval)); - } };