mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
Move native js files into binding object
This commit is contained in:
parent
8492c52e15
commit
c90546f138
48
src/node.cc
48
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.)
|
||||
|
12
src/node.js
12
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user