v8/test/inspector/debugger/class-private-methods-static.js
Joyee Cheung 0ea5b5248d [class] implement inspector support for static private methods
When looking for private members in an object for the inspector,
we check if that object is a class constructor with the a bit
has_static_private_methods set on its SFI. If it
is, we look for any variables in the context locals
with a VariableMode associated with private methods or accessors
and a IsStaticFlag being kStatic.

This patch also filters out static private methods when inspecting
instances.

Design doc: https://docs.google.com/document/d/1N91LObhQexnB0eE7EvGe57HsvNMFX16CaWu-XCTnnmY/edit
See also: https://docs.google.com/document/d/14maU596YbHcWR7XR-_iXM_ANhAAmiuRlJZysM61lqaE/edit

Bug: v8:9839, v8:8330
Change-Id: Idad15349c983898de2ce632c38b0174da10e639d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1955664
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/master@{#66636}
2020-03-09 20:19:17 +00:00

126 lines
4.0 KiB
JavaScript

// 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.
// Flags: --harmony-private-methods
let { session, contextGroup, Protocol } = InspectorTest.start(
"Test static private class methods"
);
const script = `
function run() {
class A {
static test() {
debugger;
}
static #field = 2;
#instanceMethod() { } // should not show up
get #instanceAccessor() { return this.#field; } // should not show up
set #instanceAccessor(val) { this.#field = val; } // should not show up
static set #writeOnly(val) { this.#field = val; }
static get #readOnly() { return this.#field; }
static get #accessor() { return this.#field; }
static set #accessor(val) { this.#field = val; }
static #inc() { return ++A.#accessor; }
};
A.test();
class B extends A {
static get #accessor() { return 'subclassAccessor'; }
static #subclassMethod() { return B.#accessor; }
static test() {
debugger;
}
}
B.test();
}`;
contextGroup.addScript(script);
InspectorTest.runAsyncTestSuite([
async function testScopesPaused() {
Protocol.Debugger.enable();
// Do not await here, instead oncePaused should be awaited.
Protocol.Runtime.evaluate({ expression: 'run()' });
InspectorTest.log('privateProperties on the base class');
let {
params: { callFrames }
} = await Protocol.Debugger.oncePaused(); // inside A.test()
let frame = callFrames[0];
let { result } = await Protocol.Runtime.getProperties({
objectId: frame.this.objectId
});
InspectorTest.logMessage(result.privateProperties);
// TODO(joyee): make it possible to desugar the brand check, which requires
// the class variable to be saved, even when the static private
// methods/accessors are not referenced in the class body.
InspectorTest.log('Evaluating A.#inc();');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'A.#inc();',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logObject(result);
InspectorTest.log('Evaluating this.#inc();');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'this.#inc();',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logObject(result);
InspectorTest.log('Evaluating ++this.#accessor;');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: '++this.#accessor;',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logObject(result);
InspectorTest.log('Evaluating this.#readOnly;');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'this.#readOnly;',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logObject(result);
InspectorTest.log('Evaluating this.#writeOnly = 0; this.#field;');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'this.#writeOnly = 0; this.#field;',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logObject(result);
Protocol.Debugger.resume();
({ params: { callFrames } } = await Protocol.Debugger.oncePaused()); // B.test();
frame = callFrames[0];
InspectorTest.log('privateProperties on the subclass');
({ result } = await Protocol.Runtime.getProperties({
objectId: frame.this.objectId
}));
InspectorTest.logMessage(result.privateProperties);
InspectorTest.log('Evaluating this.#inc(); from the base class');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'this.#inc();',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logMessage(result);
InspectorTest.log('Evaluating this.#subclassMethod();');
({ result } = await Protocol.Debugger.evaluateOnCallFrame({
expression: 'this.#subclassMethod();',
callFrameId: callFrames[0].callFrameId
}));
InspectorTest.logMessage(result);
Protocol.Debugger.resume();
Protocol.Debugger.disable();
}
]);