| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 60d8afa commit d59c6de
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2313,6 +2313,11 @@ than the parent module. Linked modules must share the same context. | |||
| 2313 | 2313 | ||
| 2314 | 2314 | The linker function returned a module for which linking has failed. | |
| 2315 | 2315 | ||
| 2316 | + <a id="ERR_VM_MODULE_LINK_FAILURE"></a> | ||
| 2317 | + ### `ERR_VM_MODULE_LINK_FAILURE` | ||
| 2318 | + | ||
| 2319 | + The module was unable to be linked due to a failure. | ||
| 2320 | + | ||
| 2316 | 2321 | <a id="ERR_VM_MODULE_NOT_MODULE"></a> | |
| 2317 | 2322 | ### `ERR_VM_MODULE_NOT_MODULE` | |
| 2318 | 2323 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -317,6 +317,8 @@ class SourceTextModule extends Module { | |||
| 317 | 317 | throw new ERR_VM_MODULE_DIFFERENT_CONTEXT(); | |
| 318 | 318 | } | |
| 319 | 319 | if (module.status === 'errored') { | |
| 320 | + // TODO(devsnek): replace with ERR_VM_MODULE_LINK_FAILURE | ||
| 321 | + // and error cause proposal. | ||
| 320 | 322 | throw new ERR_VM_MODULE_LINKING_ERRORED(); | |
| 321 | 323 | } | |
| 322 | 324 | if (module.status === 'unlinked') { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -291,7 +291,9 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { | |||
| 291 | 291 | Local<Value> resolve_return_value = | |
| 292 | 292 | maybe_resolve_return_value.ToLocalChecked(); | |
| 293 | 293 | if (!resolve_return_value->IsPromise()) { | |
| 294 | - env->ThrowError("linking error, expected resolver to return a promise"); | ||
| 294 | + THROW_ERR_VM_MODULE_LINK_FAILURE( | ||
| 295 | + env, "request for '%s' did not return promise", specifier_std); | ||
| 296 | + return; | ||
| 295 | 297 | } | |
| 296 | 298 | Local<Promise> resolve_promise = resolve_return_value.As<Promise>(); | |
| 297 | 299 | obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise); | |
@@ -485,33 +487,35 @@ MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context, | |||
| 485 | 487 | ||
| 486 | 488 | Isolate* isolate = env->isolate(); | |
| 487 | 489 | ||
| 490 | + Utf8Value specifier_utf8(isolate, specifier); | ||
| 491 | + std::string specifier_std(*specifier_utf8, specifier_utf8.length()); | ||
| 492 | + | ||
| 488 | 493 | ModuleWrap* dependent = GetFromModule(env, referrer); | |
| 489 | 494 | if (dependent == nullptr) { | |
| 490 | - env->ThrowError("linking error, null dep"); | ||
| 495 | + THROW_ERR_VM_MODULE_LINK_FAILURE( | ||
| 496 | + env, "request for '%s' is from invalid module", specifier_std); | ||
| 491 | 497 | return MaybeLocal<Module>(); | |
| 492 | 498 | } | |
| 493 | 499 | ||
| 494 | - Utf8Value specifier_utf8(isolate, specifier); | ||
| 495 | - std::string specifier_std(*specifier_utf8, specifier_utf8.length()); | ||
| 496 | - | ||
| 497 | 500 | if (dependent->resolve_cache_.count(specifier_std) != 1) { | |
| 498 | - env->ThrowError("linking error, not in local cache"); | ||
| 501 | + THROW_ERR_VM_MODULE_LINK_FAILURE( | ||
| 502 | + env, "request for '%s' is not in cache", specifier_std); | ||
| 499 | 503 | return MaybeLocal<Module>(); | |
| 500 | 504 | } | |
| 501 | 505 | ||
| 502 | 506 | Local<Promise> resolve_promise = | |
| 503 | 507 | dependent->resolve_cache_[specifier_std].Get(isolate); | |
| 504 | 508 | ||
| 505 | 509 | if (resolve_promise->State() != Promise::kFulfilled) { | |
| 506 | - env->ThrowError("linking error, dependency promises must be resolved on " | ||
| 507 | - "instantiate"); | ||
| 510 | + THROW_ERR_VM_MODULE_LINK_FAILURE( | ||
| 511 | + env, "request for '%s' is not yet fulfilled", specifier_std); | ||
| 508 | 512 | return MaybeLocal<Module>(); | |
| 509 | 513 | } | |
| 510 | 514 | ||
| 511 | 515 | Local<Object> module_object = resolve_promise->Result().As<Object>(); | |
| 512 | 516 | if (module_object.IsEmpty() || !module_object->IsObject()) { | |
| 513 | - env->ThrowError("linking error, expected a valid module object from " | ||
| 514 | - "resolver"); | ||
| 517 | + THROW_ERR_VM_MODULE_LINK_FAILURE( | ||
| 518 | + env, "request for '%s' did not return an object", specifier_std); | ||
| 515 | 519 | return MaybeLocal<Module>(); | |
| 516 | 520 | } | |
| 517 | 521 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | + #include "debug_utils-inl.h" | ||
| 6 | 7 | #include "env.h" | |
| 7 | 8 | #include "v8.h" | |
| 8 | 9 | ||
@@ -75,29 +76,40 @@ void OnFatalError(const char* location, const char* message); | |||
| 75 | 76 | V(ERR_TLS_INVALID_PROTOCOL_METHOD, TypeError) \ | |
| 76 | 77 | V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, Error) \ | |
| 77 | 78 | V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \ | |
| 79 | + V(ERR_VM_MODULE_LINK_FAILURE, Error) \ | ||
| 78 | 80 | V(ERR_WASI_NOT_STARTED, Error) \ | |
| 79 | 81 | V(ERR_WORKER_INIT_FAILED, Error) \ | |
| 80 | - V(ERR_PROTO_ACCESS, Error) \ | ||
| 82 | + V(ERR_PROTO_ACCESS, Error) | ||
| 81 | 83 | ||
| 82 | - #define V(code, type) \ | ||
| 83 | - inline v8::Local<v8::Value> code(v8::Isolate* isolate, \ | ||
| 84 | - const char* message) { \ | ||
| 85 | - v8::Local<v8::String> js_code = OneByteString(isolate, #code); \ | ||
| 86 | - v8::Local<v8::String> js_msg = OneByteString(isolate, message); \ | ||
| 87 | - v8::Local<v8::Object> e = \ | ||
| 88 | - v8::Exception::type(js_msg)->ToObject( \ | ||
| 89 | - isolate->GetCurrentContext()).ToLocalChecked(); \ | ||
| 90 | - e->Set(isolate->GetCurrentContext(), OneByteString(isolate, "code"), \ | ||
| 91 | - js_code).Check(); \ | ||
| 92 | - return e; \ | ||
| 93 | - } \ | ||
| 94 | - inline void THROW_ ## code(v8::Isolate* isolate, const char* message) { \ | ||
| 95 | - isolate->ThrowException(code(isolate, message)); \ | ||
| 96 | - } \ | ||
| 97 | - inline void THROW_ ## code(Environment* env, const char* message) { \ | ||
| 98 | - THROW_ ## code(env->isolate(), message); \ | ||
| 84 | + #define V(code, type) \ | ||
| 85 | + template <typename... Args> \ | ||
| 86 | + inline v8::Local<v8::Value> code( \ | ||
| 87 | + v8::Isolate* isolate, const char* format, Args&&... args) { \ | ||
| 88 | + std::string message = SPrintF(format, std::forward<Args>(args)...); \ | ||
| 89 | + v8::Local<v8::String> js_code = OneByteString(isolate, #code); \ | ||
| 90 | + v8::Local<v8::String> js_msg = \ | ||
| 91 | + OneByteString(isolate, message.c_str(), message.length()); \ | ||
| 92 | + v8::Local<v8::Object> e = v8::Exception::type(js_msg) \ | ||
| 93 | + ->ToObject(isolate->GetCurrentContext()) \ | ||
| 94 | + .ToLocalChecked(); \ | ||
| 95 | + e->Set(isolate->GetCurrentContext(), \ | ||
| 96 | + OneByteString(isolate, "code"), \ | ||
| 97 | + js_code) \ | ||
| 98 | + .Check(); \ | ||
| 99 | + return e; \ | ||
| 100 | + } \ | ||
| 101 | + template <typename... Args> \ | ||
| 102 | + inline void THROW_##code( \ | ||
| 103 | + v8::Isolate* isolate, const char* format, Args&&... args) { \ | ||
| 104 | + isolate->ThrowException( \ | ||
| 105 | + code(isolate, format, std::forward<Args>(args)...)); \ | ||
| 106 | + } \ | ||
| 107 | + template <typename... Args> \ | ||
| 108 | + inline void THROW_##code( \ | ||
| 109 | + Environment* env, const char* format, Args&&... args) { \ | ||
| 110 | + THROW_##code(env->isolate(), format, std::forward<Args>(args)...); \ | ||
| 99 | 111 | } | |
| 100 | - ERRORS_WITH_CODE(V) | ||
| 112 | + ERRORS_WITH_CODE(V) | ||
| 101 | 113 | #undef V | |
| 102 | 114 | ||
| 103 | 115 | // Errors with predefined static messages | |
| Back | FazBrowse Home | New Git URL |
0 commit comments