summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-03-15 14:22:50 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-03-15 14:24:15 -0700
commitc90546f138e42ee191a9ef240a0168007b243604 (patch)
tree92a79e7ef8647d1d64cac4dfbe6686ac2ce4707d
parent8492c52e1529cf5988efd2b64e853b08a9c3a079 (diff)
downloadnode-c90546f138e42ee191a9ef240a0168007b243604.tar.gz
Move native js files into binding object
-rw-r--r--src/node.cc48
-rw-r--r--src/node.js12
2 files changed, 34 insertions, 26 deletions
diff --git a/src/node.cc b/src/node.cc
index 26fd61eef..2d47b7880 100644
--- a/src/node.cc
+++ b/src/node.cc
@@ -1117,6 +1117,32 @@ static Handle<Value> Binding(const Arguments& args) {
binding_cache->Set(module, exports);
}
+ } else if (!strcmp(*module_v, "natives")) {
+ if (binding_cache->Has(module)) {
+ exports = binding_cache->Get(module)->ToObject();
+ } else {
+ exports = Object::New();
+ // Explicitly define native sources.
+ // TODO DRY/automate this?
+ exports->Set(String::New("assert"), String::New(native_assert));
+ exports->Set(String::New("dns"), String::New(native_dns));
+ exports->Set(String::New("file"), String::New(native_file));
+ exports->Set(String::New("fs"), String::New(native_fs));
+ exports->Set(String::New("http"), String::New(native_http));
+ exports->Set(String::New("ini"), String::New(native_ini));
+ exports->Set(String::New("mjsunit"), String::New(native_mjsunit));
+ exports->Set(String::New("multipart"), String::New(native_multipart));
+ exports->Set(String::New("posix"), String::New(native_posix));
+ exports->Set(String::New("querystring"), String::New(native_querystring));
+ exports->Set(String::New("repl"), String::New(native_repl));
+ exports->Set(String::New("sys"), String::New(native_sys));
+ exports->Set(String::New("tcp"), String::New(native_tcp));
+ exports->Set(String::New("uri"), String::New(native_uri));
+ exports->Set(String::New("url"), String::New(native_url));
+ exports->Set(String::New("utils"), String::New(native_utils));
+ binding_cache->Set(module, exports);
+ }
+
} else {
assert(0);
return ThrowException(Exception::Error(String::New("No such module")));
@@ -1216,28 +1242,6 @@ static void Load(int argc, char *argv[]) {
ChildProcess::Initialize(process); // child_process.cc
DefineConstants(process); // constants.cc
-
- Local<Object> natives = Object::New();
- process->Set(String::New("natives"), natives);
- // Explicitly define native sources.
- natives->Set(String::New("assert"), String::New(native_assert));
- natives->Set(String::New("dns"), String::New(native_dns));
- natives->Set(String::New("file"), String::New(native_file));
- natives->Set(String::New("fs"), String::New(native_fs));
- natives->Set(String::New("http"), String::New(native_http));
- natives->Set(String::New("ini"), String::New(native_ini));
- natives->Set(String::New("mjsunit"), String::New(native_mjsunit));
- natives->Set(String::New("multipart"), String::New(native_multipart));
- natives->Set(String::New("posix"), String::New(native_posix));
- natives->Set(String::New("querystring"), String::New(native_querystring));
- natives->Set(String::New("repl"), String::New(native_repl));
- natives->Set(String::New("sys"), String::New(native_sys));
- natives->Set(String::New("tcp"), String::New(native_tcp));
- natives->Set(String::New("uri"), String::New(native_uri));
- natives->Set(String::New("url"), String::New(native_url));
- natives->Set(String::New("utils"), String::New(native_utils));
-
-
// Compile, execute the src/node.js file. (Which was included as static C
// string in node_natives.h. 'natve_node' is the string containing that
// source code.)
diff --git a/src/node.js b/src/node.js
index b2079e2f8..22df434e1 100644
--- a/src/node.js
+++ b/src/node.js
@@ -74,12 +74,16 @@ function createInternalModule (id, constructor) {
};
+// This contains the source code for the files in lib/
+// Like, natives.fs is the contents of lib/fs.js
+var natives = process.binding('natives');
+
function requireNative (id) {
if (internalModuleCache[id]) return internalModuleCache[id].exports;
- if (!process.natives[id]) throw new Error('No such native module ' + id);
+ if (!natives[id]) throw new Error('No such native module ' + id);
var m = new Module(id);
internalModuleCache[id] = m;
- var e = m._compile(process.natives[id], id);
+ var e = m._compile(natives[id], id);
if (e) throw e;
return m.exports;
}
@@ -540,10 +544,10 @@ function loadModule (request, parent, callback) {
if (!cachedModule) {
// Try to compile from native modules
- if (process.natives[id]) {
+ if (natives[id]) {
debug('load native module ' + id);
cachedModule = new Module(id);
- var e = cachedModule._compile(process.natives[id], id);
+ var e = cachedModule._compile(natives[id], id);
if (e) throw e;
internalModuleCache[id] = cachedModule;
}