Changeset 198168 in webkit


Ignore:
Timestamp:
Mar 14, 2016 4:20:27 PM (8 years ago)
Author:
mark.lam@apple.com
Message:

Need to distinguish between Symbol() and Symbol("").
https://bugs.webkit.org/show_bug.cgi?id=155438

Reviewed by Saam Barati.

Source/JavaScriptCore:

  • runtime/PrivateName.h:

(JSC::PrivateName::PrivateName):

Source/WTF:

While toString of both Symbol() and Symbol("") yields "Symbol()", Function.name
should yield "" and "[]" respectively. Hence, we need to tell between the two.
This functionality will be needed later in https://bugs.webkit.org/show_bug.cgi?id=155437.

We achieve this by creating another singleton instance like the empty StringImpl
as the null StringImpl. isNullSymbol() tests if the Stringimpl instance is a
symbol, and its substring is the null() singleton.

  • wtf/text/StringImpl.cpp:

(WTF::StringImpl::createSymbol):
(WTF::StringImpl::createNullSymbol):
(WTF::StringImpl::containsOnlyWhitespace):
(WTF::StringImpl::createSymbolEmpty): Deleted.

  • wtf/text/StringImpl.h:

(WTF::StringImpl::tryCreateUninitialized):
(WTF::StringImpl::stringKind):
(WTF::StringImpl::isSymbol):
(WTF::StringImpl::isAtomic):
(WTF::StringImpl::isNullSymbol):

  • wtf/text/StringStatics.cpp:

(WTF::StringImpl::null):

Tools:

  • TestWebKitAPI/Tests/WTF/StringImpl.cpp:

(TestWebKitAPI::TEST):

  • Test that the a symbol with an empty string is not equivalent to a null symbol.
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r198167 r198168  
     12016-03-14  Mark Lam  <mark.lam@apple.com>
     2
     3        Need to distinguish between Symbol() and Symbol("").
     4        https://bugs.webkit.org/show_bug.cgi?id=155438
     5
     6        Reviewed by Saam Barati.
     7
     8        * runtime/PrivateName.h:
     9        (JSC::PrivateName::PrivateName):
     10
    1112016-03-14  Oliver Hunt  <oliver@apple.com>
    212
  • trunk/Source/JavaScriptCore/runtime/PrivateName.h

    r184828 r198168  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434public:
    3535    PrivateName()
    36         : m_uid(StringImpl::createSymbolEmpty())
     36        : m_uid(StringImpl::createNullSymbol())
    3737    {
    3838    }
  • trunk/Source/WTF/ChangeLog

    r198093 r198168  
     12016-03-14  Mark Lam  <mark.lam@apple.com>
     2
     3        Need to distinguish between Symbol() and Symbol("").
     4        https://bugs.webkit.org/show_bug.cgi?id=155438
     5
     6        Reviewed by Saam Barati.
     7
     8        While toString of both Symbol() and Symbol("") yields "Symbol()", Function.name
     9        should yield "" and "[]" respectively.  Hence, we need to tell between the two.
     10        This functionality will be needed later in https://bugs.webkit.org/show_bug.cgi?id=155437.
     11
     12        We achieve this by creating another singleton instance like the empty StringImpl
     13        as the null StringImpl.  isNullSymbol() tests if the Stringimpl instance is a
     14        symbol, and its substring is the null() singleton.
     15
     16        * wtf/text/StringImpl.cpp:
     17        (WTF::StringImpl::createSymbol):
     18        (WTF::StringImpl::createNullSymbol):
     19        (WTF::StringImpl::containsOnlyWhitespace):
     20        (WTF::StringImpl::createSymbolEmpty): Deleted.
     21        * wtf/text/StringImpl.h:
     22        (WTF::StringImpl::tryCreateUninitialized):
     23        (WTF::StringImpl::stringKind):
     24        (WTF::StringImpl::isSymbol):
     25        (WTF::StringImpl::isAtomic):
     26        (WTF::StringImpl::isNullSymbol):
     27        * wtf/text/StringStatics.cpp:
     28        (WTF::StringImpl::null):
     29
    1302016-03-13  Joseph Pecoraro  <pecoraro@apple.com>
    231
  • trunk/Source/WTF/wtf/text/StringImpl.cpp

    r196223 r198168  
    307307}
    308308
    309 Ref<SymbolImpl> StringImpl::createSymbolEmpty()
    310 {
    311     return createSymbol(empty());
     309Ref<SymbolImpl> StringImpl::createNullSymbol()
     310{
     311    return createSymbol(null());
    312312}
    313313
  • trunk/Source/WTF/wtf/text/StringImpl.h

    r198019 r198168  
    409409    }
    410410
    411     WTF_EXPORT_STRING_API static Ref<SymbolImpl> createSymbolEmpty();
     411    WTF_EXPORT_STRING_API static Ref<SymbolImpl> createNullSymbol();
    412412    WTF_EXPORT_STRING_API static Ref<SymbolImpl> createSymbol(PassRefPtr<StringImpl> rep);
    413413
     
    485485    bool isSymbol() const { return m_hashAndFlags & s_hashFlagStringKindIsSymbol; }
    486486    bool isAtomic() const { return m_hashAndFlags & s_hashFlagStringKindIsAtomic; }
     487    bool isNullSymbol() const { return isSymbol() && (substringBuffer() == null()); }
    487488
    488489    void setIsAtomic(bool isAtomic)
     
    864865    WTF_EXPORT_PRIVATE NEVER_INLINE unsigned hashSlowCase() const;
    865866    WTF_EXPORT_PRIVATE static unsigned nextHashForSymbol();
     867    WTF_EXPORT_PRIVATE static StringImpl* null();
    866868
    867869    // The bottom bit in the ref count indicates a static (immortal) string.
  • trunk/Source/WTF/wtf/text/StringStatics.cpp

    r183624 r198168  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All Rights Reserved.
     2 * Copyright (C) 2010, 2016 Apple Inc. All Rights Reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4141
    4242namespace WTF {
     43
     44StringImpl* StringImpl::null()
     45{
     46    static NeverDestroyed<StringImpl> nullString(ConstructEmptyString);
     47    return &nullString.get();
     48}
    4349
    4450StringImpl* StringImpl::empty()
  • trunk/Tools/ChangeLog

    r198141 r198168  
     12016-03-14  Mark Lam  <mark.lam@apple.com>
     2
     3        Need to distinguish between Symbol() and Symbol("").
     4        https://bugs.webkit.org/show_bug.cgi?id=155438
     5
     6        Reviewed by Saam Barati.
     7
     8        * TestWebKitAPI/Tests/WTF/StringImpl.cpp:
     9        (TestWebKitAPI::TEST):
     10        - Test that the a symbol with an empty string is not equivalent to a null symbol.
     11
    1122016-03-14  David Kilzer  <ddkilzer@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp

    r198019 r198168  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012, 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    514514}
    515515
    516 TEST(WTF, StringImplCreateSymbolEmpty)
    517 {
    518     RefPtr<StringImpl> reference = StringImpl::createSymbolEmpty();
     516TEST(WTF, StringImplCreateNullSymbol)
     517{
     518    RefPtr<StringImpl> reference = StringImpl::createNullSymbol();
    519519    ASSERT_TRUE(reference->isSymbol());
     520    ASSERT_TRUE(reference->isNullSymbol());
    520521    ASSERT_FALSE(reference->isAtomic());
    521522    ASSERT_EQ(0u, reference->length());
     
    528529    RefPtr<StringImpl> reference = StringImpl::createSymbol(original);
    529530    ASSERT_TRUE(reference->isSymbol());
     531    ASSERT_FALSE(reference->isNullSymbol());
    530532    ASSERT_FALSE(reference->isAtomic());
    531533    ASSERT_FALSE(original->isSymbol());
     
    533535    ASSERT_EQ(original->length(), reference->length());
    534536    ASSERT_TRUE(equal(reference.get(), "original"));
     537
     538    RefPtr<StringImpl> empty = stringFromUTF8("");
     539    RefPtr<StringImpl> emptyReference = StringImpl::createSymbol(empty);
     540    ASSERT_TRUE(emptyReference->isSymbol());
     541    ASSERT_FALSE(emptyReference->isNullSymbol());
     542    ASSERT_FALSE(emptyReference->isAtomic());
     543    ASSERT_FALSE(empty->isSymbol());
     544    ASSERT_FALSE(empty->isNullSymbol());
     545    ASSERT_TRUE(empty->isAtomic());
     546    ASSERT_EQ(empty->length(), emptyReference->length());
     547    ASSERT_TRUE(equal(emptyReference.get(), ""));
    535548}
    536549
     
    549562}
    550563
    551 TEST(WTF, StringImplSymbolEmptyToAtomicString)
    552 {
    553     RefPtr<StringImpl> reference = StringImpl::createSymbolEmpty();
     564TEST(WTF, StringImplNullSymbolToAtomicString)
     565{
     566    RefPtr<StringImpl> reference = StringImpl::createNullSymbol();
    554567    ASSERT_TRUE(reference->isSymbol());
    555568    ASSERT_FALSE(reference->isAtomic());
Note: See TracChangeset for help on using the changeset viewer.