Permalink
Browse files

Revised loader protocol to be more in line with the new interpreter m…

…odule, and the ECMAScript strawman proposal that introduced the Module primordial.
  • Loading branch information...
1 parent 4cb1daf commit a3d71f91c668820659f3859963bb44f789db0ceb @kriskowal kriskowal committed Mar 1, 2010
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/loader.js
View
18 lib/loader.js
@@ -14,6 +14,7 @@ var file = require(/**/"file"/**/);
// this gets swapped out with a full fledged-read before
// we're done using it
var read = file.read;
+var Module = system.Module || system.evaluate; // legacy
exports.Loader = function (options) {
var loader = {};
@@ -60,15 +61,24 @@ exports.Loader = function (options) {
return text;
};
- loader.evaluate = function (text, topId, path) {
+ loader.Module = function (text, topId, path) {
if (system.evaluate) {
if (!path)
path = loader.find(topId);
- var factory = system.evaluate(text, path, 1);
+ var factory = Module(text, path, 1);
factory.path = path;
return factory;
} else {
- return new Function("with(arguments[0]){"+text+"\n//*/}");
+ return function (inject) {
+ var keys = [], values = [];
+ for (var key in inject) {
+ if (Object.prototype.hasOwnProperty.call(inject, key)) {
+ keys.push(key);
+ values.push(inject[key]);
+ }
+ }
+ return Function.apply(null, keys).apply(this, values);
+ };
}
};
@@ -84,7 +94,7 @@ exports.Loader = function (options) {
};
loader.reload = function (topId, path) {
- factories[topId] = loader.evaluate(loader.fetch(topId, path), topId, path);
+ factories[topId] = loader.Module(loader.fetch(topId, path), topId, path);
};
loader.isLoaded = function (topId) {

0 comments on commit a3d71f9

Please sign in to comment.