Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-11-22 02:06:20 +0300
committerRyan Dahl <ry@tinyclouds.org>2010-11-22 02:06:20 +0300
commitbb6d468dd83a3a9e59b053b706242ae7b7bf1a17 (patch)
tree36703177c01824f9d9560b2313ce1687560bb96c /src
parent11b2ee76322c2d251d618ece286d23272ca92af5 (diff)
requireNative doesn't depend on rest of module system
Diffstat (limited to 'src')
-rw-r--r--src/node.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/src/node.js b/src/node.js
index 5baa6aad40f..d9684d7832f 100644
--- a/src/node.js
+++ b/src/node.js
@@ -104,22 +104,32 @@ var module = (function () {
// Like, natives.fs is the contents of lib/fs.js
var natives = process.binding('natives');
- function loadNative (id) {
+ // Native modules don't need a full require function. So we can bootstrap
+ // most of the system with this mini-require.
+ function requireNative (id) {
+ if (internalModuleCache[id]) return internalModuleCache[id].exports;
+ if (!natives[id]) throw new Error('No such native module ' + id);
+
+ // REPL is a special case, because it needs the real require.
+ if (id == 'repl') {
+ var replModule = new Module("repl");
+ replModule._compile(natives.repl, 'repl.js');
+ internalModuleCache.repl = replModule;
+ return replModule.exports;
+ }
+
+ var fn = process.compile(
+ "(function (exports, require) {" + natives[id] + "\n})",
+ id + '.js');
var m = new Module(id);
+ fn(m.exports, requireNative);
+ m.loaded = true;
internalModuleCache[id] = m;
- var e = m._compile(natives[id], id+".js");
- if (e) throw e; // error compiling native module
- return m;
+ return m.exports;
}
exports.requireNative = requireNative;
- function requireNative (id) {
- if (internalModuleCache[id]) return internalModuleCache[id].exports;
- if (!natives[id]) throw new Error('No such native module ' + id);
- return loadNative(id).exports;
- }
-
// Modules
@@ -230,7 +240,7 @@ var module = (function () {
}
if (natives[id]) {
debug('load native module ' + request);
- return loadNative(id).exports;
+ return requireNative(id);
}
var cachedModule = moduleCache[filename];