Commit d73a775a authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

Reland "[d8] Avoid recursive unhandled rejected Promise processing"

This is a reland of 66e4c99c

Move recursive check variable onto PerIsolateData to avoid data races.

Original change's description:
> [d8] Avoid recursive unhandled rejected Promise processing
>
> Bug: chromium:1126309
> Change-Id: I9d9d33cd151ed8af5ee8af09b8957eae9df2dcb1
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2410059
> Commit-Queue: Toon Verwaest <verwaest@chromium.org>
> Auto-Submit: Camillo Bruni <cbruni@chromium.org>
> Reviewed-by: Toon Verwaest <verwaest@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#69986}

Bug: chromium:1126309
Change-Id: I83353e891e8987fa6f828e1efd82968b895638b6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2423708Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70080}
parent 07f471fc
...@@ -1142,6 +1142,7 @@ PerIsolateData::PerIsolateData(Isolate* isolate) ...@@ -1142,6 +1142,7 @@ PerIsolateData::PerIsolateData(Isolate* isolate)
if (i::FLAG_expose_async_hooks) { if (i::FLAG_expose_async_hooks) {
async_hooks_wrapper_ = new AsyncHooks(isolate); async_hooks_wrapper_ = new AsyncHooks(isolate);
} }
ignore_unhandled_promises_ = false;
} }
PerIsolateData::~PerIsolateData() { PerIsolateData::~PerIsolateData() {
...@@ -1172,6 +1173,7 @@ MaybeLocal<Context> PerIsolateData::GetTimeoutContext() { ...@@ -1172,6 +1173,7 @@ MaybeLocal<Context> PerIsolateData::GetTimeoutContext() {
} }
void PerIsolateData::RemoveUnhandledPromise(Local<Promise> promise) { void PerIsolateData::RemoveUnhandledPromise(Local<Promise> promise) {
if (ignore_unhandled_promises_) return;
// Remove handled promises from the list // Remove handled promises from the list
DCHECK_EQ(promise->GetIsolate(), isolate_); DCHECK_EQ(promise->GetIsolate(), isolate_);
for (auto it = unhandled_promises_.begin(); it != unhandled_promises_.end(); for (auto it = unhandled_promises_.begin(); it != unhandled_promises_.end();
...@@ -1186,17 +1188,17 @@ void PerIsolateData::RemoveUnhandledPromise(Local<Promise> promise) { ...@@ -1186,17 +1188,17 @@ void PerIsolateData::RemoveUnhandledPromise(Local<Promise> promise) {
void PerIsolateData::AddUnhandledPromise(Local<Promise> promise, void PerIsolateData::AddUnhandledPromise(Local<Promise> promise,
Local<Message> message, Local<Message> message,
Local<Value> exception) { Local<Value> exception) {
if (ignore_unhandled_promises_) return;
DCHECK_EQ(promise->GetIsolate(), isolate_); DCHECK_EQ(promise->GetIsolate(), isolate_);
unhandled_promises_.emplace_back(v8::Global<v8::Promise>(isolate_, promise), unhandled_promises_.emplace_back(v8::Global<v8::Promise>(isolate_, promise),
v8::Global<v8::Message>(isolate_, message), v8::Global<v8::Message>(isolate_, message),
v8::Global<v8::Value>(isolate_, exception)); v8::Global<v8::Value>(isolate_, exception));
} }
size_t PerIsolateData::GetUnhandledPromiseCount() {
return unhandled_promises_.size();
}
int PerIsolateData::HandleUnhandledPromiseRejections() { int PerIsolateData::HandleUnhandledPromiseRejections() {
// Avoid recursive calls to HandleUnhandledPromiseRejections.
if (ignore_unhandled_promises_) return 0;
ignore_unhandled_promises_ = true;
v8::HandleScope scope(isolate_); v8::HandleScope scope(isolate_);
// Ignore promises that get added during error reporting. // Ignore promises that get added during error reporting.
size_t i = 0; size_t i = 0;
......
...@@ -260,7 +260,6 @@ class PerIsolateData { ...@@ -260,7 +260,6 @@ class PerIsolateData {
void AddUnhandledPromise(Local<Promise> promise, Local<Message> message, void AddUnhandledPromise(Local<Promise> promise, Local<Message> message,
Local<Value> exception); Local<Value> exception);
int HandleUnhandledPromiseRejections(); int HandleUnhandledPromiseRejections();
size_t GetUnhandledPromiseCount();
private: private:
friend class Shell; friend class Shell;
...@@ -273,6 +272,7 @@ class PerIsolateData { ...@@ -273,6 +272,7 @@ class PerIsolateData {
Global<Value> realm_shared_; Global<Value> realm_shared_;
std::queue<Global<Function>> set_timeout_callbacks_; std::queue<Global<Function>> set_timeout_callbacks_;
std::queue<Global<Context>> set_timeout_contexts_; std::queue<Global<Context>> set_timeout_contexts_;
bool ignore_unhandled_promises_;
std::vector<std::tuple<Global<Promise>, Global<Message>, Global<Value>>> std::vector<std::tuple<Global<Promise>, Global<Message>, Global<Value>>>
unhandled_promises_; unhandled_promises_;
AsyncHooks* async_hooks_wrapper_; AsyncHooks* async_hooks_wrapper_;
......
...@@ -8,11 +8,4 @@ Error: WebAssembly.compile(): Argument 0 must be a buffer source ...@@ -8,11 +8,4 @@ Error: WebAssembly.compile(): Argument 0 must be a buffer source
at console.log (<anonymous>) at console.log (<anonymous>)
at *%(basename)s:12:9 at *%(basename)s:12:9
*%(basename)s:9: Error: WebAssembly.compile(): Argument 0 must be a buffer source 1 pending unhandled Promise rejection(s) detected.
WebAssembly.compile();
^
Error: WebAssembly.compile(): Argument 0 must be a buffer source
at TypeError.name (*%(basename)s:9:15)
at TypeError.toString (<anonymous>)
2 pending unhandled Promise rejection(s) detected.
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