Commit f3774fde authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[debugger] Fix debug-evaluate for context-allocated this.

When `this` is context allocated inside a class constructor (strict mode
function), due to an arrow function, debug evaluate was unable to locate
the value. This is quick fix for the issue, which probably deserves a
more general rewrite at some later point in time (with more domain
expertise).

Bug: chromium:760225
Change-Id: I5208d8a202ad69439f60ada480599d0efcdc4ce4
Cq-Include-Trybots: luci.chromium.try:linux-rel,win7-rel
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1687412
Commit-Queue: Yang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62532}
parent c72b5be0
......@@ -615,9 +615,16 @@ bool ScopeIterator::VisitContextLocals(const Visitor& visitor,
bool ScopeIterator::VisitLocals(const Visitor& visitor, Mode mode) const {
if (mode == Mode::STACK && current_scope_->is_declaration_scope() &&
current_scope_->AsDeclarationScope()->has_this_declaration()) {
Handle<Object> receiver = frame_inspector_ == nullptr
? handle(generator_->receiver(), isolate_)
: frame_inspector_->GetReceiver();
// TODO(bmeurer): We should refactor the general variable lookup
// around "this", since the current way is rather hacky when the
// receiver is context-allocated.
auto this_var = current_scope_->AsDeclarationScope()->receiver();
Handle<Object> receiver =
this_var->location() == VariableLocation::CONTEXT
? handle(context_->get(this_var->index()), isolate_)
: frame_inspector_ == nullptr
? handle(generator_->receiver(), isolate_)
: frame_inspector_->GetReceiver();
if (receiver->IsOptimizedOut(isolate_) || receiver->IsTheHole(isolate_)) {
receiver = isolate_->factory()->undefined_value();
}
......
// Copyright 2019 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.
Debug = debug.Debug
let thisValue;
function listener(event, exec_state, event_data, data) {
if (event == Debug.DebugEvent.Break) {
thisValue = exec_state.frame(0).evaluate('this').value();
}
};
Debug.setListener(listener);
class Foo {}
class Bar extends Foo {
constructor() {
super();
var b = () => this;
this.c = 'b'; // <-- Inspect 'this' (it will be undefined)
debugger;
}
}
new Bar();
Debug.setListener(null);
assertNotEquals(undefined, thisValue);
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