diff --git a/src/d8/d8.cc b/src/d8/d8.cc index 3ff321ec2b..c709bf852c 100644 --- a/src/d8/d8.cc +++ b/src/d8/d8.cc @@ -1184,10 +1184,9 @@ void PerIsolateData::AddUnhandledPromise(Local promise, Local message, Local exception) { DCHECK_EQ(promise->GetIsolate(), isolate_); - unhandled_promises_.push_back( - std::make_tuple(v8::Global(isolate_, promise), - v8::Global(isolate_, message), - v8::Global(isolate_, exception))); + unhandled_promises_.emplace_back(v8::Global(isolate_, promise), + v8::Global(isolate_, message), + v8::Global(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 message = std::get<1>(tuple).Get(isolate_); Local 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(unhandled_promises_count); } PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) { diff --git a/test/message/message.status b/test/message/message.status index 76dd39dbb0..f3d8d7c995 100644 --- a/test/message/message.status +++ b/test/message/message.status @@ -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], diff --git a/test/message/mjsunit/fail/assert-in-promise-fail-recursive.js b/test/message/mjsunit/fail/assert-in-promise-fail-recursive.js new file mode 100644 index 0000000000..66239c3f90 --- /dev/null +++ b/test/message/mjsunit/fail/assert-in-promise-fail-recursive.js @@ -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()); diff --git a/test/message/mjsunit/fail/assert-in-promise-fail-recursive.out b/test/message/mjsunit/fail/assert-in-promise-fail-recursive.out new file mode 100644 index 0000000000..870a249b84 --- /dev/null +++ b/test/message/mjsunit/fail/assert-in-promise-fail-recursive.out @@ -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 () + at console.log () + at *%(basename)s:12:9 + +1 pending unhandled Promise rejection(s) detected. +