Browse Source

Use the top level check for the bindings cache

(rather than each potential module having its own if check)
v0.7.4-release
Paul Querna 15 years ago
committed by Ryan Dahl
parent
commit
8dbfe5ea8f
  1. 42
      src/node.cc

42
src/node.cc

@ -1588,27 +1588,16 @@ static Handle<Value> Binding(const Arguments& args) {
binding_cache->Set(module, exports);
}
else if (!strcmp(*module_v, "stdio")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
Stdio::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "cares")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
Cares::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "fs")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
// Initialize the stats object
@ -1619,57 +1608,28 @@ static Handle<Value> Binding(const Arguments& args) {
StatWatcher::Initialize(exports);
File::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "signal_watcher")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
SignalWatcher::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "http_parser")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
InitHttpParser(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "child_process")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
ChildProcess::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "buffer")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
Buffer::Initialize(exports);
binding_cache->Set(module, exports);
}
} else if (!strcmp(*module_v, "evals")) {
if (binding_cache->Has(module)) {
exports = binding_cache->Get(module)->ToObject();
} else {
exports = Object::New();
node::Context::Initialize(exports);
node::Script::Initialize(exports);
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?
@ -1697,8 +1657,6 @@ static Handle<Value> Binding(const Arguments& args) {
exports->Set(String::New("module"), String::New(native_module));
exports->Set(String::New("string_decoder"), String::New(native_string_decoder));
binding_cache->Set(module, exports);
}
} else {
return ThrowException(Exception::Error(String::New("No such module")));
}

Loading…
Cancel
Save