Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
StringImpl created from literal should be BufferInternal
https://bugs.webkit.org/show_bug.cgi?id=92940 Reviewed by Anders Carlsson. Source/WTF: The ownership of string created from literal should be BufferInternal so that StringImpl never tries to delete the characters. The ownership was accidentaly set to BufferOwned in r123689. * wtf/text/StringImpl.cpp: (WTF::StringImpl::createFromLiteral): Update to use the new constructor. * wtf/text/StringImpl.h: (WTF::StringImpl::StringImpl): Add a new constructor making the construction from literal explicit. Add the flag s_hashFlagHasTerminatingNullCharacter since the data has the terminating null character. Tools: Add tests for the contruction of strings from literal. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WTF/AtomicString.cpp: Added. (TestWebKitAPI): (TestWebKitAPI::TEST): * TestWebKitAPI/Tests/WTF/StringImpl.cpp: Added. (TestWebKitAPI): (TestWebKitAPI::TEST): Canonical link: https://commits.webkit.org/110957@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@124611 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
fba7f8a
commit 12fd0ce
Showing
9 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2012 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include <wtf/text/AtomicString.h> | ||
|
||
namespace TestWebKitAPI { | ||
|
||
TEST(WTF, AtomicStringCreationFromLiteral) | ||
{ | ||
AtomicString stringWithTemplate("Template Literal", AtomicString::ConstructFromLiteral); | ||
ASSERT_EQ(strlen("Template Literal"), stringWithTemplate.length()); | ||
ASSERT_TRUE(stringWithTemplate == "Template Literal"); | ||
ASSERT_TRUE(stringWithTemplate.string().is8Bit()); | ||
ASSERT_TRUE(stringWithTemplate.impl()->hasTerminatingNullCharacter()); | ||
|
||
const char* programmaticStringData = "Explicit Size Literal"; | ||
AtomicString programmaticString(programmaticStringData, strlen(programmaticStringData), AtomicString::ConstructFromLiteral); | ||
ASSERT_EQ(strlen(programmaticStringData), programmaticString.length()); | ||
ASSERT_TRUE(programmaticStringData == programmaticStringData); | ||
ASSERT_TRUE(programmaticString.string().is8Bit()); | ||
ASSERT_TRUE(programmaticString.impl()->hasTerminatingNullCharacter()); | ||
ASSERT_EQ(programmaticStringData, reinterpret_cast<const char*>(programmaticString.string().characters8())); | ||
} | ||
|
||
TEST(WTF, AtomicStringCreationFromLiteralUniqueness) | ||
{ | ||
AtomicString string1("Template Literal", AtomicString::ConstructFromLiteral); | ||
AtomicString string2("Template Literal", AtomicString::ConstructFromLiteral); | ||
ASSERT_EQ(string1.impl(), string2.impl()); | ||
|
||
AtomicString string3("Template Literal"); | ||
ASSERT_EQ(string1.impl(), string3.impl()); | ||
} | ||
|
||
} // namespace TestWebKitAPI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2012 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include <wtf/text/StringImpl.h> | ||
|
||
namespace TestWebKitAPI { | ||
|
||
TEST(WTF, StringImplCreationFromLiteral) | ||
{ | ||
RefPtr<StringImpl> stringWithTemplate = StringImpl::createFromLiteral("Template Literal"); | ||
ASSERT_EQ(strlen("Template Literal"), stringWithTemplate->length()); | ||
ASSERT_TRUE(equal(stringWithTemplate.get(), "Template Literal")); | ||
ASSERT_TRUE(stringWithTemplate->is8Bit()); | ||
ASSERT_TRUE(stringWithTemplate->hasTerminatingNullCharacter()); | ||
|
||
const char* programmaticStringData = "Explicit Size Literal"; | ||
RefPtr<StringImpl> programmaticString = StringImpl::createFromLiteral(reinterpret_cast<const LChar*>(programmaticStringData), strlen(programmaticStringData)); | ||
ASSERT_EQ(strlen(programmaticStringData), programmaticString->length()); | ||
ASSERT_TRUE(equal(programmaticString.get(), programmaticStringData)); | ||
ASSERT_EQ(programmaticStringData, reinterpret_cast<const char*>(programmaticString->characters8())); | ||
ASSERT_TRUE(programmaticString->is8Bit()); | ||
ASSERT_TRUE(programmaticString->hasTerminatingNullCharacter()); | ||
} | ||
|
||
TEST(WTF, StringImplFromLiteralLoop16BitConversion) | ||
{ | ||
RefPtr<StringImpl> controlString = StringImpl::create("Template Literal"); | ||
for (size_t i = 0; i < 10; ++i) { | ||
RefPtr<StringImpl> string = StringImpl::createFromLiteral("Template Literal"); | ||
|
||
ASSERT_EQ(0, memcmp(controlString->characters(), string->characters(), controlString->length() * sizeof(UChar))); | ||
ASSERT_TRUE(string->has16BitShadow()); | ||
} | ||
} | ||
|
||
} // namespace TestWebKitAPI |