diff options
author | Gus Caplan <me@gus.host> | 2018-11-14 09:06:18 -0600 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2018-11-16 09:16:15 -0600 |
commit | e1aa7301b4118a92a8f056d1bc02e6069886a913 (patch) | |
tree | 28f9f739bc9fd71f42282e4bc5c955d4141c591f /src | |
parent | 5f9b624766d42907001232599e57a99f10810b9d (diff) | |
download | android-node-v8-e1aa7301b4118a92a8f056d1bc02e6069886a913.tar.gz android-node-v8-e1aa7301b4118a92a8f056d1bc02e6069886a913.tar.bz2 android-node-v8-e1aa7301b4118a92a8f056d1bc02e6069886a913.zip |
src: emit warnings from V8
PR-URL: https://github.com/nodejs/node/pull/24365
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/node.cc | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/node.cc b/src/node.cc index 48e8f0a249..f6ec033bbb 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1078,12 +1078,6 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) { // coverity[leaked_storage] } -static void OnMessage(Local<Message> message, Local<Value> error) { - // The current version of V8 sends messages for errors only - // (thus `error` is always set). - FatalException(Isolate::GetCurrent(), error, message); -} - static Maybe<bool> ProcessEmitWarningGeneric(Environment* env, const char* warning, const char* type = nullptr, @@ -1160,6 +1154,33 @@ Maybe<bool> ProcessEmitDeprecationWarning(Environment* env, deprecation_code); } +static void OnMessage(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; + } +} + static Local<Object> InitModule(Environment* env, node_module* mod, @@ -2583,7 +2604,9 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { v8_platform.Platform()->RegisterIsolate(isolate, event_loop); Isolate::Initialize(isolate, params); - isolate->AddMessageListener(OnMessage); + isolate->AddMessageListenerWithErrorLevel(OnMessage, + Isolate::MessageErrorLevel::kMessageError | + Isolate::MessageErrorLevel::kMessageWarning); isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException); isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit); isolate->SetFatalErrorHandler(OnFatalError); |