From 9364b353d4f6b940d780f843d8b6c19380c4aef8 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 1 Jul 2020 08:42:31 +0000 Subject: [PATCH] Bug 1648010 - Remove NS_NAMED_LITERAL_CSTRING and NS_NAMED_LITERAL_STRING macros. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D80631 --- accessible/base/nsCoreUtils.cpp | 4 +- accessible/windows/msaa/Compatibility.cpp | 20 ++- accessible/windows/msaa/CompatibilityUIA.cpp | 2 +- accessible/windows/msaa/Platform.cpp | 2 +- caps/BasePrincipal.cpp | 2 +- caps/tests/gtest/TestOriginAttributes.cpp | 7 +- chrome/nsChromeRegistry.cpp | 2 +- docshell/base/nsPingListener.cpp | 2 +- dom/base/BodyUtil.cpp | 5 +- dom/base/Document.cpp | 2 +- dom/base/Navigator.cpp | 4 +- dom/base/Selection.cpp | 4 +- dom/base/nsJSEnvironment.cpp | 2 +- dom/base/nsObjectLoadingContent.cpp | 2 +- dom/base/nsXMLContentSerializer.cpp | 6 +- dom/base/test/gtest/TestParser.cpp | 7 +- dom/cache/QuotaClient.cpp | 2 +- dom/canvas/CanvasRenderingContext2D.cpp | 2 +- dom/canvas/CanvasRenderingContextHelper.cpp | 2 +- dom/file/uri/BlobURLProtocolHandler.cpp | 10 +- dom/filesystem/FileSystemUtils.cpp | 4 +- dom/html/HTMLMediaElement.cpp | 2 +- dom/html/PluginDocument.cpp | 4 +- dom/indexedDB/ActorsParent.cpp | 95 +++++++------- dom/indexedDB/ProfilerHelpers.h | 2 +- dom/ipc/ContentParent.cpp | 5 +- dom/jsurl/nsJSProtocolHandler.cpp | 4 +- dom/localstorage/ActorsParent.cpp | 4 +- dom/media/VideoUtils.cpp | 2 +- dom/media/eme/MediaKeySystemAccess.cpp | 14 +-- dom/media/eme/mediadrm/MediaDrmCDMProxy.cpp | 7 +- dom/media/gmp/ChromiumCDMParent.cpp | 4 +- dom/media/gmp/ChromiumCDMProxy.cpp | 2 +- dom/media/gtest/TestCDMStorage.cpp | 68 +++++----- .../android/AndroidDecoderModule.cpp | 4 +- dom/plugins/base/nsPluginHost.cpp | 4 +- dom/plugins/base/nsPluginInstanceOwner.cpp | 2 +- dom/plugins/base/nsPluginsDirUnix.cpp | 4 +- dom/plugins/ipc/FunctionHook.cpp | 2 +- dom/plugins/ipc/PluginModuleChild.cpp | 2 +- dom/plugins/ipc/PluginModuleParent.cpp | 10 +- dom/quota/ActorsParent.cpp | 10 +- dom/quota/PersistenceType.cpp | 6 +- dom/quota/QuotaCommon.cpp | 4 +- dom/quota/test/gtest/TestQuotaManager.cpp | 4 +- dom/script/ScriptLoader.cpp | 2 +- dom/security/nsContentSecurityUtils.cpp | 40 +++--- .../test/gtest/TestFilenameEvalParser.cpp | 118 +++++++++--------- dom/serviceworkers/ServiceWorkerContainer.cpp | 2 +- dom/simpledb/ActorsParent.cpp | 2 +- dom/u2f/U2F.cpp | 13 +- dom/u2f/U2FAuthenticator.h | 2 +- dom/webauthn/AndroidWebAuthnTokenManager.h | 22 ++-- dom/webauthn/U2FSoftTokenManager.cpp | 2 +- dom/webauthn/WebAuthnManagerBase.cpp | 4 +- dom/webauthn/WebAuthnUtil.cpp | 9 +- .../WebBrowserPersistLocalDocument.cpp | 2 +- dom/workers/RuntimeService.cpp | 4 +- dom/xml/nsXMLContentSink.cpp | 4 +- dom/xslt/xslt/txMozillaXSLTProcessor.cpp | 4 +- dom/xul/nsXULContentSink.cpp | 4 +- editor/libeditor/CSSEditUtils.cpp | 2 +- editor/libeditor/HTMLEditSubActionHandler.cpp | 4 +- editor/libeditor/HTMLEditor.cpp | 4 +- editor/libeditor/HTMLEditorObjectResizer.cpp | 2 +- editor/libeditor/TextEditor.cpp | 2 +- extensions/auth/nsAuthGSSAPI.cpp | 4 +- .../pref/autoconfig/src/nsReadConfig.cpp | 2 +- image/ImageMemoryReporter.cpp | 2 +- intl/strres/nsStringBundle.cpp | 5 +- ipc/glue/GeckoChildProcessHost.cpp | 2 +- js/xpconnect/loader/ScriptPreloader.cpp | 2 +- js/xpconnect/src/XPCJSRuntime.cpp | 6 +- layout/base/AccessibleCaret.cpp | 5 +- layout/base/PresShell.cpp | 4 +- layout/generic/nsImageFrame.cpp | 6 +- layout/generic/nsPageFrame.cpp | 12 +- layout/mathml/nsMathMLContainerFrame.cpp | 2 +- layout/printing/nsPrintJob.cpp | 2 +- layout/style/test/gtest/StyloParsingBench.cpp | 2 +- layout/xul/nsMenuBarFrame.cpp | 4 +- layout/xul/tree/nsTreeBodyFrame.cpp | 2 +- layout/xul/tree/nsTreeSelection.cpp | 4 +- .../src/common/browser_logging/WebRtcLog.cpp | 2 +- modules/libpref/Preferences.cpp | 2 +- mozglue/tests/gtest/TestDLLBlocklist.cpp | 10 +- netwerk/base/CaptivePortalService.cpp | 2 +- netwerk/base/nsIncrementalDownload.cpp | 2 +- netwerk/base/nsURLHelperOSX.cpp | 2 +- netwerk/base/nsURLHelperUnix.cpp | 2 +- netwerk/base/nsURLHelperWin.cpp | 2 +- netwerk/cookie/CookiePersistentStorage.cpp | 8 +- netwerk/cookie/CookieService.cpp | 10 +- netwerk/dns/TRRService.cpp | 4 +- netwerk/protocol/about/nsAboutCacheEntry.cpp | 14 +-- netwerk/protocol/data/nsDataHandler.cpp | 6 +- netwerk/protocol/http/AlternateServices.cpp | 4 +- netwerk/protocol/http/HttpTrafficAnalyzer.cpp | 2 +- netwerk/protocol/http/nsHttpChannel.cpp | 4 +- netwerk/protocol/http/nsHttpHandler.cpp | 4 +- .../viewsource/nsViewSourceChannel.cpp | 2 +- netwerk/test/gtest/TestIsValidIp.cpp | 73 ++++++----- .../manager/ssl/ContentSignatureVerifier.cpp | 2 +- security/manager/ssl/LocalCertService.cpp | 6 +- security/manager/ssl/nsNSSCallbacks.cpp | 5 +- security/manager/ssl/nsNSSComponent.cpp | 15 ++- .../manager/ssl/nsSiteSecurityService.cpp | 4 +- .../ssl/tests/gtest/DataStorageTest.cpp | 10 +- .../ssl/tests/gtest/TLSIntoleranceTest.cpp | 8 +- startupcache/test/TestStartupCache.cpp | 2 +- storage/mozStorageService.cpp | 17 ++- .../antitracking/ContentBlockingLog.cpp | 2 +- .../components/extensions/MatchPattern.cpp | 2 +- .../components/telemetry/core/Telemetry.cpp | 10 +- .../telemetry/core/TelemetryHistogram.cpp | 2 +- .../telemetry/core/TelemetryOrigin.cpp | 2 +- .../gtest/TestGeckoViewStreaming.cpp | 17 ++- .../telemetry/other/UntrustedModules.cpp | 4 +- .../telemetry/tests/gtest/TestOrigins.cpp | 26 ++-- .../extensions/AddonManagerStartup.cpp | 2 +- toolkit/profile/nsProfileLock.cpp | 10 +- .../nsWindowsSystemProxySettings.cpp | 2 +- toolkit/xre/nsAppRunner.cpp | 6 +- toolkit/xre/nsGDKErrorHandler.cpp | 8 +- toolkit/xre/nsNativeAppSupportUnix.cpp | 2 +- toolkit/xre/nsXREDirProvider.cpp | 18 +-- tools/profiler/core/shared-libraries-win32.cc | 2 +- uriloader/base/nsURILoader.cpp | 4 +- uriloader/exthandler/win/nsMIMEInfoWin.cpp | 4 +- widget/gtk/nsLookAndFeel.cpp | 2 +- widget/nsPrintSettingsService.cpp | 2 +- widget/windows/GfxInfo.cpp | 8 +- widget/windows/WinUtils.cpp | 2 +- widget/windows/nsDataObj.cpp | 4 +- widget/windows/tests/TestWinDND.cpp | 4 +- xpcom/build/Omnijar.cpp | 2 +- xpcom/components/ManifestParser.cpp | 28 ++--- xpcom/io/FileUtilsWin.h | 10 +- xpcom/io/nsLocalFileCommon.cpp | 2 +- xpcom/io/nsLocalFileWin.cpp | 6 +- xpcom/string/nsLiteralString.h | 2 - xpcom/tests/gtest/TestArenaAllocator.cpp | 4 +- xpcom/tests/gtest/TestBase64.cpp | 4 +- xpcom/tests/gtest/TestStrings.cpp | 4 +- xpcom/tests/gtest/TestTokenizer.cpp | 10 +- 145 files changed, 537 insertions(+), 576 deletions(-) diff --git a/accessible/base/nsCoreUtils.cpp b/accessible/base/nsCoreUtils.cpp index 49e0126001b4..cdb2eb9e485f 100644 --- a/accessible/base/nsCoreUtils.cpp +++ b/accessible/base/nsCoreUtils.cpp @@ -377,8 +377,8 @@ bool nsCoreUtils::IsErrorPage(Document* aDocument) { nsAutoCString path; uri->GetPathQueryRef(path); - NS_NAMED_LITERAL_CSTRING(neterror, "neterror"); - NS_NAMED_LITERAL_CSTRING(certerror, "certerror"); + constexpr auto neterror = "neterror"_ns; + constexpr auto certerror = "certerror"_ns; return StringBeginsWith(path, neterror) || StringBeginsWith(path, certerror); } diff --git a/accessible/windows/msaa/Compatibility.cpp b/accessible/windows/msaa/Compatibility.cpp index 918da4e7be38..e0455f5c9091 100644 --- a/accessible/windows/msaa/Compatibility.cpp +++ b/accessible/windows/msaa/Compatibility.cpp @@ -295,12 +295,12 @@ static bool IsSystemOleAcc(nsCOMPtr& aFile) { static bool IsTypelibPreferred() { // If IAccessible's Proxy/Stub CLSID is kUniversalMarshalerClsid, then any // external a11y clients are expecting to use a typelib. - NS_NAMED_LITERAL_STRING(kUniversalMarshalerClsid, - "{00020424-0000-0000-C000-000000000046}"); + constexpr auto kUniversalMarshalerClsid = + u"{00020424-0000-0000-C000-000000000046}"_ns; - NS_NAMED_LITERAL_STRING( - kIAccessiblePSClsidPath, - "Interface\\{618736E0-3C3D-11CF-810C-00AA00389B71}\\ProxyStubClsid32"); + constexpr auto kIAccessiblePSClsidPath = + "Interface\\{618736E0-3C3D-11CF-810C-00AA00389B71}" + u"\\ProxyStubClsid32"_ns; nsAutoString psClsid; if (!ReadCOMRegDefaultString(kIAccessiblePSClsidPath, psClsid)) { @@ -314,9 +314,8 @@ static bool IsTypelibPreferred() { static bool IsIAccessibleTypelibRegistered() { // The system default IAccessible typelib is always registered with version // 1.1, under the neutral locale (LCID 0). - NS_NAMED_LITERAL_STRING( - kIAccessibleTypelibRegPath, - "TypeLib\\{1EA4DBF0-3C3B-11CF-810C-00AA00389B71}\\1.1\\0\\win32"); + constexpr auto kIAccessibleTypelibRegPath = + u"TypeLib\\{1EA4DBF0-3C3B-11CF-810C-00AA00389B71}\\1.1\\0\\win32"_ns; nsAutoString typelibPath; if (!ReadCOMRegDefaultString(kIAccessibleTypelibRegPath, typelibPath)) { @@ -334,9 +333,8 @@ static bool IsIAccessibleTypelibRegistered() { } static bool IsIAccessiblePSRegistered() { - NS_NAMED_LITERAL_STRING( - kIAccessiblePSRegPath, - "CLSID\\{03022430-ABC4-11D0-BDE2-00AA001A1953}\\InProcServer32"); + constexpr auto kIAccessiblePSRegPath = + u"CLSID\\{03022430-ABC4-11D0-BDE2-00AA001A1953}\\InProcServer32"_ns; nsAutoString proxyStubPath; if (!ReadCOMRegDefaultString(kIAccessiblePSRegPath, proxyStubPath)) { diff --git a/accessible/windows/msaa/CompatibilityUIA.cpp b/accessible/windows/msaa/CompatibilityUIA.cpp index 9d26b1145c06..7d803dd10232 100644 --- a/accessible/windows/msaa/CompatibilityUIA.cpp +++ b/accessible/windows/msaa/CompatibilityUIA.cpp @@ -161,7 +161,7 @@ Maybe Compatibility::OnUIAMessage(WPARAM aWParam, LPARAM aLParam) { Telemetry::AutoTimer timer; // UIA creates a section containing the substring "HOOK_SHMEM_" - NS_NAMED_LITERAL_STRING(kStrHookShmem, "HOOK_SHMEM_"); + constexpr auto kStrHookShmem = u"HOOK_SHMEM_"_ns; // The section name always ends with this suffix, which is derived from the // current thread id and the UIA message's WPARAM and LPARAM. diff --git a/accessible/windows/msaa/Platform.cpp b/accessible/windows/msaa/Platform.cpp index 0d90f6a47c6b..196358a04f3c 100644 --- a/accessible/windows/msaa/Platform.cpp +++ b/accessible/windows/msaa/Platform.cpp @@ -284,7 +284,7 @@ static void AppendVersionInfo(nsIFile* aClientExe, nsAString& aStrToAppend) { aStrToAppend.AppendLiteral(u"|"); - NS_NAMED_LITERAL_STRING(dot, "."); + constexpr auto dot = u"."_ns; aStrToAppend.AppendInt(major); aStrToAppend.Append(dot); diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index 3296b9c4f9ad..975364125e09 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -667,7 +667,7 @@ NS_IMETHODIMP BasePrincipal::GetPrefLightCacheKey(nsIURI* aURI, bool aWithCredentials, nsACString& _retval) { _retval.Truncate(); - NS_NAMED_LITERAL_CSTRING(space, " "); + constexpr auto space = " "_ns; nsCOMPtr uri; nsresult rv = GetURI(getter_AddRefs(uri)); diff --git a/caps/tests/gtest/TestOriginAttributes.cpp b/caps/tests/gtest/TestOriginAttributes.cpp index 2fd18da25b73..55b2020e319e 100644 --- a/caps/tests/gtest/TestOriginAttributes.cpp +++ b/caps/tests/gtest/TestOriginAttributes.cpp @@ -110,10 +110,9 @@ TEST(OriginAttributes, NullPrincipal) bool oldSitePref = Preferences::GetBool(SITE_PREF); Preferences::SetBool(SITE_PREF, true); - NS_NAMED_LITERAL_STRING( - spec, "moz-nullprincipal:{9bebdabb-828a-4284-8b00-432a968c6e42}"); - NS_NAMED_LITERAL_STRING(expected, - "9bebdabb-828a-4284-8b00-432a968c6e42.mozilla"); + constexpr auto spec = + u"moz-nullprincipal:{9bebdabb-828a-4284-8b00-432a968c6e42}"_ns; + constexpr auto expected = u"9bebdabb-828a-4284-8b00-432a968c6e42.mozilla"_ns; nsCOMPtr uri; NS_NewURI(getter_AddRefs(uri), spec); diff --git a/chrome/nsChromeRegistry.cpp b/chrome/nsChromeRegistry.cpp index d901a2bfbb7e..7b761070445a 100644 --- a/chrome/nsChromeRegistry.cpp +++ b/chrome/nsChromeRegistry.cpp @@ -170,7 +170,7 @@ nsresult nsChromeRegistry::GetProviderAndPath(nsIURI* aChromeURL, } nsresult nsChromeRegistry::Canonify(nsCOMPtr& aChromeURL) { - NS_NAMED_LITERAL_CSTRING(kSlash, "/"); + constexpr auto kSlash = "/"_ns; nsresult rv; diff --git a/docshell/base/nsPingListener.cpp b/docshell/base/nsPingListener.cpp index 85c01626f484..94a8e36cda28 100644 --- a/docshell/base/nsPingListener.cpp +++ b/docshell/base/nsPingListener.cpp @@ -193,7 +193,7 @@ static void SendPing(void* aClosure, nsIContent* aContent, nsIURI* aURI, return; } - NS_NAMED_LITERAL_CSTRING(uploadData, "PING"); + constexpr auto uploadData = "PING"_ns; nsCOMPtr uploadStream; rv = NS_NewCStringInputStream(getter_AddRefs(uploadStream), uploadData); diff --git a/dom/base/BodyUtil.cpp b/dom/base/BodyUtil.cpp index ec8c9519b888..e93332ef0d14 100644 --- a/dom/base/BodyUtil.cpp +++ b/dom/base/BodyUtil.cpp @@ -420,7 +420,7 @@ already_AddRefed BodyUtil::ConsumeFormData(nsIGlobalObject* aParent, const nsCString& aMimeType, const nsCString& aStr, ErrorResult& aRv) { - NS_NAMED_LITERAL_CSTRING(formDataMimeType, "multipart/form-data"); + constexpr auto formDataMimeType = "multipart/form-data"_ns; // Allow semicolon separated boundary/encoding suffix like // multipart/form-data; boundary= but disallow multipart/form-datafoobar. @@ -443,8 +443,7 @@ already_AddRefed BodyUtil::ConsumeFormData(nsIGlobalObject* aParent, return fd.forget(); } - NS_NAMED_LITERAL_CSTRING(urlDataMimeType, - "application/x-www-form-urlencoded"); + constexpr auto urlDataMimeType = "application/x-www-form-urlencoded"_ns; bool isValidUrlEncodedMimeType = StringBeginsWith(aMimeType, urlDataMimeType); if (isValidUrlEncodedMimeType && diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 892e17511dc0..36b0c986873f 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -9083,7 +9083,7 @@ void Document::WriteCommon(const nsAString& aText, bool aNewlineTerminate, } } - static NS_NAMED_LITERAL_STRING(new_line, "\n"); + static constexpr auto new_line = u"\n"_ns; ++mWriteLevel; diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index 8bc4b5800a49..6efc6edd724a 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -650,7 +650,7 @@ class VibrateWindowListener : public nsIDOMEventListener { mWindow = do_GetWeakReference(aWindow); mDocument = do_GetWeakReference(aDocument); - NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange"); + constexpr auto visibilitychange = u"visibilitychange"_ns; aDocument->AddSystemEventListener(visibilitychange, this, /* listener */ true, /* use capture */ false /* wants untrusted */); @@ -701,7 +701,7 @@ void VibrateWindowListener::RemoveListener() { if (!target) { return; } - NS_NAMED_LITERAL_STRING(visibilitychange, "visibilitychange"); + constexpr auto visibilitychange = u"visibilitychange"_ns; target->RemoveSystemEventListener(visibilitychange, this, true /* use capture */); } diff --git a/dom/base/Selection.cpp b/dom/base/Selection.cpp index c63400683b80..9970e5059e7a 100644 --- a/dom/base/Selection.cpp +++ b/dom/base/Selection.cpp @@ -3514,8 +3514,8 @@ void Selection::SetColors(const nsAString& aForegroundColor, mCustomColors.reset(new SelectionCustomColors); - NS_NAMED_LITERAL_STRING(currentColorStr, "currentColor"); - NS_NAMED_LITERAL_STRING(transparentStr, "transparent"); + constexpr auto currentColorStr = u"currentColor"_ns; + constexpr auto transparentStr = u"transparent"_ns; if (!aForegroundColor.Equals(currentColorStr)) { nscolor foregroundColor; diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 2c54b5aa8f4c..ed00a8018407 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -510,7 +510,7 @@ class ScriptErrorEvent : public Runnable { init.mFilename = mReport->mFileName; init.mBubbles = true; - NS_NAMED_LITERAL_STRING(xoriginMsg, "Script error."); + constexpr auto xoriginMsg = u"Script error."_ns; if (!mReport->mIsMuted) { init.mMessage = mReport->mErrorMsg; init.mLineno = mReport->mLineNumber; diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index 97abad22f62f..60cea9f51222 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -810,7 +810,7 @@ void nsObjectLoadingContent::GetNestedParams( do_QueryInterface(static_cast(this)); nsCOMPtr allParams; - NS_NAMED_LITERAL_STRING(xhtml_ns, "http://www.w3.org/1999/xhtml"); + constexpr auto xhtml_ns = u"http://www.w3.org/1999/xhtml"_ns; ErrorResult rv; allParams = ourElement->GetElementsByTagNameNS(xhtml_ns, u"param"_ns, rv); if (rv.Failed()) { diff --git a/dom/base/nsXMLContentSerializer.cpp b/dom/base/nsXMLContentSerializer.cpp index a5cd26baf6a8..0c91fe8f758e 100644 --- a/dom/base/nsXMLContentSerializer.cpp +++ b/dom/base/nsXMLContentSerializer.cpp @@ -220,7 +220,7 @@ nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection, nsresult rv; - NS_NAMED_LITERAL_STRING(cdata, " 0) { NS_ENSURE_TRUE(AppendToString(cdata, *mOutput), NS_ERROR_OUT_OF_MEMORY); @@ -316,7 +316,7 @@ nsXMLContentSerializer::AppendComment(Comment* aComment, int32_t aStartOffset, NS_ENSURE_TRUE(MaybeAddNewlineForRootNode(*mOutput), NS_ERROR_OUT_OF_MEMORY); - NS_NAMED_LITERAL_STRING(startComment, ""); + constexpr auto fragmentHeaderString = ""_ns; nsDependentCString trailingString( "\r\n" diff --git a/widget/windows/tests/TestWinDND.cpp b/widget/windows/tests/TestWinDND.cpp index e9c76463eba9..51e43cf19e91 100644 --- a/widget/windows/tests/TestWinDND.cpp +++ b/widget/windows/tests/TestWinDND.cpp @@ -167,7 +167,7 @@ nsresult GetTransferableFile(nsCOMPtr& pTransferable) { nsresult GetTransferableText(nsCOMPtr& pTransferable) { nsresult rv; - NS_NAMED_LITERAL_STRING(mozString, "Mozilla can drag and drop"); + constexpr auto mozString = u"Mozilla can drag and drop"_ns; nsCOMPtr xferString = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID); rv = xferString->SetData(mozString); @@ -184,7 +184,7 @@ nsresult GetTransferableText(nsCOMPtr& pTransferable) { nsresult GetTransferableTextTwo(nsCOMPtr& pTransferable) { nsresult rv; - NS_NAMED_LITERAL_STRING(mozString, " twice over"); + constexpr auto mozString = u" twice over"_ns; nsCOMPtr xferString = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID); rv = xferString->SetData(mozString); diff --git a/xpcom/build/Omnijar.cpp b/xpcom/build/Omnijar.cpp index 7f0149aeba7e..36a8a511cbeb 100644 --- a/xpcom/build/Omnijar.cpp +++ b/xpcom/build/Omnijar.cpp @@ -44,7 +44,7 @@ void Omnijar::InitOne(nsIFile* aPath, Type aType) { nsCOMPtr dir; nsDirectoryService::gService->Get(SPROP(aType), NS_GET_IID(nsIFile), getter_AddRefs(dir)); - NS_NAMED_LITERAL_CSTRING(kOmnijarName, MOZ_STRINGIFY(OMNIJAR_NAME)); + constexpr auto kOmnijarName = nsLiteralCString{MOZ_STRINGIFY(OMNIJAR_NAME)}; if (NS_FAILED(dir->Clone(getter_AddRefs(file))) || NS_FAILED(file->AppendNative(kOmnijarName))) { return; diff --git a/xpcom/components/ManifestParser.cpp b/xpcom/components/ManifestParser.cpp index d91609f355f8..efb45d411303 100644 --- a/xpcom/components/ManifestParser.cpp +++ b/xpcom/components/ManifestParser.cpp @@ -389,25 +389,25 @@ void ParseManifest(NSLocationType aType, FileLocation& aFile, char* aBuf, nsChromeRegistry::ManifestProcessingContext chromecx(aType, aFile); nsresult rv; - NS_NAMED_LITERAL_STRING(kContentAccessible, "contentaccessible"); - NS_NAMED_LITERAL_STRING(kRemoteEnabled, "remoteenabled"); - NS_NAMED_LITERAL_STRING(kRemoteRequired, "remoterequired"); - NS_NAMED_LITERAL_STRING(kApplication, "application"); - NS_NAMED_LITERAL_STRING(kAppVersion, "appversion"); - NS_NAMED_LITERAL_STRING(kGeckoVersion, "platformversion"); - NS_NAMED_LITERAL_STRING(kOs, "os"); - NS_NAMED_LITERAL_STRING(kOsVersion, "osversion"); - NS_NAMED_LITERAL_STRING(kABI, "abi"); - NS_NAMED_LITERAL_STRING(kProcess, "process"); + constexpr auto kContentAccessible = u"contentaccessible"_ns; + constexpr auto kRemoteEnabled = u"remoteenabled"_ns; + constexpr auto kRemoteRequired = u"remoterequired"_ns; + constexpr auto kApplication = u"application"_ns; + constexpr auto kAppVersion = u"appversion"_ns; + constexpr auto kGeckoVersion = u"platformversion"_ns; + constexpr auto kOs = u"os"_ns; + constexpr auto kOsVersion = u"osversion"_ns; + constexpr auto kABI = u"abi"_ns; + constexpr auto kProcess = u"process"_ns; #if defined(MOZ_WIDGET_ANDROID) - NS_NAMED_LITERAL_STRING(kTablet, "tablet"); + constexpr auto kTablet = u"tablet"_ns; #endif - NS_NAMED_LITERAL_STRING(kMain, "main"); - NS_NAMED_LITERAL_STRING(kContent, "content"); + constexpr auto kMain = u"main"_ns; + constexpr auto kContent = u"content"_ns; // Obsolete - NS_NAMED_LITERAL_STRING(kXPCNativeWrappers, "xpcnativewrappers"); + constexpr auto kXPCNativeWrappers = u"xpcnativewrappers"_ns; nsAutoString appID; nsAutoString appVersion; diff --git a/xpcom/io/FileUtilsWin.h b/xpcom/io/FileUtilsWin.h index d848c6bd4851..6a1f3dc06219 100644 --- a/xpcom/io/FileUtilsWin.h +++ b/xpcom/io/FileUtilsWin.h @@ -41,7 +41,7 @@ inline bool NtPathToDosPath(const nsAString& aNtPath, nsAString& aDosPath) { if (aNtPath.IsEmpty()) { return true; } - NS_NAMED_LITERAL_STRING(symLinkPrefix, "\\??\\"); + constexpr auto symLinkPrefix = u"\\??\\"_ns; uint32_t ntPathLen = aNtPath.Length(); uint32_t symLinkPrefixLen = symLinkPrefix.Length(); if (ntPathLen >= 6 && aNtPath.CharAt(5) == L':' && @@ -120,15 +120,15 @@ inline bool NtPathToDosPath(const nsAString& aNtPath, nsAString& aDosPath) { } // Try to handle UNC paths. NB: This must happen after we've checked drive // mappings in case a UNC path is mapped to a drive! - NS_NAMED_LITERAL_STRING(uncPrefix, "\\\\"); - NS_NAMED_LITERAL_STRING(deviceMupPrefix, "\\Device\\Mup\\"); + constexpr auto uncPrefix = u"\\\\"_ns; + constexpr auto deviceMupPrefix = u"\\Device\\Mup\\"_ns; if (StringBeginsWith(aNtPath, deviceMupPrefix)) { aDosPath = uncPrefix; aDosPath += Substring(aNtPath, deviceMupPrefix.Length()); return true; } - NS_NAMED_LITERAL_STRING(deviceLanmanRedirectorPrefix, - "\\Device\\LanmanRedirector\\"); + constexpr auto deviceLanmanRedirectorPrefix = + u"\\Device\\LanmanRedirector\\"_ns; if (StringBeginsWith(aNtPath, deviceLanmanRedirectorPrefix)) { aDosPath = uncPrefix; aDosPath += Substring(aNtPath, deviceLanmanRedirectorPrefix.Length()); diff --git a/xpcom/io/nsLocalFileCommon.cpp b/xpcom/io/nsLocalFileCommon.cpp index 5d247eb85801..ba690482a986 100644 --- a/xpcom/io/nsLocalFileCommon.cpp +++ b/xpcom/io/nsLocalFileCommon.cpp @@ -354,7 +354,7 @@ nsLocalFile::GetRelativeDescriptor(nsIFile* aFromFile, nsACString& aResult) { NS_IMETHODIMP nsLocalFile::SetRelativeDescriptor(nsIFile* aFromFile, const nsACString& aRelativeDesc) { - NS_NAMED_LITERAL_CSTRING(kParentDirStr, "../"); + constexpr auto kParentDirStr = "../"_ns; nsCOMPtr targetFile; nsresult rv = aFromFile->Clone(getter_AddRefs(targetFile)); diff --git a/xpcom/io/nsLocalFileWin.cpp b/xpcom/io/nsLocalFileWin.cpp index b8ba28381f83..063e637af222 100644 --- a/xpcom/io/nsLocalFileWin.cpp +++ b/xpcom/io/nsLocalFileWin.cpp @@ -960,8 +960,8 @@ static void StripRundll32(nsString& aCommandString) { // C:\Windows\System32\rundll32.exe "path to dll", var var // rundll32.exe "path to dll", var var - NS_NAMED_LITERAL_STRING(rundllSegment, "rundll32.exe "); - NS_NAMED_LITERAL_STRING(rundllSegmentShort, "rundll32 "); + constexpr auto rundllSegment = u"rundll32.exe "_ns; + constexpr auto rundllSegmentShort = u"rundll32 "_ns; // case insensitive int32_t strLen = rundllSegment.Length(); @@ -1197,7 +1197,7 @@ nsresult nsLocalFile::AppendInternal(const nsString& aNode, // "foo..foo", "..foo", and "foo.." are not falsely detected, // but the invalid paths "..\", "foo\..", "foo\..\foo", // "..\foo", etc are. - NS_NAMED_LITERAL_STRING(doubleDot, "\\.."); + constexpr auto doubleDot = u"\\.."_ns; nsAString::const_iterator start, end, offset; aNode.BeginReading(start); aNode.EndReading(end); diff --git a/xpcom/string/nsLiteralString.h b/xpcom/string/nsLiteralString.h index 557ac27ad386..72c41f7e06e3 100644 --- a/xpcom/string/nsLiteralString.h +++ b/xpcom/string/nsLiteralString.h @@ -22,11 +22,9 @@ #define NS_LITERAL_STRING(s) \ static_cast(nsLiteralString(u"" s)) -#define NS_NAMED_LITERAL_STRING(n, s) const nsLiteralString n(u"" s) #define NS_LITERAL_CSTRING(s) \ static_cast(nsLiteralCString("" s)) -#define NS_NAMED_LITERAL_CSTRING(n, s) const nsLiteralCString n("" s) constexpr auto operator""_ns(const char* aStr, std::size_t aLen) { return nsLiteralCString{aStr, aLen}; diff --git a/xpcom/tests/gtest/TestArenaAllocator.cpp b/xpcom/tests/gtest/TestArenaAllocator.cpp index fdb9ba8af3cd..ed13d629796f 100644 --- a/xpcom/tests/gtest/TestArenaAllocator.cpp +++ b/xpcom/tests/gtest/TestArenaAllocator.cpp @@ -293,11 +293,11 @@ TEST(ArenaAllocator, Extensions) EXPECT_TRUE(nsString(dup).Equals(kTestStr)); // Make sure it works with literal strings. - NS_NAMED_LITERAL_STRING(wideStr, "A wide string."); + constexpr auto wideStr = u"A wide string."_ns; nsLiteralString::char_type* wide = mozilla::ArenaStrdup(wideStr, a); EXPECT_TRUE(wideStr.Equals(wide)); - NS_NAMED_LITERAL_CSTRING(cStr, "A c-string."); + constexpr auto cStr = "A c-string."_ns; nsLiteralCString::char_type* cstr = mozilla::ArenaStrdup(cStr, a); EXPECT_TRUE(cStr.Equals(cstr)); diff --git a/xpcom/tests/gtest/TestBase64.cpp b/xpcom/tests/gtest/TestBase64.cpp index 8814f3c5a8e1..b360b6f3f924 100644 --- a/xpcom/tests/gtest/TestBase64.cpp +++ b/xpcom/tests/gtest/TestBase64.cpp @@ -391,7 +391,7 @@ TEST(Base64, DecodeNon8BitWideString) TEST(Base64, TruncateOnInvalidDecodeCString) { - NS_NAMED_LITERAL_CSTRING(invalid, "@@=="); + constexpr auto invalid = "@@=="_ns; nsAutoCString out("I should be truncated!"); nsresult rv = mozilla::Base64Decode(invalid, out); ASSERT_TRUE(NS_FAILED(rv)); @@ -400,7 +400,7 @@ TEST(Base64, TruncateOnInvalidDecodeCString) TEST(Base64, TruncateOnInvalidDecodeWideString) { - NS_NAMED_LITERAL_STRING(invalid, "@@=="); + constexpr auto invalid = u"@@=="_ns; nsAutoString out(u"I should be truncated!"); nsresult rv = mozilla::Base64Decode(invalid, out); ASSERT_TRUE(NS_FAILED(rv)); diff --git a/xpcom/tests/gtest/TestStrings.cpp b/xpcom/tests/gtest/TestStrings.cpp index 513643eb9b5e..28a6eb7acb8e 100644 --- a/xpcom/tests/gtest/TestStrings.cpp +++ b/xpcom/tests/gtest/TestStrings.cpp @@ -581,7 +581,7 @@ TEST_F(Strings, assign_c) { } TEST_F(Strings, test1) { - NS_NAMED_LITERAL_STRING(empty, ""); + constexpr auto empty = u""_ns; const nsAString& aStr = empty; nsAutoString buf(aStr); @@ -2463,7 +2463,7 @@ CONVERSION_BENCH(PerfUTF8toUTF16VIThousand, CopyUTF8toUTF16, mViThousandUtf8, // Tests for usability of nsTLiteralString in constant expressions. static_assert(u""_ns.IsEmpty()); -constexpr auto testStringA = NS_LITERAL_STRING("a"); +constexpr auto testStringA = u"a"_ns; static_assert(!testStringA.IsEmpty()); static_assert(!testStringA.IsVoid()); static_assert(testStringA.IsLiteral()); diff --git a/xpcom/tests/gtest/TestTokenizer.cpp b/xpcom/tests/gtest/TestTokenizer.cpp index 45b133d42918..73e6327ca4e7 100644 --- a/xpcom/tests/gtest/TestTokenizer.cpp +++ b/xpcom/tests/gtest/TestTokenizer.cpp @@ -974,7 +974,7 @@ TEST(Tokenizer, Incremental) return NS_OK; }); - NS_NAMED_LITERAL_CSTRING(input, "test1,test2,,,test3"); + constexpr auto input = "test1,test2,,,test3"_ns; auto cur = input.BeginReading(); auto end = input.EndReading(); for (; cur < end; ++cur) { @@ -1027,7 +1027,7 @@ TEST(Tokenizer, IncrementalRollback) return NS_OK; }); - NS_NAMED_LITERAL_CSTRING(input, "test1,test2,,,test3"); + constexpr auto input = "test1,test2,,,test3"_ns; auto cur = input.BeginReading(); auto end = input.EndReading(); for (; cur < end; ++cur) { @@ -1078,7 +1078,7 @@ TEST(Tokenizer, IncrementalNeedMoreInput) return NS_OK; }); - NS_NAMED_LITERAL_CSTRING(input, "a bb,c"); + constexpr auto input = "a bb,c"_ns; auto cur = input.BeginReading(); auto end = input.EndReading(); @@ -1177,7 +1177,7 @@ TEST(Tokenizer, IncrementalCustomRaw) custom = i.AddCustomToken("test2", Tokenizer::CASE_SENSITIVE); i.SetTokenizingMode(Tokenizer::Mode::CUSTOM_ONLY); - NS_NAMED_LITERAL_CSTRING(input, "test1,test2!,,test3test2tes"); + constexpr auto input = "test1,test2!,,test3test2tes"_ns; auto cur = input.BeginReading(); auto end = input.EndReading(); for (; cur < end; ++cur) { @@ -1215,7 +1215,7 @@ TEST(Tokenizer, IncrementalCustomRemove) custom = i.AddCustomToken("custom1", Tokenizer::CASE_SENSITIVE); - NS_NAMED_LITERAL_CSTRING(input, "custom1custom1"); + constexpr auto input = "custom1custom1"_ns; i.FeedInput(input); EXPECT_TRUE(test == 1); i.FinishInput();