Commit 8eadbe5c authored by Joyee Cheung's avatar Joyee Cheung Committed by Commit Bot

[class] hide private name symbols from the block scope in DevTools

Currently, the private name symbols are displayed in the block
scopes in DevTools, though these are just implementation details
of private fields. This patch hides them from the block scope
by marking variables with names starting with `#` as synthetic.

The private fields are still going to show up in the previews
of objects, only the key symbols themselves are going to be hidden.

Bug: v8:8773, chromium:982267
Change-Id: I059472d05c26a1f035ab92718a1b7e5ecafa8dc4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741846Reviewed-by: 's avatarSathya Gunasekaran  <gsathya@chromium.org>
Commit-Queue: Joyee Cheung <joyee@igalia.com>
Cr-Commit-Position: refs/heads/master@{#63112}
parent d1582442
...@@ -707,7 +707,7 @@ bool ScopeInfo::VariableIsSynthetic(String name) { ...@@ -707,7 +707,7 @@ bool ScopeInfo::VariableIsSynthetic(String name) {
// variable is a compiler-introduced temporary. However, to avoid conflict // variable is a compiler-introduced temporary. However, to avoid conflict
// with user declarations, the current temporaries like .generator_object and // with user declarations, the current temporaries like .generator_object and
// .result start with a dot, so we can use that as a flag. It's a hack! // .result start with a dot, so we can use that as a flag. It's a hack!
return name.length() == 0 || name.Get(0) == '.' || return name.length() == 0 || name.Get(0) == '.' || name.Get(0) == '#' ||
name.Equals(name.GetReadOnlyRoots().this_string()); name.Equals(name.GetReadOnlyRoots().this_string());
} }
......
Test private class fields in scopes
Running test: testScopesPaused
[
[0] : {
callFrameId : <callFrameId>
functionLocation : {
columnNumber : 16
lineNumber : 4
scriptId : <scriptId>
}
functionName : A
location : {
columnNumber : 6
lineNumber : 5
scriptId : <scriptId>
}
scopeChain : [
[0] : {
endLocation : {
columnNumber : 5
lineNumber : 6
scriptId : <scriptId>
}
name : A
object : {
className : Object
description : Object
objectId : <objectId>
type : object
}
startLocation : {
columnNumber : 16
lineNumber : 4
scriptId : <scriptId>
}
type : local
}
[1] : {
object : {
className : global
description : global
objectId : <objectId>
type : object
}
type : global
}
]
this : {
className : A
description : A
objectId : <objectId>
type : object
}
url :
}
[1] : {
callFrameId : <callFrameId>
functionLocation : {
columnNumber : 12
lineNumber : 1
scriptId : <scriptId>
}
functionName : run
location : {
columnNumber : 2
lineNumber : 8
scriptId : <scriptId>
}
scopeChain : [
[0] : {
endLocation : {
columnNumber : 1
lineNumber : 9
scriptId : <scriptId>
}
name : run
object : {
className : Object
description : Object
objectId : <objectId>
type : object
}
startLocation : {
columnNumber : 12
lineNumber : 1
scriptId : <scriptId>
}
type : local
}
[1] : {
object : {
className : global
description : global
objectId : <objectId>
type : object
}
type : global
}
]
this : {
className : global
description : global
objectId : <objectId>
type : object
}
url :
}
[2] : {
callFrameId : <callFrameId>
functionLocation : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
functionName :
location : {
columnNumber : 0
lineNumber : 0
scriptId : <scriptId>
}
scopeChain : [
[0] : {
object : {
className : global
description : global
objectId : <objectId>
type : object
}
type : global
}
]
this : {
className : global
description : global
objectId : <objectId>
type : object
}
url :
}
]
// 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.
let { session, contextGroup, Protocol } = InspectorTest.start(
"Test private class fields in scopes"
);
contextGroup.addScript(`
function run() {
class A {
#foo = "hello"
constructor () {
debugger;
}
};
new A();
}`);
InspectorTest.runAsyncTestSuite([
async function testScopesPaused() {
Protocol.Debugger.enable();
Protocol.Runtime.evaluate({ expression: "run()" });
let {
params: { callFrames }
} = await Protocol.Debugger.oncePaused(); // inside A()
InspectorTest.logMessage(callFrames);
Protocol.Debugger.resume();
Protocol.Debugger.disable();
}
]);
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