[d8] Handle recursively rejected promises

Bug: chromium:1098842
Change-Id: Id29edfda99f49a167a03b5158396a07559c75907
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2270231
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68604}
This commit is contained in:
Camillo Bruni 2020-06-29 17:19:46 +02:00 committed by Commit Bot
parent f9d3d78b8d
commit 83ac374209
4 changed files with 33 additions and 8 deletions

View File

@ -1184,10 +1184,9 @@ void PerIsolateData::AddUnhandledPromise(Local<Promise> promise,
Local<Message> message,
Local<Value> exception) {
DCHECK_EQ(promise->GetIsolate(), isolate_);
unhandled_promises_.push_back(
std::make_tuple(v8::Global<v8::Promise>(isolate_, promise),
v8::Global<v8::Message>(isolate_, message),
v8::Global<v8::Value>(isolate_, exception)));
unhandled_promises_.emplace_back(v8::Global<v8::Promise>(isolate_, promise),
v8::Global<v8::Message>(isolate_, message),
v8::Global<v8::Value>(isolate_, exception));
}
size_t PerIsolateData::GetUnhandledPromiseCount() {
@ -1195,16 +1194,17 @@ size_t PerIsolateData::GetUnhandledPromiseCount() {
}
int PerIsolateData::HandleUnhandledPromiseRejections() {
int unhandled_promises_count = 0;
v8::HandleScope scope(isolate_);
for (auto& tuple : unhandled_promises_) {
// Ignore promises that get added during error reporting.
size_t unhandled_promises_count = unhandled_promises_.size();
for (size_t i = 0; i < unhandled_promises_count; i++) {
const auto& tuple = unhandled_promises_[i];
Local<v8::Message> message = std::get<1>(tuple).Get(isolate_);
Local<v8::Value> value = std::get<2>(tuple).Get(isolate_);
Shell::ReportException(isolate_, message, value);
unhandled_promises_count++;
}
unhandled_promises_.clear();
return unhandled_promises_count;
return static_cast<int>(unhandled_promises_count);
}
PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {

View File

@ -58,6 +58,7 @@
['lite_mode or variant == jitless', {
# TODO(v8:7777): Re-enable once wasm is supported in jitless mode.
'mjsunit/fail/assert-promise-result-wasm-compile-fail': [SKIP],
'mjsunit/fail/assert-in-promise-fail-recursive': [FAIL],
'fail/wasm-*': [SKIP],
'wasm-*': [SKIP],

View File

@ -0,0 +1,12 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let count = 2;
TypeError.prototype.__defineGetter__("name", function () {
if (count <= 0) return;
count--;
WebAssembly.compile();
});
;
console.log(new TypeError());

View File

@ -0,0 +1,12 @@
Error
*%(basename)s:9: Error: WebAssembly.compile(): Argument 0 must be a buffer source
WebAssembly.compile();
^
Error: WebAssembly.compile(): Argument 0 must be a buffer source
at TypeError.name (*%(basename)s:9:15)
at TypeError.toString (<anonymous>)
at console.log (<anonymous>)
at *%(basename)s:12:9
1 pending unhandled Promise rejection(s) detected.