Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: emit warnings from V8 #24365

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
refack marked this conversation as resolved.
Show resolved Hide resolved
Environment* env = Environment::GetCurrent(isolate);
if (!env) {
break;
}
Utf8Value filename(isolate,
message->GetScriptOrigin().ResourceName());
// (filename):(line) (message)
refack marked this conversation as resolved.
Show resolved Hide resolved
std::stringstream warning;
warning << *filename;
warning << ":";
warning << message->GetLineNumber(env->context()).FromMaybe(-1);
warning << " ";
v8::String::Utf8Value msg(isolate, message->Get());
warning << *msg;
devsnek marked this conversation as resolved.
Show resolved Hide resolved
USE(ProcessEmitWarningGeneric(env, warning.str().c_str(), "V8"));
break;
}
case Isolate::MessageErrorLevel::kMessageError:
FatalException(isolate, error, message);
devsnek marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}


static Local<Object> InitModule(Environment* env,
node_module* mod,
Expand Down Expand Up @@ -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);
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