8ab1c88c01
This CL adds "new.target" to the ScopeObject with the materialized stack local variables. It's only available if the parser actually allocates a variable for it, otherwise we currently throw a ReferenceError. The added test also ensures that "new.target" is only included for debug-evaluate, but NOT for the scope view. Having ".new.target" show up there would be more confusing than helpful. Drive-by: Remove bogus DCHECK. The context we try to lookup "new.target" can be anything, not just a `with` context. R=bmeurer@chromium.org, leszeks@chromium.org Bug: chromium:1246863 Change-Id: Id4f99b3336044904e3dc76912f65b6f63f092258 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4003039 Reviewed-by: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Simon Zünd <szuend@chromium.org> Cr-Commit-Position: refs/heads/main@{#84069}
84 lines
2.2 KiB
JavaScript
84 lines
2.2 KiB
JavaScript
// Copyright 2022 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.
|
|
|
|
const {session, contextGroup, Protocol} =
|
|
InspectorTest.start(`Test that new.target can be inspected in Debugger.evaluateOnCallFrame`);
|
|
|
|
contextGroup.addScript(`
|
|
function C() {
|
|
const fn = new.target;
|
|
debugger;
|
|
}
|
|
|
|
function D() {
|
|
const fn = eval('new.target');
|
|
debugger;
|
|
}
|
|
|
|
function E() {
|
|
debugger;
|
|
}
|
|
|
|
class A {
|
|
constructor() {
|
|
const fn = new.target;
|
|
debugger;
|
|
}
|
|
}
|
|
|
|
class B extends A {}
|
|
|
|
function F() {
|
|
() => new.target; // context-allocate.
|
|
debugger;
|
|
}
|
|
`);
|
|
|
|
async function ensureNewTargetIsNotReportedInTheScopeChain(scopeChain) {
|
|
for (const scope of scopeChain) {
|
|
if (scope.type !== 'local') continue;
|
|
const {result: {result: variables}} =
|
|
await Protocol.Runtime.getProperties({ objectId: scope.object.objectId });
|
|
const variable = variables.find(variable => variable.name === '.new.target');
|
|
if (variable) {
|
|
InspectorTest.logMessage(`FAIL: 'new.target' was also reported in the scopeChain on Debugger.paused`);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function evaluateNewTargetOnPause(expression) {
|
|
await Protocol.Debugger.enable();
|
|
Protocol.Runtime.evaluate({ expression });
|
|
|
|
const { params: { callFrames: [{ callFrameId, scopeChain }] } } = await Protocol.Debugger.oncePaused();
|
|
await ensureNewTargetIsNotReportedInTheScopeChain(scopeChain);
|
|
|
|
const { result: { result } } = await Protocol.Debugger.evaluateOnCallFrame({
|
|
callFrameId,
|
|
expression: 'new.target',
|
|
});
|
|
InspectorTest.logMessage(result);
|
|
|
|
await Protocol.Debugger.resume();
|
|
await Protocol.Debugger.disable();
|
|
}
|
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
async function withExplicitUsage() {
|
|
await evaluateNewTargetOnPause('new C()');
|
|
},
|
|
async function withDirectEval() {
|
|
await evaluateNewTargetOnPause('new D()');
|
|
},
|
|
async function withoutExplicitUsage() {
|
|
await evaluateNewTargetOnPause('new E()');
|
|
},
|
|
async function withInheritence() {
|
|
await evaluateNewTargetOnPause('new B()');
|
|
},
|
|
async function withContextAllocatedNewTarget() {
|
|
await evaluateNewTargetOnPause('new F()');
|
|
},
|
|
]);
|