Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2020-10-03 00:10:55 +0300
committerJames M Snell <jasnell@gmail.com>2020-10-10 18:17:48 +0300
commit2310f679a1c200b8c4a35749703ce1e3429f65f5 (patch)
tree1272b6bc46d44fb9154b8af520fa2a561f729616 /src/node_binding.cc
parenteb322bbe7f8c893b3f513e411aaf7430d9596141 (diff)
src: move node_binding to modern THROW_ERR*
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/35469 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_binding.cc')
-rw-r--r--src/node_binding.cc38
1 files changed, 18 insertions, 20 deletions
diff --git a/src/node_binding.cc b/src/node_binding.cc
index 0d577a8c8e8..0db930adff1 100644
--- a/src/node_binding.cc
+++ b/src/node_binding.cc
@@ -6,6 +6,8 @@
#include "node_native_module_env.h"
#include "util.h"
+#include <string>
+
#if HAVE_OPENSSL
#define NODE_BUILTIN_OPENSSL_MODULES(V) V(crypto) V(tls_wrap)
#else
@@ -424,13 +426,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
CHECK_NULL(thread_local_modpending);
if (args.Length() < 2) {
- env->ThrowError("process.dlopen needs at least 2 arguments.");
- return;
+ return THROW_ERR_MISSING_ARGS(
+ env, "process.dlopen needs at least 2 arguments");
}
int32_t flags = DLib::kDefaultFlags;
if (args.Length() > 2 && !args[2]->Int32Value(context).To(&flags)) {
- return env->ThrowTypeError("flag argument must be an integer.");
+ return THROW_ERR_INVALID_ARG_TYPE(env, "flag argument must be an integer.");
}
Local<Object> module;
@@ -456,15 +458,13 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
thread_local_modpending = nullptr;
if (!is_opened) {
- Local<String> errmsg =
- OneByteString(env->isolate(), dlib->errmsg_.c_str());
+ std::string errmsg = dlib->errmsg_.c_str();
dlib->Close();
#ifdef _WIN32
// Windows needs to add the filename into the error message
- errmsg = String::Concat(
- env->isolate(), errmsg, args[1]->ToString(context).ToLocalChecked());
+ errmsg += *filename;
#endif // _WIN32
- env->isolate()->ThrowException(Exception::Error(errmsg));
+ THROW_ERR_DLOPEN_FAILED(env, errmsg.c_str());
return false;
}
@@ -494,7 +494,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
sizeof(errmsg),
"Module did not self-register: '%s'.",
*filename);
- env->ThrowError(errmsg);
+ THROW_ERR_DLOPEN_FAILED(env, errmsg);
return false;
}
}
@@ -525,7 +525,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
// NOTE: `mp` is allocated inside of the shared library's memory, calling
// `dlclose` will deallocate it
dlib->Close();
- env->ThrowError(errmsg);
+ THROW_ERR_DLOPEN_FAILED(env, errmsg);
return false;
}
CHECK_EQ(mp->nm_flags & NM_F_BUILTIN, 0);
@@ -538,7 +538,7 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
mp->nm_register_func(exports, module, mp->nm_priv);
} else {
dlib->Close();
- env->ThrowError("Module has no declared entry point.");
+ THROW_ERR_DLOPEN_FAILED(env, "Module has no declared entry point.");
return false;
}
@@ -577,12 +577,6 @@ static Local<Object> InitModule(Environment* env,
return exports;
}
-static void ThrowIfNoSuchModule(Environment* env, const char* module_v) {
- char errmsg[1024];
- snprintf(errmsg, sizeof(errmsg), "No such module: %s", module_v);
- env->ThrowError(errmsg);
-}
-
void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
@@ -611,7 +605,9 @@ void GetInternalBinding(const FunctionCallbackInfo<Value>& args) {
env->isolate()))
.FromJust());
} else {
- return ThrowIfNoSuchModule(env, *module_v);
+ char errmsg[1024];
+ snprintf(errmsg, sizeof(errmsg), "No such module: %s", *module_v);
+ return THROW_ERR_INVALID_MODULE(env, errmsg);
}
args.GetReturnValue().Set(exports);
@@ -646,7 +642,7 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
sizeof(errmsg),
"No such module was linked: %s",
*module_name_v);
- return env->ThrowError(errmsg);
+ return THROW_ERR_INVALID_MODULE(env, errmsg);
}
Local<Object> module = Object::New(env->isolate());
@@ -661,7 +657,9 @@ void GetLinkedBinding(const FunctionCallbackInfo<Value>& args) {
} else if (mod->nm_register_func != nullptr) {
mod->nm_register_func(exports, module, mod->nm_priv);
} else {
- return env->ThrowError("Linked module has no declared entry point.");
+ return THROW_ERR_INVALID_MODULE(
+ env,
+ "Linked moduled has no declared entry point.");
}
auto effective_exports =