Bug 217577 - Cannot create StringImpl from empty string literal
Summary: Cannot create StringImpl from empty string literal
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-10-11 04:38 PDT by Yusuke Suzuki
Modified: 2020-10-18 04:39 PDT (History)
20 users (show)

See Also:


Attachments
Patch (7.27 KB, patch)
2020-10-11 04:42 PDT, Yusuke Suzuki
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-10-11 04:38:27 PDT
Cannot create StringImpl from empty string literal
Comment 1 Yusuke Suzuki 2020-10-11 04:42:48 PDT
Created attachment 411047 [details]
Patch
Comment 2 Darin Adler 2020-10-11 12:02:17 PDT
Comment on attachment 411047 [details]
Patch

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

> Source/JavaScriptCore/inspector/JSInjectedScriptHost.cpp:370
> +            return jsNontrivialString(vm, emptyString());

Not sure what we really need in this unreachable place, but if we want to use an empty string, then how about using jsEmptyString(vm)?

> Source/JavaScriptCore/runtime/SamplingProfiler.cpp:1033
> +        String hash = emptyString();

No initializer is needed here, since String already initializes to the null string. Note that the code below always overwrites the value of hash anyway. I would suggest initializing to "<nil>"_s and then removing the else below, or not initializing at all.

> Source/WTF/wtf/text/ASCIILiteral.h:68
> +    ASSERT_UNDER_CONSTEXPR_CONTEXT(n);

Nice! Does it work?

> Source/WebCore/page/NavigatorBase.cpp:92
> +        platformName.construct(uname(&osname) >= 0 ? String(osname.sysname) + " "_str + String(osname.machine) : emptyString());

This is seems excessively inefficient. Using emptyString() is fine, I suppose. But the code before should be makeString(osname.sysname, ' ', osname.machine) so we don’t create and destroy so many temporary strings.

> Source/WebCore/platform/UserAgentQuirks.cpp:191
> +    return emptyString();

In this unreachable place it seems like we could return ASCIILiteral::null() and the function could return ASCIILiteral. Could also return a null string instead of an empty one, which is slightly more efficient.
Comment 3 Radar WebKit Bug Importer 2020-10-18 04:39:16 PDT
<rdar://problem/70416626>