@@ -1074,12 +1074,6 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
10741074 // coverity[leaked_storage]
10751075}
10761076
1077- static void OnMessage(Local<Message> message, Local<Value> error) {
1078- // The current version of V8 sends messages for errors only
1079- // (thus `error` is always set).
1080- FatalException(Isolate::GetCurrent(), error, message);
1081- }
1082-
10831077static Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
10841078 const char* warning,
10851079 const char* type = nullptr,
@@ -1156,6 +1150,33 @@ Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
11561150 deprecation_code);
11571151}
11581152
1153+ static void OnMessage(Local<Message> message, Local<Value> error) {
1154+ Isolate* isolate = message->GetIsolate();
1155+ switch (message->ErrorLevel()) {
1156+ case Isolate::MessageErrorLevel::kMessageWarning: {
1157+ Environment* env = Environment::GetCurrent(isolate);
1158+ if (!env) {
1159+ break;
1160+ }
1161+ Utf8Value filename(isolate,
1162+ message->GetScriptOrigin().ResourceName());
1163+ // (filename):(line) (message)
1164+ std::stringstream warning;
1165+ warning << *filename;
1166+ warning << ":";
1167+ warning << message->GetLineNumber(env->context()).FromMaybe(-1);
1168+ warning << " ";
1169+ v8::String::Utf8Value msg(isolate, message->Get());
1170+ warning << *msg;
1171+ USE(ProcessEmitWarningGeneric(env, warning.str().c_str(), "V8"));
1172+ break;
1173+ }
1174+ case Isolate::MessageErrorLevel::kMessageError:
1175+ FatalException(isolate, error, message);
1176+ break;
1177+ }
1178+ }
1179+
11591180
11601181static Local<Object> InitModule(Environment* env,
11611182 node_module* mod,
@@ -2580,7 +2601,9 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
25802601 v8_platform.Platform()->RegisterIsolate(isolate, event_loop);
25812602 Isolate::Initialize(isolate, params);
25822603
2583- isolate->AddMessageListener(OnMessage);
2604+ isolate->AddMessageListenerWithErrorLevel(OnMessage,
2605+ Isolate::MessageErrorLevel::kMessageError |
2606+ Isolate::MessageErrorLevel::kMessageWarning);
25842607 isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
25852608 isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
25862609 isolate->SetFatalErrorHandler(OnFatalError);
0 commit comments