[inspector] Don't pretend that native accessors are own properties.

Previously the V8 inspector would report native accessors, whose getter
evaluates to a value without causing a side effect, as own data
properties. But then the DevTools front-end will not be able to tell
whether that accessor was actually an own property or just an inherited
accessor.

The reason for reporting them as own properties in the first place was
to ensure that these properties show up in the object's preview. But
that we can handle differently by just marking these properties as
synthetic internally and including them in the preview.

Bug: chromium:1076820
Change-Id: I223299af7954e7b1a4a16bb5180d4ceff50f170f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3094005
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Kim-Anh Tran <kimanh@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#76276}
This commit is contained in:
Benedikt Meurer 2021-08-13 08:57:44 +02:00 committed by V8 LUCI CQ
parent 7346848d56
commit 52720f63da
4 changed files with 35 additions and 2 deletions

View File

@ -786,7 +786,7 @@ class PreviewPropertyAccumulator : public ValueMirror::PropertyAccumulator {
!mirror.value) {
return true;
}
if (!mirror.isOwn) return true;
if (!mirror.isOwn && !mirror.isSynthetic) return true;
if (std::find(m_blocklist.begin(), m_blocklist.end(), mirror.name) !=
m_blocklist.end()) {
return true;
@ -1288,7 +1288,6 @@ bool ValueMirror::getProperties(v8::Local<v8::Context> context,
nullptr, true)
.ToLocal(&value)) {
valueMirror = ValueMirror::create(context, value);
isOwn = true;
setterMirror = nullptr;
getterMirror = nullptr;
}
@ -1303,6 +1302,7 @@ bool ValueMirror::getProperties(v8::Local<v8::Context> context,
enumerable,
isOwn,
iterator->is_array_index(),
isAccessorProperty && valueMirror,
std::move(valueMirror),
std::move(getterMirror),
std::move(setterMirror),

View File

@ -38,6 +38,7 @@ struct PropertyMirror {
bool enumerable;
bool isOwn;
bool isIndex;
bool isSynthetic;
std::unique_ptr<ValueMirror> value;
std::unique_ptr<ValueMirror> getter;
std::unique_ptr<ValueMirror> setter;

View File

@ -26,6 +26,34 @@ Running test: testNotOwn
Internal properties
[[Prototype]] object undefined
Running test: testNotOwnSet
Symbol(Symbol.iterator) inherited function undefined
Symbol(Symbol.toStringTag) inherited string Set
__defineGetter__ inherited function undefined
__defineSetter__ inherited function undefined
__lookupGetter__ inherited function undefined
__lookupSetter__ inherited function undefined
__proto__ inherited no value, getter, setter
add inherited function undefined
clear inherited function undefined
constructor inherited function undefined
delete inherited function undefined
entries inherited function undefined
forEach inherited function undefined
has inherited function undefined
hasOwnProperty inherited function undefined
isPrototypeOf inherited function undefined
keys inherited function undefined
propertyIsEnumerable inherited function undefined
size inherited number 3
toLocaleString inherited function undefined
toString inherited function undefined
valueOf inherited function undefined
values inherited function undefined
Internal properties
[[Entries]] object undefined
[[Prototype]] object undefined
Running test: testAccessorsOnly
b own no value, getter, setter
d own no value, setter

View File

@ -15,6 +15,10 @@ InspectorTest.runAsyncTestSuite([
return logExpressionProperties('({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d() {return 6;} }})', { ownProperties: false });
},
function testNotOwnSet() {
return logExpressionProperties('new Set([1, 2, 3])', { ownProperties: false });
},
function testAccessorsOnly() {
return logExpressionProperties('({ a: 2, set b(_) {}, get b() {return 5;}, c: \'c\', set d(_){} })', { ownProperties: true, accessorPropertiesOnly: true});
},