Skip to content

Commit ffb72f8

Browse files
addaleaxrvagg
authored andcommitted
deps: cherry-pick 09b53ee from upstream V8
Original commit message: [api] Make running scripts in AddMessageListener callback work in debug mode The existance of an `AllowJavascriptExecutionDebugOnly` scope in `Isolate::ReportPendingMessages()` indicates that the API supports running arbitrary JS code in a `AddMessageListener` callback. Currently, this can fail in debug mode: The `!isolate->external_caught_exception()` condition is checked when entering API methods inside such a handler. However, if there is a verbose `TryCatch` active when the exception occurs, this check fails, and when calling `ToString()` on the exception object leaves a pending exception itself, the flag is re-set to `true`. Fix this problem by clearing the flag and the pending exception if there was one during `ToString()`. This matches the code a few lines up in `messages.cc`, so the exception state is now consistent during the callback. This currently makes a Node.js test fail in debug mode (`parallel/test-error-reporting`). Bug: node:7144 Bug: node:17016 Change-Id: I060d00fea3e9a497f4df34c6ff8d6e29ebe96321 Reviewed-on: https://chromium-review.googlesource.com/718096 Commit-Queue: Yang Guo <yangguo@chromium.org> Reviewed-by: Yang Guo <yangguo@chromium.org> Cr-Commit-Position: refs/heads/master@{#49466} Refs: v8/v8@09b53ee PR-URL: #21767 Refs: v8/v8@09b53ee Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent 6f545d1 commit ffb72f8

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

deps/v8/AUTHORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Alexis Campailla <alexis@janeasystems.com>
4242
Andreas Anyuru <andreas.anyuru@gmail.com>
4343
Andrew Paprocki <andrew@ishiboo.com>
4444
Andrei Kashcha <anvaka@gmail.com>
45-
Anna Henningsen <addaleax@gmail.com>
45+
Anna Henningsen <anna@addaleax.net>
4646
Bangfu Tao <bangfu.tao@samsung.com>
4747
Ben Noordhuis <info@bnoordhuis.nl>
4848
Benjamin Tan <demoneaux@gmail.com>

deps/v8/include/v8-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 6
1212
#define V8_MINOR_VERSION 2
1313
#define V8_BUILD_NUMBER 414
14-
#define V8_PATCH_LEVEL 61
14+
#define V8_PATCH_LEVEL 62
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/messages.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ void MessageHandler::ReportMessage(Isolate* isolate, const MessageLocation* loc,
114114
}
115115

116116
if (!maybe_stringified.ToHandle(&stringified)) {
117+
DCHECK(isolate->has_pending_exception());
118+
isolate->clear_pending_exception();
119+
isolate->set_external_caught_exception(false);
117120
stringified =
118121
isolate->factory()->NewStringFromAsciiChecked("exception");
119122
}

deps/v8/test/cctest/test-api.cc

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5747,23 +5747,55 @@ TEST(CustomErrorMessage) {
57475747

57485748
static void check_custom_rethrowing_message(v8::Local<v8::Message> message,
57495749
v8::Local<v8::Value> data) {
5750+
CHECK(data->IsExternal());
5751+
int* callcount = static_cast<int*>(data.As<v8::External>()->Value());
5752+
++*callcount;
5753+
57505754
const char* uncaught_error = "Uncaught exception";
57515755
CHECK(message->Get()
57525756
->Equals(CcTest::isolate()->GetCurrentContext(),
57535757
v8_str(uncaught_error))
57545758
.FromJust());
5759+
// Test that compiling code inside a message handler works.
5760+
CHECK(CompileRunChecked(CcTest::isolate(), "(function(a) { return a; })(42)")
5761+
->Equals(CcTest::isolate()->GetCurrentContext(),
5762+
v8::Integer::NewFromUnsigned(CcTest::isolate(), 42))
5763+
.FromJust());
57555764
}
57565765

57575766

57585767
TEST(CustomErrorRethrowsOnToString) {
5768+
int callcount = 0;
57595769
LocalContext context;
5760-
v8::HandleScope scope(context->GetIsolate());
5761-
context->GetIsolate()->AddMessageListener(check_custom_rethrowing_message);
5770+
v8::Isolate* isolate = context->GetIsolate();
5771+
v8::HandleScope scope(isolate);
5772+
context->GetIsolate()->AddMessageListener(
5773+
check_custom_rethrowing_message, v8::External::New(isolate, &callcount));
5774+
5775+
CompileRun(
5776+
"var e = { toString: function() { throw e; } };"
5777+
"try { throw e; } finally {}");
5778+
5779+
CHECK_EQ(callcount, 1);
5780+
context->GetIsolate()->RemoveMessageListeners(
5781+
check_custom_rethrowing_message);
5782+
}
5783+
5784+
TEST(CustomErrorRethrowsOnToStringInsideVerboseTryCatch) {
5785+
int callcount = 0;
5786+
LocalContext context;
5787+
v8::Isolate* isolate = context->GetIsolate();
5788+
v8::HandleScope scope(isolate);
5789+
v8::TryCatch try_catch(isolate);
5790+
try_catch.SetVerbose(true);
5791+
context->GetIsolate()->AddMessageListener(
5792+
check_custom_rethrowing_message, v8::External::New(isolate, &callcount));
57625793

57635794
CompileRun(
57645795
"var e = { toString: function() { throw e; } };"
57655796
"try { throw e; } finally {}");
57665797

5798+
CHECK_EQ(callcount, 1);
57675799
context->GetIsolate()->RemoveMessageListeners(
57685800
check_custom_rethrowing_message);
57695801
}

0 commit comments

Comments
 (0)