⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 280651 in webkit


Ignore:
Timestamp:
Aug 4, 2021, 12:37:35 PM (5 years ago)
Author:
mmaxfield@apple.com
Message:

[Cocoa] Tweak the formatting for passing NSArrays to TextStreams
https://bugs.webkit.org/show_bug.cgi?id=228766

Reviewed by Simon Fraser.

Source/WTF:

Instead of using -[NSArray description], which puts its output on multiple lines,
instead use the same formatting as WTF::Vector, which puts its output on a single line.

We can also use this opportunity to tweak the implementation of operator<<(id) to
allow it to be called with Core Foundation types in raw C++ code.

  • wtf/text/TextStream.h:
  • wtf/text/cocoa/TextStreamCocoa.mm:

(WTF::TextStream::operator<<):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.cpp: Added.

(TEST):

  • TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.mm: Added.

(TEST):

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r280626 r280651  
     12021-08-03  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Tweak the formatting for passing NSArrays to TextStreams
     4        https://bugs.webkit.org/show_bug.cgi?id=228766
     5
     6        Reviewed by Simon Fraser.
     7
     8        Instead of using -[NSArray description], which puts its output on multiple lines,
     9        instead use the same formatting as WTF::Vector, which puts its output on a single line.
     10
     11        We can also use this opportunity to tweak the implementation of operator<<(id) to
     12        allow it to be called with Core Foundation types in raw C++ code.
     13
     14        * wtf/text/TextStream.h:
     15        * wtf/text/cocoa/TextStreamCocoa.mm:
     16        (WTF::TextStream::operator<<):
     17
    1182021-08-03  Risul Islam  <risul_islam@apple.com>
    219
  • trunk/Source/WTF/wtf/text/TextStream.h

    r279847 r280651  
    7979    WTF_EXPORT_PRIVATE TextStream& operator<<(const FormatNumberRespectingIntegers&);
    8080
     81#if PLATFORM(COCOA)
     82    WTF_EXPORT_PRIVATE TextStream& operator<<(id);
    8183#ifdef __OBJC__
    82     WTF_EXPORT_PRIVATE TextStream& operator<<(id<NSObject>);
     84    WTF_EXPORT_PRIVATE TextStream& operator<<(NSArray *);
     85#endif
    8386#endif
    8487
  • trunk/Source/WTF/wtf/text/cocoa/TextStreamCocoa.mm

    r277744 r280651  
    2626namespace WTF {
    2727
    28 TextStream& TextStream::operator<<(id<NSObject> object)
     28TextStream& TextStream::operator<<(id object)
    2929{
    30     m_text.append([object description]);
     30    if ([object isKindOfClass:[NSArray class]])
     31        return *this << static_cast<NSArray *>(object);
     32
     33    if ([object conformsToProtocol:@protocol(NSObject)])
     34        m_text.append([object description]);
     35    else
     36        m_text.append("(id)");
    3137    return *this;
    3238}
    3339
     40TextStream& TextStream::operator<<(NSArray *array)
     41{
     42    *this << "[";
     43
     44    for (NSUInteger i = 0; i < array.count; ++i) {
     45        id item = array[i];
     46        *this << item;
     47        if (i < array.count - 1)
     48            *this << ", ";
     49    }
     50
     51    return *this << "]";
    3452}
     53
     54}
  • trunk/Tools/ChangeLog

    r280640 r280651  
     12021-08-03  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Cocoa] Tweak the formatting for passing NSArrays to TextStreams
     4        https://bugs.webkit.org/show_bug.cgi?id=228766
     5
     6        Reviewed by Simon Fraser.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.cpp: Added.
     10        (TEST):
     11        * TestWebKitAPI/Tests/WTF/cocoa/TextStreamCocoa.mm: Added.
     12        (TEST):
     13
    1142021-08-04  Jonathan Bedard  <jbedard@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r280559 r280651  
    113113                1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
    114114                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
     115                1C4616A026BA5A2100F8C9F6 /* TextStreamCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C46169E26BA510700F8C9F6 /* TextStreamCocoa.mm */; };
     116                1C4616A726BB172F00F8C9F6 /* TextStreamCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C4616A626BB172F00F8C9F6 /* TextStreamCocoa.cpp */; };
    115117                1C51534C261596D700FBC4FE /* UserInstalledAhem.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C51534B261596BD00FBC4FE /* UserInstalledAhem.html */; };
    116118                1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
     
    18791881                1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
    18801882                1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
     1883                1C46169E26BA510700F8C9F6 /* TextStreamCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TextStreamCocoa.mm; sourceTree = "<group>"; };
     1884                1C4616A626BB172F00F8C9F6 /* TextStreamCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TextStreamCocoa.cpp; sourceTree = "<group>"; };
    18811885                1C51534B261596BD00FBC4FE /* UserInstalledAhem.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = UserInstalledAhem.html; sourceTree = "<group>"; };
    18821886                1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
     
    20022006                2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
    20032007                2EB29D5D1F762DA50023A5F1 /* dump-datatransfer-types.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "dump-datatransfer-types.html"; sourceTree = "<group>"; };
    2004                 2EC7034926AF5E88002B2D37 /* KeyboardEventTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = KeyboardEventTests.mm; path = KeyboardEventTests.mm; sourceTree = "<group>"; };
     2008                2EC7034926AF5E88002B2D37 /* KeyboardEventTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = KeyboardEventTests.mm; sourceTree = "<group>"; };
    20052009                2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlayingControlsTests.mm; sourceTree = "<group>"; };
    20062010                2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; };
     
    49734977                        children = (
    49744978                                BC3FEB63267FCF740054006A /* SpanCocoa.mm */,
     4979                                1C4616A626BB172F00F8C9F6 /* TextStreamCocoa.cpp */,
     4980                                1C46169E26BA510700F8C9F6 /* TextStreamCocoa.mm */,
    49754981                                E3C21A7B21B25CA2003B31A3 /* URLExtras.mm */,
    49764982                        );
     
    53135319                                7C83DF401D0A590C00FEBCF3 /* TestsController.cpp in Sources */,
    53145320                                9329AA291DE3F81E003ABD07 /* TextBreakIterator.cpp in Sources */,
     5321                                1C4616A726BB172F00F8C9F6 /* TextStreamCocoa.cpp in Sources */,
     5322                                1C4616A026BA5A2100F8C9F6 /* TextStreamCocoa.mm in Sources */,
    53155323                                7B2739F32632AB640040F182 /* ThreadAssertionsTest.cpp in Sources */,
    53165324                                E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.