src: move OnMessage to node_errors.cc

Rename the per-isolate message listener to `PerIsolateMessageListener`
and move it to `node_errors.cc` since it's part of the error
handling process. It also creates an external reference so it needs
to be exposed in `node_errors.h` for a snapshot builder to know.

PR-URL: https://github.com/nodejs/node/pull/27304
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Joyee Cheung committed 2019-04-26 19:03:14 +08:00
1 parent e029b927c2
commit 744cdecbf4
3 files changed
+30 -28

No files matched your search

+27
View File
@@ -6,6 +6,7 @@
#ifdef NODE_REPORT
#include "node_report.h"
#endif
#include "node_process.h"
#include "node_v8_platform-inl.h"
namespace node {
@@ -739,6 +740,32 @@ const char* errno_string(int errorno) {
}
}
void PerIsolateMessageListener(Local<Message> message, Local<Value> error) {
Isolate* isolate = message->GetIsolate();
switch (message->ErrorLevel()) {
case Isolate::MessageErrorLevel::kMessageWarning: {
Environment* env = Environment::GetCurrent(isolate);
if (!env) {
break;
}
Utf8Value filename(isolate, message->GetScriptOrigin().ResourceName());
// (filename):(line) (message)
std::stringstream warning;
warning << *filename;
warning << ":";
warning << message->GetLineNumber(env->context()).FromMaybe(-1);
warning << " ";
v8::String::Utf8Value msg(isolate, message->Get());
warning << *msg;
USE(ProcessEmitWarningGeneric(env, warning.str().c_str(), "V8"));
break;
}
case Isolate::MessageErrorLevel::kMessageError:
FatalException(isolate, error, message);
break;
}
}
} // namespace errors
void DecorateErrorStack(Environment* env,