Commit 40245b75 authored by tzik's avatar tzik Committed by Commit Bot

Use Isolate::GetEnteredOrMicrotaskContext instead of GetEnteredContext

This CL replaces most of Isolate::GetEnteredContext with
GetEnteredOrMicrotaskContext, as it should be more relevant.

Here is a brief overview of the series of changes.
https://docs.google.com/document/d/1MY_xlsYS7E6_qbwwY66-FH3JkAYeTHBlF5qVBrBpWyY/edit#heading=h.fx2rezbyzz5c

Bug: v8:8124
Change-Id: I27355e325a92094240c25b672d1219f3214a9da0
Reviewed-on: https://chromium-review.googlesource.com/c/1297654Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57470}
parent 08eed80c
......@@ -137,6 +137,12 @@ Handle<Context> HandleScopeImplementer::LastEnteredContext() {
return Handle<Context>(entered_contexts_.back(), isolate_);
}
Handle<Context> HandleScopeImplementer::LastEnteredOrMicrotaskContext() {
if (MicrotaskContextIsLastEnteredContext()) return MicrotaskContext();
if (entered_contexts_.empty()) return Handle<Context>::null();
return Handle<Context>(entered_contexts_.back(), isolate_);
}
} // namespace internal
} // namespace v8
......
......@@ -8004,13 +8004,8 @@ v8::Local<v8::Context> Isolate::GetEnteredContext() {
v8::Local<v8::Context> Isolate::GetEnteredOrMicrotaskContext() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
i::Handle<i::Object> last;
if (isolate->handle_scope_implementer()
->MicrotaskContextIsLastEnteredContext()) {
last = isolate->handle_scope_implementer()->MicrotaskContext();
} else {
last = isolate->handle_scope_implementer()->LastEnteredContext();
}
i::Handle<i::Object> last =
isolate->handle_scope_implementer()->LastEnteredOrMicrotaskContext();
if (last.is_null()) return Local<Context>();
DCHECK(last->IsNativeContext());
return Utils::ToLocal(i::Handle<i::Context>::cast(last));
......
......@@ -397,6 +397,7 @@ class HandleScopeImplementer {
// Returns the last entered context or an empty handle if no
// contexts have been entered.
inline Handle<Context> LastEnteredContext();
inline Handle<Context> LastEnteredOrMicrotaskContext();
inline void EnterMicrotaskContext(Handle<Context> context);
inline void LeaveMicrotaskContext();
......
......@@ -361,9 +361,7 @@ bool Builtins::AllowDynamicFunction(Isolate* isolate, Handle<JSFunction> target,
Handle<JSObject> target_global_proxy) {
if (FLAG_allow_unsafe_function_constructor) return true;
HandleScopeImplementer* impl = isolate->handle_scope_implementer();
Handle<Context> responsible_context =
impl->MicrotaskContextIsLastEnteredContext() ? impl->MicrotaskContext()
: impl->LastEnteredContext();
Handle<Context> responsible_context = impl->LastEnteredOrMicrotaskContext();
// TODO(jochen): Remove this.
if (responsible_context.is_null()) {
return true;
......
......@@ -926,7 +926,7 @@ PerIsolateData::RealmScope::RealmScope(PerIsolateData* data) : data_(data) {
data_->realm_switch_ = 0;
data_->realms_ = new Global<Context>[1];
data_->realms_[0].Reset(data_->isolate_,
data_->isolate_->GetEnteredContext());
data_->isolate_->GetEnteredOrMicrotaskContext());
}
......@@ -993,7 +993,7 @@ void Shell::PerformanceNow(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Shell::RealmCurrent(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = args.GetIsolate();
PerIsolateData* data = PerIsolateData::Get(isolate);
int index = data->RealmFind(isolate->GetEnteredContext());
int index = data->RealmFind(isolate->GetEnteredOrMicrotaskContext());
if (index == -1) return;
args.GetReturnValue().Set(index);
}
......@@ -1076,7 +1076,7 @@ void Shell::RealmCreateAllowCrossRealmAccess(
Local<Context> context;
if (CreateRealm(args, -1, v8::MaybeLocal<Value>()).ToLocal(&context)) {
context->SetSecurityToken(
args.GetIsolate()->GetEnteredContext()->GetSecurityToken());
args.GetIsolate()->GetEnteredOrMicrotaskContext()->GetSecurityToken());
}
}
......
......@@ -466,7 +466,8 @@ size_t V8Debugger::nearHeapLimitCallback(void* data, size_t current_heap_limit,
V8Debugger* thisPtr = static_cast<V8Debugger*>(data);
thisPtr->m_originalHeapLimit = current_heap_limit;
thisPtr->m_scheduledOOMBreak = true;
v8::Local<v8::Context> context = thisPtr->m_isolate->GetEnteredContext();
v8::Local<v8::Context> context =
thisPtr->m_isolate->GetEnteredOrMicrotaskContext();
thisPtr->m_targetContextGroupId =
context.IsEmpty() ? 0 : thisPtr->m_inspector->contextGroupId(context);
thisPtr->m_isolate->RequestInterrupt(
......
......@@ -2426,12 +2426,12 @@ Handle<Context> Isolate::GetIncumbentContext() {
*top_backup_incumbent_scope()->backup_incumbent_context_);
}
// Last candidate: the entered context.
// Last candidate: the entered context or microtask context.
// Given that there is no other author function is running, there must be
// no cross-context function running, then the incumbent realm must match
// the entry realm.
v8::Local<v8::Context> entered_context =
reinterpret_cast<v8::Isolate*>(this)->GetEnteredContext();
reinterpret_cast<v8::Isolate*>(this)->GetEnteredOrMicrotaskContext();
return Utils::OpenHandle(*entered_context);
}
......
......@@ -246,7 +246,7 @@ void IsolateData::DumpAsyncTaskStacksStateForTest() {
int IsolateData::HandleMessage(v8::Local<v8::Message> message,
v8::Local<v8::Value> exception) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = isolate->GetEnteredContext();
v8::Local<v8::Context> context = isolate->GetEnteredOrMicrotaskContext();
if (context.IsEmpty()) return 0;
v8_inspector::V8Inspector* inspector =
IsolateData::FromContext(context)->inspector_.get();
......@@ -289,7 +289,7 @@ void IsolateData::MessageHandler(v8::Local<v8::Message> message,
// static
void IsolateData::PromiseRejectHandler(v8::PromiseRejectMessage data) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::Local<v8::Context> context = isolate->GetEnteredContext();
v8::Local<v8::Context> context = isolate->GetEnteredOrMicrotaskContext();
if (context.IsEmpty()) return;
v8::Local<v8::Promise> promise = data.GetPromise();
v8::Local<v8::Private> id_private = v8::Private::ForApi(
......
......@@ -45,14 +45,14 @@ function connect(contextGroup, num) {
await session2.Protocol.Runtime.evaluate({expression: 'var p2; setTimeout(() => { p2 = Promise.reject("error5") }, 0)'});
await InspectorTest.waitForPendingTasks();
InspectorTest.log('Revoking in 2');
await session2.Protocol.Runtime.evaluate({expression: 'setTimeout(() => { p2.catch() }, 0);'});
await session2.Protocol.Runtime.evaluate({expression: 'setTimeout(() => { p2.catch(()=>{}) }, 0);'});
await InspectorTest.waitForPendingTasks();
InspectorTest.log('Rejecting in 1');
await session1.Protocol.Runtime.evaluate({expression: 'var p1; setTimeout(() => { p1 = Promise.reject("error6")} , 0)'});
await InspectorTest.waitForPendingTasks();
InspectorTest.log('Revoking in 1');
await session1.Protocol.Runtime.evaluate({expression: 'setTimeout(() => { p1.catch() }, 0);'});
await session1.Protocol.Runtime.evaluate({expression: 'setTimeout(() => { p1.catch(()=>{}) }, 0);'});
await InspectorTest.waitForPendingTasks();
InspectorTest.completeTest();
......
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