Commit f62653f9 authored by Camillo Bruni's avatar Camillo Bruni Committed by V8 LUCI CQ

[isolate] Clean up MessageHandler::ReportMessage

- Use early return
- Add exception_string read-only root

Change-Id: Iba935a4a0308d21ced2693047fdf217b7f9e62f4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3097884Reviewed-by: 's avatarPatrick Thier <pthier@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76335}
parent 05ff5f0a
......@@ -106,55 +106,55 @@ void MessageHandler::ReportMessage(Isolate* isolate, const MessageLocation* loc,
Handle<JSMessageObject> message) {
v8::Local<v8::Message> api_message_obj = v8::Utils::MessageToLocal(message);
if (api_message_obj->ErrorLevel() == v8::Isolate::kMessageError) {
// We are calling into embedder's code which can throw exceptions.
// Thus we need to save current exception state, reset it to the clean one
// and ignore scheduled exceptions callbacks can throw.
if (api_message_obj->ErrorLevel() != v8::Isolate::kMessageError) {
ReportMessageNoExceptions(isolate, loc, message, v8::Local<v8::Value>());
return;
}
// We pass the exception object into the message handler callback though.
Object exception_object = ReadOnlyRoots(isolate).undefined_value();
if (isolate->has_pending_exception()) {
exception_object = isolate->pending_exception();
}
Handle<Object> exception(exception_object, isolate);
// We are calling into embedder's code which can throw exceptions.
// Thus we need to save current exception state, reset it to the clean one
// and ignore scheduled exceptions callbacks can throw.
Isolate::ExceptionScope exception_scope(isolate);
isolate->clear_pending_exception();
isolate->set_external_caught_exception(false);
// We pass the exception object into the message handler callback though.
Object exception_object = ReadOnlyRoots(isolate).undefined_value();
if (isolate->has_pending_exception()) {
exception_object = isolate->pending_exception();
}
Handle<Object> exception(exception_object, isolate);
// Turn the exception on the message into a string if it is an object.
if (message->argument().IsJSObject()) {
HandleScope scope(isolate);
Handle<Object> argument(message->argument(), isolate);
Isolate::ExceptionScope exception_scope(isolate);
isolate->clear_pending_exception();
isolate->set_external_caught_exception(false);
MaybeHandle<Object> maybe_stringified;
Handle<Object> stringified;
// Make sure we don't leak uncaught internally generated Error objects.
if (argument->IsJSError()) {
maybe_stringified = Object::NoSideEffectsToString(isolate, argument);
} else {
v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate));
catcher.SetVerbose(false);
catcher.SetCaptureMessage(false);
// Turn the exception on the message into a string if it is an object.
if (message->argument().IsJSObject()) {
HandleScope scope(isolate);
Handle<Object> argument(message->argument(), isolate);
maybe_stringified = Object::ToString(isolate, argument);
}
MaybeHandle<Object> maybe_stringified;
Handle<Object> stringified;
// Make sure we don't leak uncaught internally generated Error objects.
if (argument->IsJSError()) {
maybe_stringified = Object::NoSideEffectsToString(isolate, argument);
} else {
v8::TryCatch catcher(reinterpret_cast<v8::Isolate*>(isolate));
catcher.SetVerbose(false);
catcher.SetCaptureMessage(false);
if (!maybe_stringified.ToHandle(&stringified)) {
DCHECK(isolate->has_pending_exception());
isolate->clear_pending_exception();
isolate->set_external_caught_exception(false);
stringified =
isolate->factory()->NewStringFromAsciiChecked("exception");
}
message->set_argument(*stringified);
maybe_stringified = Object::ToString(isolate, argument);
}
v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception);
ReportMessageNoExceptions(isolate, loc, message, api_exception_obj);
} else {
ReportMessageNoExceptions(isolate, loc, message, v8::Local<v8::Value>());
if (!maybe_stringified.ToHandle(&stringified)) {
DCHECK(isolate->has_pending_exception());
isolate->clear_pending_exception();
isolate->set_external_caught_exception(false);
stringified = isolate->factory()->exception_string();
}
message->set_argument(*stringified);
}
v8::Local<v8::Value> api_exception_obj = v8::Utils::ToLocal(exception);
ReportMessageNoExceptions(isolate, loc, message, api_exception_obj);
}
void MessageHandler::ReportMessageNoExceptions(
......
......@@ -198,13 +198,14 @@
V(_, dot_string, ".") \
V(_, dot_switch_tag_string, ".switch_tag") \
V(_, dotAll_string, "dotAll") \
V(_, enumerable_string, "enumerable") \
V(_, element_string, "element") \
V(_, Error_string, "Error") \
V(_, errors_string, "errors") \
V(_, EvalError_string, "EvalError") \
V(_, element_string, "element") \
V(_, enumerable_string, "enumerable") \
V(_, error_to_string, "[object Error]") \
V(_, errors_string, "errors") \
V(_, eval_string, "eval") \
V(_, EvalError_string, "EvalError") \
V(_, exception_string, "exception") \
V(_, exec_string, "exec") \
V(_, false_string, "false") \
V(_, FinalizationRegistry_string, "FinalizationRegistry") \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment