v8/test/inspector/debugger/class-private-methods-preview.js
Joyee Cheung 963ff849df [class] implement inspector support for private instance methods
This patch implements inspector support for private instance methods:

- Previously to implement brand checking for instances with private
  instance methods we store the brand both as the value with the brand
  itself as the key in the stances. Now we make the value the context
  associated with the class instead.
- To retrieve the private instance methods and accessors from the
  instances at runtime, we look into the contexts stored with the
  brands, and analyze the scope info to get the names as well as
  context slot indices of them.
- This patch extends the `PrivatePropertyDescriptor` in the inspector
  protocol to include optional `get` and `set` fields, and make the
  `value` field optional (similar to `PropertyDescriptor`s).
  Private fields or private instance methods are returned in the
  `value` field while private accessors are returned in the `get`
  and/or `set` field. Property previews for the instaces containing
  private instance methods and accessors are also updated similarly,
  although no additional protocol change is necessary since the
  `PropertyPreview` type can already be used to display accessors.

Design doc: https://docs.google.com/document/d/1N91LObhQexnB0eE7EvGe57HsvNMFX16CaWu-XCTnnmY/edit

Bug: v8:9839, v8:8330
Change-Id: If37090bd23833a18f75deb1249ca5c4405ca2bf2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1934407
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65337}
2019-12-04 20:13:34 +00:00

39 lines
1.3 KiB
JavaScript

// Copyright 2016 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("Check private methods in object preview.");
Protocol.Debugger.enable();
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(dumpInternalProperties);
contextGroup.setupInjectedScriptEnvironment();
InspectorTest.runAsyncTestSuite([
async function testPrivateMethods() {
const expressions = [
"new class extends class { constructor() { return new Proxy({}, {}); } } { #method() { return 1; } }",
"new class { #method() { return 1; } get #accessor() { } set #accessor(val) { } }",
"new class extends class { #method() { return 1; } } { get #accessor() { } set #accessor(val) { } }",
];
for (const expression of expressions) {
InspectorTest.log(`expression: ${expression}`);
await Protocol.Runtime.evaluate({
expression: `console.table(${expression})`,
generatePreview: true
});
}
}
]);
function dumpInternalProperties(message) {
try {
InspectorTest.logMessage(message.params.args[0].preview.properties);
} catch {
InspectorTest.logMessage(message);
}
}