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>
pull/24365/head
Gus Caplan 2018-11-14 09:06:18 -06:00
parent 5f9b624766
commit e1aa7301b4
No known key found for this signature in database
GPG Key ID: F00BD11880E82F0E
3 changed files with 50 additions and 7 deletions

View File

@ -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);

View File

@ -0,0 +1,19 @@
'use strict';
require('../common');
function AsmModule() {
'use asm';
function add(a, b) {
a = a | 0;
b = b | 0;
// should be `return (a + b) | 0;`
return a + b;
}
return { add: add };
}
AsmModule();

View File

@ -0,0 +1 @@
(node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type