@@ -1078,12 +1078,6 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
10781078 // coverity[leaked_storage]
10791079}
10801080
1081- static void OnMessage (Local<Message> message, Local<Value> error) {
1082- // The current version of V8 sends messages for errors only
1083- // (thus `error` is always set).
1084- FatalException (Isolate::GetCurrent (), error, message);
1085- }
1086-
10871081static Maybe<bool > ProcessEmitWarningGeneric (Environment* env,
10881082 const char * warning,
10891083 const char * type = nullptr ,
@@ -1160,6 +1154,33 @@ Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
11601154 deprecation_code);
11611155}
11621156
1157+ static void OnMessage (Local<Message> message, Local<Value> error) {
1158+ Isolate* isolate = message->GetIsolate ();
1159+ switch (message->ErrorLevel ()) {
1160+ case Isolate::MessageErrorLevel::kMessageWarning : {
1161+ Environment* env = Environment::GetCurrent (isolate);
1162+ if (!env) {
1163+ break ;
1164+ }
1165+ Utf8Value filename (isolate,
1166+ message->GetScriptOrigin ().ResourceName ());
1167+ // (filename):(line) (message)
1168+ std::stringstream warning;
1169+ warning << *filename;
1170+ warning << " :" ;
1171+ warning << message->GetLineNumber (env->context ()).FromMaybe (-1 );
1172+ warning << " " ;
1173+ v8::String::Utf8Value msg (isolate, message->Get ());
1174+ warning << *msg;
1175+ USE (ProcessEmitWarningGeneric (env, warning.str ().c_str (), " V8" ));
1176+ break ;
1177+ }
1178+ case Isolate::MessageErrorLevel::kMessageError :
1179+ FatalException (isolate, error, message);
1180+ break ;
1181+ }
1182+ }
1183+
11631184
11641185static Local<Object> InitModule (Environment* env,
11651186 node_module* mod,
@@ -2583,7 +2604,9 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
25832604 v8_platform.Platform ()->RegisterIsolate (isolate, event_loop);
25842605 Isolate::Initialize (isolate, params);
25852606
2586- isolate->AddMessageListener (OnMessage);
2607+ isolate->AddMessageListenerWithErrorLevel (OnMessage,
2608+ Isolate::MessageErrorLevel::kMessageError |
2609+ Isolate::MessageErrorLevel::kMessageWarning );
25872610 isolate->SetAbortOnUncaughtExceptionCallback (ShouldAbortOnUncaughtException);
25882611 isolate->SetMicrotasksPolicy (MicrotasksPolicy::kExplicit );
25892612 isolate->SetFatalErrorHandler (OnFatalError);
0 commit comments