Bug 142772 - Fix StringView misplaced implementations after r181525 and r181558
Summary: Fix StringView misplaced implementations after r181525 and r181558
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Dhi Aurrahman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-16 21:48 PDT by Dhi Aurrahman
Modified: 2015-03-18 18:11 PDT (History)
3 users (show)

See Also:


Attachments
Patch (8.60 KB, patch)
2015-03-16 21:54 PDT, Dhi Aurrahman
no flags Details | Formatted Diff | Diff
Patch (14.90 KB, patch)
2015-03-17 01:26 PDT, Dhi Aurrahman
no flags Details | Formatted Diff | Diff
Patch (15.63 KB, patch)
2015-03-17 21:25 PDT, Dhi Aurrahman
no flags Details | Formatted Diff | Diff
Patch (17.28 KB, patch)
2015-03-18 13:28 PDT, Dhi Aurrahman
no flags Details | Formatted Diff | Diff
Patch for landing (17.28 KB, patch)
2015-03-18 17:27 PDT, Dhi Aurrahman
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dhi Aurrahman 2015-03-16 21:48:03 PDT
Fix StringView typos after r181525 and r181558
Comment 1 Dhi Aurrahman 2015-03-16 21:54:41 PDT
Created attachment 248809 [details]
Patch
Comment 2 Benjamin Poulain 2015-03-16 23:03:46 PDT
Comment on attachment 248809 [details]
Patch

I messed up, thanks for fixing after me.
Comment 3 Darin Adler 2015-03-16 23:14:52 PDT
Comment on attachment 248809 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248809&action=review

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:220
> +    StringView reference(String("abcdefg"));

These tests look incorrect. This creates a dangling StringView that points to a String that has already been deleted. I’m surprised that tests written this way don’t immediately fail with the StringView string lifetime assertion when run in a debug build.

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:230
> +    ASSERT_TRUE(reference.startsWith(oneLetterPrefix));

These should be using EXPECT, not ASSERT.
Comment 4 Benjamin Poulain 2015-03-16 23:42:29 PDT
Comment on attachment 248809 [details]
Patch

Oops, I did not notice the test issues :(
Comment 5 Dhi Aurrahman 2015-03-17 01:26:57 PDT
Created attachment 248830 [details]
Patch
Comment 6 Darin Adler 2015-03-17 09:25:08 PDT
Comment on attachment 248830 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248830&action=review

No 16-bit coverage in the tests?

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:228
> +    RefPtr<StringImpl> reference = StringImpl::create(reinterpret_cast<const LChar*>("abcdefg"));
> +    RefPtr<StringImpl> emptyPrefix = StringImpl::create(reinterpret_cast<const LChar*>(""));
> +    RefPtr<StringImpl> oneLetterPrefix = StringImpl::create(reinterpret_cast<const LChar*>("a"));
> +    RefPtr<StringImpl> shortPrefix = StringImpl::create(reinterpret_cast<const LChar*>("ab"));
> +    RefPtr<StringImpl> longPrefix = StringImpl::create(reinterpret_cast<const LChar*>("abcd"));
> +    RefPtr<StringImpl> upperCasePrefix = StringImpl::create(reinterpret_cast<const LChar*>("AB"));
> +    RefPtr<StringImpl> notPrefix = StringImpl::create(reinterpret_cast<const LChar*>("cd"));
> +    RefPtr<StringImpl> withLatin1CharsPrefix = StringImpl::create(reinterpret_cast<const LChar*>("àb"));
> +    RefPtr<StringImpl> spacePrefix = StringImpl::create(reinterpret_cast<const LChar*>(" "));

Should just be:

    String reference = "abcdefg";

Direct use of StringImpl is unnecessary.

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:230
> +    StringView referenceStringView(*reference.get());

If we are only testing 8-bit then this could just be:

    StringView referenceStringView(reinterpret_cast<const LChar*>("abcdefg"), 7);

We could also make a helper function to make a StringView from a literal to make the test short and readable.
Comment 7 Dhi Aurrahman 2015-03-17 18:12:30 PDT
Comment on attachment 248830 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248830&action=review

>> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:230
>> +    StringView referenceStringView(*reference.get());
> 
> If we are only testing 8-bit then this could just be:
> 
>     StringView referenceStringView(reinterpret_cast<const LChar*>("abcdefg"), 7);
> 
> We could also make a helper function to make a StringView from a literal to make the test short and readable.

Hi Darin,

I'm not sure I completely understand. 

If I put something like:

StringView stringViewFromLiteral(const char* characters) {
    return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
}

// I guess this one is for 16-bit
StringView stringViewFromUTF8(const char* characters) {
    return String::fromUTF8(characters);
}

TEST(WTF, StringViewStartsWithBasic)
{
    StringView reference = stringViewFromLiteral("abcdefg");
    StringView referenceUTF8 = stringViewFromLiteral("àîûèô");

    StringView prefix = stringViewFromLiteral("abc");
    StringView prefixUTF8 = stringViewFromLiteral("àîû");

    EXPECT_TRUE(reference.startsWith(prefix));
    EXPECT_TRUE(referenceUTF8.startsWith(prefixUTF8));
}

Got it pass in debug build. What do you think?
Comment 8 Dhi Aurrahman 2015-03-17 21:25:32 PDT
Created attachment 248907 [details]
Patch
Comment 9 Dhi Aurrahman 2015-03-17 21:26:23 PDT
Comment on attachment 248907 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248907&action=review

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:491
> +    EXPECT_FALSE(referenceUTF8.endsWithIgnoringASCIICase(reference));

I'm not sure about this
Comment 10 Darin Adler 2015-03-18 08:35:32 PDT
Comment on attachment 248907 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248907&action=review

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:221
> +StringView stringViewFromLiteral(const char* characters)
> +{
> +    return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
> +}

This is great.

> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:226
> +StringView stringViewFromUTF8(const char* characters)
> +{
> +    return String::fromUTF8(characters);
> +}

This won’t work. The string is deleted when the function returns and the StringView is left pointing to deleted memory.
Comment 11 Dhi Aurrahman 2015-03-18 09:17:56 PDT
Comment on attachment 248907 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=248907&action=review

>> Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:226
>> +}
> 
> This won’t work. The string is deleted when the function returns and the StringView is left pointing to deleted memory.

Honestly, I'm not sure how to create the 16-bit flavor of it.
Comment 12 Dhi Aurrahman 2015-03-18 13:28:19 PDT
Created attachment 248956 [details]
Patch
Comment 13 Dhi Aurrahman 2015-03-18 13:31:34 PDT
Comment on attachment 248956 [details]
Patch

Hope this will work. Thanks to Benjamin for the tip.
Comment 14 Dhi Aurrahman 2015-03-18 17:27:18 PDT
Created attachment 248994 [details]
Patch for landing
Comment 15 WebKit Commit Bot 2015-03-18 18:11:01 PDT
Comment on attachment 248994 [details]
Patch for landing

Clearing flags on attachment: 248994

Committed r181717: <http://trac.webkit.org/changeset/181717>
Comment 16 WebKit Commit Bot 2015-03-18 18:11:05 PDT
All reviewed patches have been landed.  Closing bug.