Commit a6db4bd0 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

Change {this} check for arrow functions in DebugStackTraceIterator

An upcoming CL will remove the COLLECT_NON_LOCALS support of the
ScopeIterator. The DebugStackTraceIterator uses the list of non-locals
to restore the receiver for arrow functions.

This CL extracts the relevant logic into a small helper and calls
it directly.

Change-Id: Ia396fd599e41ca65810497d2f5228619cfdf7cc4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1795347Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63645}
parent e7c2a24e
......@@ -578,6 +578,11 @@ bool ScopeIterator::SetVariableValue(Handle<String> name,
Handle<StringSet> ScopeIterator::GetNonLocals() { return non_locals_; }
bool ScopeIterator::ClosureScopeHasThisReference() const {
return !closure_scope_->has_this_declaration() &&
closure_scope_->HasThisReference();
}
#ifdef DEBUG
// Debug print of the content of the current scope.
void ScopeIterator::DebugPrint() {
......
......@@ -77,6 +77,8 @@ class ScopeIterator {
// Set variable value and return true on success.
bool SetVariableValue(Handle<String> variable_name, Handle<Object> new_value);
bool ClosureScopeHasThisReference() const;
// Populate the set with collected non-local variable names.
Handle<StringSet> GetNonLocals();
......
......@@ -87,13 +87,12 @@ v8::MaybeLocal<v8::Value> DebugStackTraceIterator::GetReceiver() const {
// Arrow function defined in top level function without references to
// variables may have NativeContext as context.
if (!context->IsFunctionContext()) return v8::MaybeLocal<v8::Value>();
ScopeIterator scope_iterator(isolate_, frame_inspector_.get(),
ScopeIterator::COLLECT_NON_LOCALS);
ScopeIterator scope_iterator(isolate_, frame_inspector_.get());
// We lookup this variable in function context only when it is used in arrow
// function otherwise V8 can optimize it out.
if (!scope_iterator.GetNonLocals()->Has(isolate_,
isolate_->factory()->this_string()))
if (!scope_iterator.ClosureScopeHasThisReference()) {
return v8::MaybeLocal<v8::Value>();
}
DisallowHeapAllocation no_gc;
VariableMode mode;
InitializationFlag flag;
......@@ -106,6 +105,7 @@ v8::MaybeLocal<v8::Value> DebugStackTraceIterator::GetReceiver() const {
if (value->IsTheHole(isolate_)) return v8::MaybeLocal<v8::Value>();
return Utils::ToLocal(value);
}
Handle<Object> value = frame_inspector_->GetReceiver();
if (value.is_null() || (value->IsSmi() || !value->IsTheHole(isolate_))) {
return Utils::ToLocal(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