Skip to content

Commit 5d67eec

Browse files
devsnekrvagg
authored andcommitted
src: emit warnings from V8
PR-URL: #24365 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent fa9e03c commit 5d67eec

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

src/node.cc

+30-7
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,6 @@ static void DLOpen(const FunctionCallbackInfo<Value>& args) {
10741074
// coverity[leaked_storage]
10751075
}
10761076

1077-
static void OnMessage(Local<Message> message, Local<Value> error) {
1078-
// The current version of V8 sends messages for errors only
1079-
// (thus `error` is always set).
1080-
FatalException(Isolate::GetCurrent(), error, message);
1081-
}
1082-
10831077
static Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
10841078
const char* warning,
10851079
const char* type = nullptr,
@@ -1156,6 +1150,33 @@ Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
11561150
deprecation_code);
11571151
}
11581152

1153+
static void OnMessage(Local<Message> message, Local<Value> error) {
1154+
Isolate* isolate = message->GetIsolate();
1155+
switch (message->ErrorLevel()) {
1156+
case Isolate::MessageErrorLevel::kMessageWarning: {
1157+
Environment* env = Environment::GetCurrent(isolate);
1158+
if (!env) {
1159+
break;
1160+
}
1161+
Utf8Value filename(isolate,
1162+
message->GetScriptOrigin().ResourceName());
1163+
// (filename):(line) (message)
1164+
std::stringstream warning;
1165+
warning << *filename;
1166+
warning << ":";
1167+
warning << message->GetLineNumber(env->context()).FromMaybe(-1);
1168+
warning << " ";
1169+
v8::String::Utf8Value msg(isolate, message->Get());
1170+
warning << *msg;
1171+
USE(ProcessEmitWarningGeneric(env, warning.str().c_str(), "V8"));
1172+
break;
1173+
}
1174+
case Isolate::MessageErrorLevel::kMessageError:
1175+
FatalException(isolate, error, message);
1176+
break;
1177+
}
1178+
}
1179+
11591180

11601181
static Local<Object> InitModule(Environment* env,
11611182
node_module* mod,
@@ -2580,7 +2601,9 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
25802601
v8_platform.Platform()->RegisterIsolate(isolate, event_loop);
25812602
Isolate::Initialize(isolate, params);
25822603

2583-
isolate->AddMessageListener(OnMessage);
2604+
isolate->AddMessageListenerWithErrorLevel(OnMessage,
2605+
Isolate::MessageErrorLevel::kMessageError |
2606+
Isolate::MessageErrorLevel::kMessageWarning);
25842607
isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
25852608
isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
25862609
isolate->SetFatalErrorHandler(OnFatalError);

test/message/v8_warning.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
require('../common');
4+
5+
function AsmModule() {
6+
'use asm';
7+
8+
function add(a, b) {
9+
a = a | 0;
10+
b = b | 0;
11+
12+
// should be `return (a + b) | 0;`
13+
return a + b;
14+
}
15+
16+
return { add: add };
17+
}
18+
19+
AsmModule();

test/message/v8_warning.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(node:*) V8: *v8_warning.js:* Invalid asm.js: Invalid return type

0 commit comments

Comments
 (0)