@@ -75,29 +75,48 @@ void OnFatalError(const char* location, const char* message);
7575  V (ERR_TLS_INVALID_PROTOCOL_METHOD, TypeError)                                \
7676  V (ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, Error)                                \
7777  V (ERR_VM_MODULE_CACHED_DATA_REJECTED, Error)                                 \
78+   V (ERR_VM_MODULE_LINK_FAILURE, Error)                                         \
7879  V (ERR_WASI_NOT_STARTED, Error)                                               \
7980  V (ERR_WORKER_INIT_FAILED, Error)                                             \
80-   V (ERR_PROTO_ACCESS, Error)                                                   \ 
81+   V (ERR_PROTO_ACCESS, Error)
8182
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);                                  \
83+ #define  V (code, type )                                                          \
84+   inline  v8::Local<v8::Value> code (                                            \
85+       v8::Isolate* isolate, const  char * message, va_list args) {               \
86+     v8::Local<v8::String> js_code = OneByteString (isolate, #code);             \
87+     char  buffer[256 ];                                                          \
88+     vsprintf (buffer, message, args);                                           \
89+     v8::Local<v8::String> js_msg = OneByteString (isolate, buffer);             \
90+     v8::Local<v8::Object> e = v8::Exception::type (js_msg)                      \
91+                                   ->ToObject (isolate->GetCurrentContext ())     \
92+                                   .ToLocalChecked ();                           \
93+     e->Set (isolate->GetCurrentContext (),                                       \
94+            OneByteString (isolate, " code"  ),                                     \
95+            js_code)                                                            \
96+         .Check ();                                                              \
97+     return  e;                                                                  \
98+   }                                                                            \
99+   inline  v8::Local<v8::Value> code (                                            \
100+       v8::Isolate* isolate, const  char * message, ...) {                        \
101+     va_list args;                                                              \
102+     va_start (args, message);                                                   \
103+     v8::Local<v8::Value> e = code (isolate, message, args);                     \
104+     va_end (args);                                                              \
105+     return  e;                                                                  \
106+   }                                                                            \
107+   inline  void  THROW_##code(v8::Isolate* isolate, const  char * message, ...) {   \
108+     va_list args;                                                              \
109+     va_start (args, message);                                                   \
110+     isolate->ThrowException (code (isolate, message, args));                     \
111+     va_end (args);                                                              \
112+   }                                                                            \
113+   inline  void  THROW_##code(Environment* env, const  char * message, ...) {       \
114+     va_list args;                                                              \
115+     va_start (args, message);                                                   \
116+     env->isolate ()->ThrowException (code (env->isolate (), message, args));       \
117+     va_end (args);                                                              \
99118  }
100-    ERRORS_WITH_CODE (V)
119+ ERRORS_WITH_CODE (V)
101120#undef  V
102121
103122//  Errors with predefined static messages
0 commit comments