summaryrefslogtreecommitdiff
path: root/lib/module.js
diff options
context:
space:
mode:
authorFred K. Schott <fschott@box.com>2014-06-12 11:12:54 -0700
committerFedor Indutny <fedor@indutny.com>2014-06-24 20:26:02 +0400
commita55c60c71550dd82e7bdad4ae7df42e77631204f (patch)
treeb86a9a0445dae4212b7b20e198cf9ca1e60923e3 /lib/module.js
parent16ed1946598ed3ae58bcdd362e8dceca0f89d80a (diff)
downloadnode-a55c60c71550dd82e7bdad4ae7df42e77631204f.tar.gz
module: document important methods
Signed-off-by: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'lib/module.js')
-rw-r--r--lib/module.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/module.js b/lib/module.js
index 11b9f8548..d310f93c1 100644
--- a/lib/module.js
+++ b/lib/module.js
@@ -265,6 +265,13 @@ Module._resolveLookupPaths = function(request, parent) {
};
+// Check the cache for the requested file.
+// 1. If a module already exists in the cache: return its exports object.
+// 2. If the module is native: call `NativeModule.require()` with the
+// filename and return the result.
+// 3. Otherwise, create a new module for the file and save it to the cache.
+// Then have it load the file contents before returning its exports
+// object.
Module._load = function(request, parent, isMain) {
if (parent) {
debug('Module._load REQUEST ' + (request) + ' parent: ' + parent.id);
@@ -336,6 +343,7 @@ Module._resolveFilename = function(request, parent) {
};
+// Given a file name, pass it to the proper extension handler.
Module.prototype.load = function(filename) {
debug('load ' + JSON.stringify(filename) +
' for module ' + JSON.stringify(this.id));
@@ -351,6 +359,8 @@ Module.prototype.load = function(filename) {
};
+// Loads a module at the given file path. Returns that module's
+// `exports` property.
Module.prototype.require = function(path) {
assert(util.isString(path), 'path must be a string');
assert(path, 'missing path');
@@ -363,7 +373,10 @@ Module.prototype.require = function(path) {
var resolvedArgv;
-// Returns exception if any
+// Run the file contents in the correct scope or sandbox. Expose
+// the correct helper variables (require, module, exports) to
+// the file.
+// Returns exception, if any.
Module.prototype._compile = function(content, filename) {
var self = this;
// remove shebang