Skip to content

Commit

Permalink
src: emit warnings from V8
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
devsnek authored and rvagg committed Nov 28, 2018
1 parent fa9e03c commit 5d67eec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
37 changes: 30 additions & 7 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1074,12 +1074,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,
Expand Down Expand Up @@ -1156,6 +1150,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,
Expand Down Expand Up @@ -2580,7 +2601,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);
Expand Down
19 changes: 19 additions & 0 deletions test/message/v8_warning.js
Original file line number Diff line number Diff line change
@@ -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();
1 change: 1 addition & 0 deletions test/message/v8_warning.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type

0 comments on commit 5d67eec

Please sign in to comment.