|
9 | 9 | // Use ostringstream to print exact-width integer types |
10 | 10 | // because the format specifiers are not available on AIX. |
11 | 11 | #include <sstream> |
| 12 | +#include <cstdarg> |
12 | 13 |
|
13 | 14 | namespace node { |
14 | 15 |
|
@@ -75,29 +76,48 @@ 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 | + inline v8::Local<v8::Value> code( \ |
| 86 | + v8::Isolate* isolate, const char* message, va_list args) { \ |
| 87 | + v8::Local<v8::String> js_code = OneByteString(isolate, #code); \ |
| 88 | + char buffer[256]; \ |
| 89 | + vsprintf(buffer, message, args); \ |
| 90 | + v8::Local<v8::String> js_msg = OneByteString(isolate, buffer); \ |
| 91 | + v8::Local<v8::Object> e = v8::Exception::type(js_msg) \ |
| 92 | + ->ToObject(isolate->GetCurrentContext()) \ |
| 93 | + .ToLocalChecked(); \ |
| 94 | + e->Set(isolate->GetCurrentContext(), \ |
| 95 | + OneByteString(isolate, "code"), \ |
| 96 | + js_code) \ |
| 97 | + .Check(); \ |
| 98 | + return e; \ |
| 99 | + } \ |
| 100 | + inline v8::Local<v8::Value> code( \ |
| 101 | + v8::Isolate* isolate, const char* message, ...) { \ |
| 102 | + va_list args; \ |
| 103 | + va_start(args, message); \ |
| 104 | + v8::Local<v8::Value> e = code(isolate, message, args); \ |
| 105 | + va_end(args); \ |
| 106 | + return e; \ |
| 107 | + } \ |
| 108 | + inline void THROW_##code(v8::Isolate* isolate, const char* message, ...) { \ |
| 109 | + va_list args; \ |
| 110 | + va_start(args, message); \ |
| 111 | + isolate->ThrowException(code(isolate, message, args)); \ |
| 112 | + va_end(args); \ |
| 113 | + } \ |
| 114 | + inline void THROW_##code(Environment* env, const char* message, ...) { \ |
| 115 | + va_list args; \ |
| 116 | + va_start(args, message); \ |
| 117 | + env->isolate()->ThrowException(code(env->isolate(), message, args)); \ |
| 118 | + va_end(args); \ |
99 | 119 | } |
100 | | - ERRORS_WITH_CODE(V) |
| 120 | +ERRORS_WITH_CODE(V) |
101 | 121 | #undef V |
102 | 122 |
|
103 | 123 | // Errors with predefined static messages |
|
0 commit comments