| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6de77d3 commit 0d212fc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,22 +73,64 @@ using v8::Array; | |||
| 73 | 73 | using v8::ArrayBuffer; | |
| 74 | 74 | using v8::BigInt; | |
| 75 | 75 | using v8::Context; | |
| 76 | + using v8::Exception; | ||
| 76 | 77 | using v8::FunctionCallbackInfo; | |
| 77 | 78 | using v8::FunctionTemplate; | |
| 79 | + using v8::Integer; | ||
| 80 | + using v8::Isolate; | ||
| 78 | 81 | using v8::Local; | |
| 82 | + using v8::MaybeLocal; | ||
| 79 | 83 | using v8::Object; | |
| 80 | 84 | using v8::String; | |
| 81 | 85 | using v8::Uint32; | |
| 82 | 86 | using v8::Value; | |
| 83 | 87 | ||
| 84 | 88 | ||
| 89 | + static MaybeLocal<Value> WASIException(Local<Context> context, | ||
| 90 | + int errorno, | ||
| 91 | + const char* syscall) { | ||
| 92 | + Isolate* isolate = context->GetIsolate(); | ||
| 93 | + Environment* env = Environment::GetCurrent(context); | ||
| 94 | + CHECK_NOT_NULL(env); | ||
| 95 | + const char* err_name = uvwasi_embedder_err_code_to_string(errorno); | ||
| 96 | + Local<String> js_code = OneByteString(isolate, err_name); | ||
| 97 | + Local<String> js_syscall = OneByteString(isolate, syscall); | ||
| 98 | + Local<String> js_msg = js_code; | ||
| 99 | + js_msg = | ||
| 100 | + String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", ")); | ||
| 101 | + js_msg = String::Concat(isolate, js_msg, js_syscall); | ||
| 102 | + Local<Object> e = | ||
| 103 | + Exception::Error(js_msg)->ToObject(context) | ||
| 104 | + .ToLocalChecked(); | ||
| 105 | + | ||
| 106 | + if (e->Set(context, | ||
| 107 | + env->errno_string(), | ||
| 108 | + Integer::New(isolate, errorno)).IsNothing() || | ||
| 109 | + e->Set(context, env->code_string(), js_code).IsNothing() || | ||
| 110 | + e->Set(context, env->syscall_string(), js_syscall).IsNothing()) { | ||
| 111 | + return MaybeLocal<Value>(); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + return e; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + | ||
| 85 | 118 | WASI::WASI(Environment* env, | |
| 86 | 119 | Local<Object> object, | |
| 87 | 120 | uvwasi_options_t* options) : BaseObject(env, object) { | |
| 88 | 121 | MakeWeak(); | |
| 89 | 122 | alloc_info_ = MakeAllocator(); | |
| 90 | 123 | options->allocator = &alloc_info_; | |
| 91 | - CHECK_EQ(uvwasi_init(&uvw_, options), UVWASI_ESUCCESS); | ||
| 124 | + int err = uvwasi_init(&uvw_, options); | ||
| 125 | + if (err != UVWASI_ESUCCESS) { | ||
| 126 | + Local<Context> context = env->context(); | ||
| 127 | + MaybeLocal<Value> exception = WASIException(context, err, "uvwasi_init"); | ||
| 128 | + | ||
| 129 | + if (exception.IsEmpty()) | ||
| 130 | + return; | ||
| 131 | + | ||
| 132 | + context->GetIsolate()->ThrowException(exception.ToLocalChecked()); | ||
| 133 | + } | ||
| 92 | 134 | } | |
| 93 | 135 | ||
| 94 | 136 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,3 +26,8 @@ assert.throws(() => { new WASI({ preopens: 'fhqwhgads' }); }, | |||
| 26 | 26 | assert.throws(() => { new WASI(value); }, | |
| 27 | 27 | { code: 'ERR_INVALID_ARG_TYPE' }); | |
| 28 | 28 | }); | |
| 29 | + | ||
| 30 | + // Verify that exceptions thrown from the binding layer are handled. | ||
| 31 | + assert.throws(() => { | ||
| 32 | + new WASI({ preopens: { '/sandbox': '__/not/real/path' } }); | ||
| 33 | + }, { code: 'UVWASI_ENOENT', message: /uvwasi_init/ }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments