diff --git a/src/node.cc b/src/node.cc index 89c7fa828e2..25d11276730 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1461,7 +1461,9 @@ Handle DLOpen(const v8::Arguments& args) { int r; if (args.Length() < 2) { - return Undefined(); + Local exception = Exception::Error( + String::New("process.dlopen takes exactly 2 arguments.")); + return ThrowException(exception); } String::Utf8Value filename(args[0]->ToString()); // Cast @@ -1469,8 +1471,10 @@ Handle DLOpen(const v8::Arguments& args) { err = uv_dlopen(*filename, &lib); if (err.code != UV_OK) { - SetErrno(err); - return scope.Close(Integer::New(-1)); + Local exception = Exception::Error( + String::Concat(String::New("Unable to load shared library "), + args[0]->ToString())); + return ThrowException(exception); } String::Utf8Value path(args[0]->ToString()); @@ -1501,9 +1505,9 @@ Handle DLOpen(const v8::Arguments& args) { /* Add the `_module` suffix to the extension name. */ r = snprintf(symbol, sizeof symbol, "%s_module", base); if (r <= 0 || r >= sizeof symbol) { - err.code = UV_ENOMEM; - SetErrno(err); - return scope.Close(Integer::New(-1)); + Local exception = + Exception::Error(String::New("Out of memory.")); + return ThrowException(exception); } // Get the init() function from the dynamically shared object. @@ -1520,15 +1524,16 @@ Handle DLOpen(const v8::Arguments& args) { err = uv_dlsym(lib, "init", reinterpret_cast(&mod->register_func)); if (err.code != UV_OK) { uv_dlclose(lib); - SetErrno(err); - return scope.Close(Integer::New(-1)); + Local exception = Exception::Error( + String::New("Out of memory.")); + return ThrowException(exception); } /* End Compatibility hack */ } if (mod->version != NODE_MODULE_VERSION) { - Local exception = - Exception::Error(String::New("Module version mismatch, refusing to load.")); + Local exception = Exception::Error( + String::New("Module version mismatch, refusing to load.")); return ThrowException(exception); }