|
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
|
|
0 commit comments