[webkit-changes] [WebKit/WebKit] 444a3d: Web Inspector: Support ES2022 Private Fields

Devin Rousso noreply at github.com
Wed Apr 12 13:27:26 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 444a3dccd78535db15ac4a8e0164cf8d537a35a5
      https://github.com/WebKit/WebKit/commit/444a3dccd78535db15ac4a8e0164cf8d537a35a5
  Author: Devin Rousso <hi at devinrousso.com>
  Date:   2023-04-12 (Wed, 12 Apr 2023)

  Changed paths:
    M LayoutTests/inspector/runtime/getDisplayableProperties-expected.txt
    M LayoutTests/inspector/runtime/getDisplayableProperties.html
    M LayoutTests/inspector/runtime/getProperties-expected.txt
    M LayoutTests/inspector/runtime/getProperties.html
    M LayoutTests/inspector/runtime/resources/property-descriptor-utilities.js
    M Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
    M Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
    M Source/JavaScriptCore/inspector/InjectedScriptSource.js
    M Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp
    M Source/JavaScriptCore/inspector/JSInjectedScriptHost.h
    M Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp
    M Source/JavaScriptCore/inspector/protocol/Runtime.json
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp
    M Source/JavaScriptCore/runtime/PrivateName.h
    M Source/JavaScriptCore/runtime/Symbol.cpp
    M Source/WTF/wtf/text/SymbolImpl.cpp
    M Source/WTF/wtf/text/SymbolImpl.h
    M Source/WebInspectorUI/UserInterface/Models/PropertyDescriptor.js
    M Source/WebInspectorUI/UserInterface/Models/PropertyPath.js
    M Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.css
    M Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js
    M Source/WebInspectorUI/UserInterface/Views/ObjectTreeView.js
    M Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp

  Log Message:
  -----------
  Web Inspector: Support ES2022 Private Fields
https://bugs.webkit.org/show_bug.cgi?id=254961
<rdar://problem/107863310>

Reviewed by Patrick Angle and Justin Michaud.

Web Inspector should show private fields when logging objects in the Console.

As private field usage becomes more and more popular, not being able to see private fields in the Console will become increasingly disruptive to the debugging experience.

* Source/JavaScriptCore/inspector/InjectedScriptSource.js:
(InjectedScript.prototype._forEachPropertyDescriptor):
(InjectedScript.prototype._forEachPropertyDescriptor.processProperty):
* Source/JavaScriptCore/inspector/JSInjectedScriptHost.h:
* Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp:
(Inspector::JSInjectedScriptHost::getOwnPrivatePropertyDescriptors): Added.
* Source/JavaScriptCore/inspector/JSInjectedScriptHostPrototype.cpp:
(Inspector::JSInjectedScriptHostPrototype::finishCreation):
(Inspector::jsInjectedScriptHostPrototypeFunctionGetOwnPrivatePropertyDescriptors): Added.
Create a `InjectedScriptHost` method similar to `Object.getOwnPropertyDescriptors` but only for private fields.
Use it when fetching property descriptors for the frontend to grab private fields just like all other public fields.

* Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp:
(JSC::PropertyListNode::emitDeclarePrivateFieldNames):
Pass along the `PropertyNode::name` when creating a private symbol for the private field.

* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::emitCreatePrivateBrand):
AFAIK there is no name in this scenario, just a private symbol to mark with a private brand, so use an empty string for the name.

* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::createPrivateSymbol):
(JSC::JSGlobalObject::init):
Require a name when calling `@createPrivateSymbol`.

* Source/JavaScriptCore/runtime/PrivateName.h:
(JSC::PrivateName::PrivateName): Deleted.
* Source/JavaScriptCore/runtime/Symbol.cpp:
(JSC::Symbol::Symbol):
* Source/WTF/wtf/text/SymbolImpl.h:
* Source/WTF/wtf/text/SymbolImpl.cpp:
(WTF::PrivateSymbolImpl::createNullSymbol): Deleted.
* Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:
(WebKit::IPCTestingAPI::JSMessageListener::JSMessageListener):
Require that all `PrivateName` and `PrivateSymbolImpl` be created with a name (or at least an empty string).

* Source/JavaScriptCore/inspector/protocol/Runtime.json:
* Source/WebInspectorUI/UserInterface/Models/PropertyDescriptor.js:
(WI.PropertyDescriptor):
(WI.PropertyDescriptor.fromPayload):
(WI.PropertyDescriptor.get isPrivateProperty): Added.
Expose a way for clients to know that this `WI.PropertyDescriptor` is for a private field.

* Source/WebInspectorUI/UserInterface/Models/PropertyPath.js:
(WI.PropertyPath.prototype.appendPrivatePropertyName): Added.
(WI.PropertyPath.prototype.appendPropertyDescriptor):
Make sure that private fields are sufficiently hidden (i.e. do not show "Copy Path to Property" since it won't work).

* Source/WebInspectorUI/UserInterface/Views/ObjectTreeView.js:
(WI.ObjectTreeView.comparePropertyDescriptors):
Sort private fields above all other non-internal properties.

* Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js:
(WI.ObjectTreePropertyTreeElement.prototype._createTitlePropertyStyle):
* Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.css:
(.object-tree-property .property-name:is(.private, .not-enumerable)): Renamed from `.object-tree-property .property-name.not-enumerable`.
Display private fields as a greyed out property (similar to internal properties) in order to help emphasize their semi-unreachable nature.

* LayoutTests/inspector/runtime/getDisplayableProperties.html:
* LayoutTests/inspector/runtime/getDisplayableProperties-expected.txt:
* LayoutTests/inspector/runtime/getProperties.html:
* LayoutTests/inspector/runtime/getProperties-expected.txt:
* LayoutTests/inspector/runtime/resources/property-descriptor-utilities.js:
(ProtocolTest.PropertyDescriptorUtilities.logForEach):

Canonical link: https://commits.webkit.org/262882@main




More information about the webkit-changes mailing list