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

[d8] Use more conservative error reporting in d8's async-hooks

d8 throws on unhandled rejected Promises since
https://crrev.com/c/2238569 so no special handling beyond throwing in
the async hooks themselves is needed.

Drive-by-fix: Use v8::Isolate* as local variable.

Bug: chromium:1238467
Change-Id: I271720cd9cfd1d30b58b5407c700b0f730910968
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3090333
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76255}
parent 44b4a504
...@@ -120,67 +120,63 @@ Local<Object> AsyncHooks::CreateHook( ...@@ -120,67 +120,63 @@ Local<Object> AsyncHooks::CreateHook(
void AsyncHooks::ShellPromiseHook(PromiseHookType type, Local<Promise> promise, void AsyncHooks::ShellPromiseHook(PromiseHookType type, Local<Promise> promise,
Local<Value> parent) { Local<Value> parent) {
AsyncHooks* hooks = v8::Isolate* isolate = promise->GetIsolate();
PerIsolateData::Get(promise->GetIsolate())->GetAsyncHooks(); AsyncHooks* hooks = PerIsolateData::Get(isolate)->GetAsyncHooks();
HandleScope handle_scope(hooks->isolate_); HandleScope handle_scope(isolate);
TryCatch try_catch(isolate);
try_catch.SetVerbose(true);
Local<Context> currentContext = hooks->isolate_->GetCurrentContext(); Local<Context> currentContext = isolate->GetCurrentContext();
DCHECK(!currentContext.IsEmpty()); DCHECK(!currentContext.IsEmpty());
if (type == PromiseHookType::kInit) { if (type == PromiseHookType::kInit) {
++hooks->current_async_id; ++hooks->current_async_id;
Local<Integer> async_id = Local<Integer> async_id = Integer::New(isolate, hooks->current_async_id);
Integer::New(hooks->isolate_, hooks->current_async_id);
CHECK(!promise CHECK(!promise->HasPrivate(currentContext, hooks->async_id_smb.Get(isolate))
->HasPrivate(currentContext,
hooks->async_id_smb.Get(hooks->isolate_))
.ToChecked()); .ToChecked());
promise->SetPrivate(currentContext, promise->SetPrivate(currentContext, hooks->async_id_smb.Get(isolate),
hooks->async_id_smb.Get(hooks->isolate_), async_id); async_id);
if (parent->IsPromise()) { if (parent->IsPromise()) {
Local<Promise> parent_promise = parent.As<Promise>(); Local<Promise> parent_promise = parent.As<Promise>();
Local<Value> parent_async_id = Local<Value> parent_async_id =
parent_promise parent_promise
->GetPrivate(hooks->isolate_->GetCurrentContext(), ->GetPrivate(isolate->GetCurrentContext(),
hooks->async_id_smb.Get(hooks->isolate_)) hooks->async_id_smb.Get(isolate))
.ToLocalChecked(); .ToLocalChecked();
promise->SetPrivate(currentContext, promise->SetPrivate(currentContext, hooks->trigger_id_smb.Get(isolate),
hooks->trigger_id_smb.Get(hooks->isolate_),
parent_async_id); parent_async_id);
} else { } else {
CHECK(parent->IsUndefined()); CHECK(parent->IsUndefined());
Local<Integer> trigger_id = Integer::New(hooks->isolate_, 0); Local<Integer> trigger_id = Integer::New(isolate, 0);
promise->SetPrivate(currentContext, promise->SetPrivate(currentContext, hooks->trigger_id_smb.Get(isolate),
hooks->trigger_id_smb.Get(hooks->isolate_),
trigger_id); trigger_id);
} }
} else if (type == PromiseHookType::kBefore) { } else if (type == PromiseHookType::kBefore) {
AsyncContext ctx; AsyncContext ctx;
ctx.execution_async_id = ctx.execution_async_id = promise
promise ->GetPrivate(isolate->GetCurrentContext(),
->GetPrivate(hooks->isolate_->GetCurrentContext(), hooks->async_id_smb.Get(isolate))
hooks->async_id_smb.Get(hooks->isolate_)) .ToLocalChecked()
.ToLocalChecked() .As<Integer>()
.As<Integer>() ->Value();
->Value(); ctx.trigger_async_id = promise
ctx.trigger_async_id = ->GetPrivate(isolate->GetCurrentContext(),
promise hooks->trigger_id_smb.Get(isolate))
->GetPrivate(hooks->isolate_->GetCurrentContext(), .ToLocalChecked()
hooks->trigger_id_smb.Get(hooks->isolate_)) .As<Integer>()
.ToLocalChecked() ->Value();
.As<Integer>()
->Value();
hooks->asyncContexts.push(ctx); hooks->asyncContexts.push(ctx);
} else if (type == PromiseHookType::kAfter) { } else if (type == PromiseHookType::kAfter) {
hooks->asyncContexts.pop(); hooks->asyncContexts.pop();
} }
for (AsyncHooksWrap* wrap : hooks->async_wraps_) { for (AsyncHooksWrap* wrap : hooks->async_wraps_) {
PromiseHookDispatch(type, promise, parent, wrap, hooks); PromiseHookDispatch(type, promise, parent, wrap, hooks);
if (try_catch.HasCaught()) break;
} }
if (try_catch.HasCaught()) Shell::ReportException(isolate, &try_catch);
} }
void AsyncHooks::Initialize() { void AsyncHooks::Initialize() {
...@@ -215,24 +211,9 @@ void AsyncHooks::PromiseHookDispatch(PromiseHookType type, ...@@ -215,24 +211,9 @@ void AsyncHooks::PromiseHookDispatch(PromiseHookType type,
Local<Promise> promise, Local<Promise> promise,
Local<Value> parent, AsyncHooksWrap* wrap, Local<Value> parent, AsyncHooksWrap* wrap,
AsyncHooks* hooks) { AsyncHooks* hooks) {
if (!wrap->IsEnabled()) { if (!wrap->IsEnabled()) return;
return;
}
HandleScope handle_scope(hooks->isolate_); HandleScope handle_scope(hooks->isolate_);
TryCatch try_catch(hooks->isolate_);
try_catch.SetVerbose(true);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(hooks->isolate_);
if (isolate->has_scheduled_exception()) {
isolate->ScheduleThrow(isolate->scheduled_exception());
DCHECK(try_catch.HasCaught());
Shell::ReportException(hooks->isolate_, &try_catch);
return;
}
Local<Value> rcv = Undefined(hooks->isolate_); Local<Value> rcv = Undefined(hooks->isolate_);
Local<Context> context = hooks->isolate_->GetCurrentContext(); Local<Context> context = hooks->isolate_->GetCurrentContext();
Local<Value> async_id = Local<Value> async_id =
......
// Copyright 2021 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.
// Flags: --expose-async-hooks --ignore-unhandled-promises
const ah = async_hooks.createHook({});
ah.enable();
import("./does_not_exist.js").then();
function target() {
isFinite.__proto__.__proto__ = new Proxy(target, {
get() {
return Promise.resolve();
}})
}
target();
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