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
path: root/src
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2019-12-22 20:05:39 +0300
committercjihrig <cjihrig@gmail.com>2019-12-26 06:27:11 +0300
commit208453ef42074e3d0df66c390c1fd699003f1249 (patch)
tree9544357c60f71963f66d7f0b1acd48ca569c8260 /src
parent6e20674c6f03ebe272e69cc3afb84db277163a7c (diff)
wasi: throw on failed uvwasi_init()
Prior to this commit, if uvwasi_init() failed in any way, Node would abort due to a failed CHECK_EQ(). This commit changes that behavior to a thrown exception. PR-URL: https://github.com/nodejs/node/pull/31076 Fixes: https://github.com/nodejs/node/issues/30878 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_wasi.cc44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/node_wasi.cc b/src/node_wasi.cc
index 5f4644e03ac..699c4c46991 100644
--- a/src/node_wasi.cc
+++ b/src/node_wasi.cc
@@ -74,22 +74,64 @@ using v8::ArrayBuffer;
using v8::BackingStore;
using v8::BigInt;
using v8::Context;
+using v8::Exception;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
+using v8::Integer;
+using v8::Isolate;
using v8::Local;
+using v8::MaybeLocal;
using v8::Object;
using v8::String;
using v8::Uint32;
using v8::Value;
+static MaybeLocal<Value> WASIException(Local<Context> context,
+ int errorno,
+ const char* syscall) {
+ Isolate* isolate = context->GetIsolate();
+ Environment* env = Environment::GetCurrent(context);
+ CHECK_NOT_NULL(env);
+ const char* err_name = uvwasi_embedder_err_code_to_string(errorno);
+ Local<String> js_code = OneByteString(isolate, err_name);
+ Local<String> js_syscall = OneByteString(isolate, syscall);
+ Local<String> js_msg = js_code;
+ js_msg =
+ String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", "));
+ js_msg = String::Concat(isolate, js_msg, js_syscall);
+ Local<Object> e =
+ Exception::Error(js_msg)->ToObject(context)
+ .ToLocalChecked();
+
+ if (e->Set(context,
+ env->errno_string(),
+ Integer::New(isolate, errorno)).IsNothing() ||
+ e->Set(context, env->code_string(), js_code).IsNothing() ||
+ e->Set(context, env->syscall_string(), js_syscall).IsNothing()) {
+ return MaybeLocal<Value>();
+ }
+
+ return e;
+}
+
+
WASI::WASI(Environment* env,
Local<Object> object,
uvwasi_options_t* options) : BaseObject(env, object) {
MakeWeak();
alloc_info_ = MakeAllocator();
options->allocator = &alloc_info_;
- CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS);
+ int err = uvwasi_init(&uvw_, options);
+ if (err != UVWASI_ESUCCESS) {
+ Local<Context> context = env->context();
+ MaybeLocal<Value> exception = WASIException(context, err, "uvwasi_init");
+
+ if (exception.IsEmpty())
+ return;
+
+ context->GetIsolate()->ThrowException(exception.ToLocalChecked());
+ }
}