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

[runtime] Cleaning up PromiseHook runtime functions

- remove redundant checks
- use switch over PromiseHookType

Change-Id: I89a5328009634a7025feb77e22334773c2886868
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2224225Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68210}
parent f3dd0f48
...@@ -4142,54 +4142,57 @@ void Isolate::RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise, ...@@ -4142,54 +4142,57 @@ void Isolate::RunPromiseHook(PromiseHookType type, Handle<JSPromise> promise,
void Isolate::RunPromiseHookForAsyncEventDelegate(PromiseHookType type, void Isolate::RunPromiseHookForAsyncEventDelegate(PromiseHookType type,
Handle<JSPromise> promise) { Handle<JSPromise> promise) {
if (!async_event_delegate_) return; if (!async_event_delegate_) return;
if (type == PromiseHookType::kResolve) return; switch (type) {
case PromiseHookType::kResolve:
if (type == PromiseHookType::kBefore) { return;
if (!promise->async_task_id()) return; case PromiseHookType::kBefore:
async_event_delegate_->AsyncEventOccurred(debug::kDebugWillHandle, if (!promise->async_task_id()) return;
promise->async_task_id(), false); async_event_delegate_->AsyncEventOccurred(
} else if (type == PromiseHookType::kAfter) { debug::kDebugWillHandle, promise->async_task_id(), false);
if (!promise->async_task_id()) return; break;
async_event_delegate_->AsyncEventOccurred(debug::kDebugDidHandle, case PromiseHookType::kAfter:
promise->async_task_id(), false); if (!promise->async_task_id()) return;
} else { async_event_delegate_->AsyncEventOccurred(
DCHECK(type == PromiseHookType::kInit); debug::kDebugDidHandle, promise->async_task_id(), false);
debug::DebugAsyncActionType type = debug::kDebugPromiseThen; break;
bool last_frame_was_promise_builtin = false; case PromiseHookType::kInit:
JavaScriptFrameIterator it(this); debug::DebugAsyncActionType type = debug::kDebugPromiseThen;
while (!it.done()) { bool last_frame_was_promise_builtin = false;
std::vector<Handle<SharedFunctionInfo>> infos; JavaScriptFrameIterator it(this);
it.frame()->GetFunctions(&infos); while (!it.done()) {
for (size_t i = 1; i <= infos.size(); ++i) { std::vector<Handle<SharedFunctionInfo>> infos;
Handle<SharedFunctionInfo> info = infos[infos.size() - i]; it.frame()->GetFunctions(&infos);
if (info->IsUserJavaScript()) { for (size_t i = 1; i <= infos.size(); ++i) {
// We should not report PromiseThen and PromiseCatch which is called Handle<SharedFunctionInfo> info = infos[infos.size() - i];
// indirectly, e.g. Promise.all calls Promise.then internally. if (info->IsUserJavaScript()) {
if (last_frame_was_promise_builtin) { // We should not report PromiseThen and PromiseCatch which is called
if (!promise->async_task_id()) { // indirectly, e.g. Promise.all calls Promise.then internally.
promise->set_async_task_id(++async_task_count_); if (last_frame_was_promise_builtin) {
if (!promise->async_task_id()) {
promise->set_async_task_id(++async_task_count_);
}
async_event_delegate_->AsyncEventOccurred(
type, promise->async_task_id(), debug()->IsBlackboxed(info));
} }
async_event_delegate_->AsyncEventOccurred( return;
type, promise->async_task_id(), debug()->IsBlackboxed(info));
} }
return; last_frame_was_promise_builtin = false;
} if (info->HasBuiltinId()) {
last_frame_was_promise_builtin = false; if (info->builtin_id() == Builtins::kPromisePrototypeThen) {
if (info->HasBuiltinId()) { type = debug::kDebugPromiseThen;
if (info->builtin_id() == Builtins::kPromisePrototypeThen) { last_frame_was_promise_builtin = true;
type = debug::kDebugPromiseThen; } else if (info->builtin_id() == Builtins::kPromisePrototypeCatch) {
last_frame_was_promise_builtin = true; type = debug::kDebugPromiseCatch;
} else if (info->builtin_id() == Builtins::kPromisePrototypeCatch) { last_frame_was_promise_builtin = true;
type = debug::kDebugPromiseCatch; } else if (info->builtin_id() ==
last_frame_was_promise_builtin = true; Builtins::kPromisePrototypeFinally) {
} else if (info->builtin_id() == Builtins::kPromisePrototypeFinally) { type = debug::kDebugPromiseFinally;
type = debug::kDebugPromiseFinally; last_frame_was_promise_builtin = true;
last_frame_was_promise_builtin = true; }
} }
} }
it.Advance();
} }
it.Advance();
}
} }
} }
......
...@@ -217,10 +217,8 @@ RUNTIME_FUNCTION(Runtime_PromiseHookBefore) { ...@@ -217,10 +217,8 @@ RUNTIME_FUNCTION(Runtime_PromiseHookBefore) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
Handle<JSPromise> promise = Handle<JSPromise>::cast(maybe_promise); Handle<JSPromise> promise = Handle<JSPromise>::cast(maybe_promise);
if (isolate->debug()->is_active()) isolate->PushPromise(promise); if (isolate->debug()->is_active()) isolate->PushPromise(promise);
if (promise->IsJSPromise()) { isolate->RunPromiseHook(PromiseHookType::kBefore, promise,
isolate->RunPromiseHook(PromiseHookType::kBefore, promise, isolate->factory()->undefined_value());
isolate->factory()->undefined_value());
}
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
...@@ -232,10 +230,8 @@ RUNTIME_FUNCTION(Runtime_PromiseHookAfter) { ...@@ -232,10 +230,8 @@ RUNTIME_FUNCTION(Runtime_PromiseHookAfter) {
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
Handle<JSPromise> promise = Handle<JSPromise>::cast(maybe_promise); Handle<JSPromise> promise = Handle<JSPromise>::cast(maybe_promise);
if (isolate->debug()->is_active()) isolate->PopPromise(); if (isolate->debug()->is_active()) isolate->PopPromise();
if (promise->IsJSPromise()) { isolate->RunPromiseHook(PromiseHookType::kAfter, promise,
isolate->RunPromiseHook(PromiseHookType::kAfter, promise, isolate->factory()->undefined_value());
isolate->factory()->undefined_value());
}
return ReadOnlyRoots(isolate).undefined_value(); return ReadOnlyRoots(isolate).undefined_value();
} }
......
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