|
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 |
|
@@ -56,29 +57,40 @@ void OnFatalError(const char* location, const char* message);
|
56 | 57 | V(ERR_TLS_INVALID_PROTOCOL_METHOD, TypeError) \
|
57 | 58 | V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, Error) \
|
58 | 59 | V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \
|
| 60 | + V(ERR_VM_MODULE_LINK_FAILURE, Error) \ |
59 | 61 | V(ERR_WASI_NOT_STARTED, Error) \
|
60 | 62 | V(ERR_WORKER_INIT_FAILED, Error) \
|
61 | 63 | V(ERR_PROTO_ACCESS, Error)
|
62 | 64 |
|
63 |
| -#define V(code, type) \ |
64 |
| - inline v8::Local<v8::Value> code(v8::Isolate* isolate, \ |
65 |
| - const char* message) { \ |
66 |
| - v8::Local<v8::String> js_code = OneByteString(isolate, #code); \ |
67 |
| - v8::Local<v8::String> js_msg = OneByteString(isolate, message); \ |
68 |
| - v8::Local<v8::Object> e = \ |
69 |
| - v8::Exception::type(js_msg)->ToObject( \ |
70 |
| - isolate->GetCurrentContext()).ToLocalChecked(); \ |
71 |
| - e->Set(isolate->GetCurrentContext(), OneByteString(isolate, "code"), \ |
72 |
| - js_code).Check(); \ |
73 |
| - return e; \ |
74 |
| - } \ |
75 |
| - inline void THROW_ ## code(v8::Isolate* isolate, const char* message) { \ |
76 |
| - isolate->ThrowException(code(isolate, message)); \ |
77 |
| - } \ |
78 |
| - inline void THROW_ ## code(Environment* env, const char* message) { \ |
79 |
| - THROW_ ## code(env->isolate(), message); \ |
| 65 | +#define V(code, type) \ |
| 66 | + template <typename... Args> \ |
| 67 | + inline v8::Local<v8::Value> code( \ |
| 68 | + v8::Isolate* isolate, const char* format, Args&&... args) { \ |
| 69 | + std::string message = SPrintF(format, std::forward<Args>(args)...); \ |
| 70 | + v8::Local<v8::String> js_code = OneByteString(isolate, #code); \ |
| 71 | + v8::Local<v8::String> js_msg = \ |
| 72 | + OneByteString(isolate, message.c_str(), message.length()); \ |
| 73 | + v8::Local<v8::Object> e = v8::Exception::type(js_msg) \ |
| 74 | + ->ToObject(isolate->GetCurrentContext()) \ |
| 75 | + .ToLocalChecked(); \ |
| 76 | + e->Set(isolate->GetCurrentContext(), \ |
| 77 | + OneByteString(isolate, "code"), \ |
| 78 | + js_code) \ |
| 79 | + .Check(); \ |
| 80 | + return e; \ |
| 81 | + } \ |
| 82 | + template <typename... Args> \ |
| 83 | + inline void THROW_##code( \ |
| 84 | + v8::Isolate* isolate, const char* format, Args&&... args) { \ |
| 85 | + isolate->ThrowException( \ |
| 86 | + code(isolate, format, std::forward<Args>(args)...)); \ |
| 87 | + } \ |
| 88 | + template <typename... Args> \ |
| 89 | + inline void THROW_##code( \ |
| 90 | + Environment* env, const char* format, Args&&... args) { \ |
| 91 | + THROW_##code(env->isolate(), format, std::forward<Args>(args)...); \ |
80 | 92 | }
|
81 |
| - ERRORS_WITH_CODE(V) |
| 93 | +ERRORS_WITH_CODE(V) |
82 | 94 | #undef V
|
83 | 95 |
|
84 | 96 | // Errors with predefined static messages
|
|
0 commit comments