From 4c2e5e962dc3b91217c7f4dd6b38f78a75f8115d Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 1 Dec 2014 15:18:40 -0500 Subject: [PATCH] Bug 1104875. Ellipsize long unresponsive script locations so they don't make the slow script dialog too big. r=peterv --- dom/base/nsGlobalWindow.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 081e48bd9332..5db0fe9322bc 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -70,6 +70,7 @@ #include "AudioChannelService.h" #include "MessageEvent.h" #include "nsAboutProtocolUtils.h" +#include "nsCharTraits.h" // NS_IS_HIGH/LOW_SURROGATE // Interfaces Needed #include "nsIFrame.h" @@ -11073,7 +11074,32 @@ nsGlobalWindow::ShowSlowScriptDialog() // Append file and line number information, if available if (filename.get()) { nsXPIDLString scriptLocation; + // We want to drop the middle part of too-long locations. We'll + // define "too-long" as longer than 60 UTF-16 code units. Just + // have to be a bit careful about unpaired surrogates. NS_ConvertUTF8toUTF16 filenameUTF16(filename.get()); + if (filenameUTF16.Length() > 60) { + // XXXbz Do we need to insert any bidi overrides here? + size_t cutStart = 30; + size_t cutLength = filenameUTF16.Length() - 60; + MOZ_ASSERT(cutLength > 0); + if (NS_IS_LOW_SURROGATE(filenameUTF16[cutStart])) { + // Don't truncate before the low surrogate, in case it's preceded by a + // high surrogate and forms a single Unicode character. Instead, just + // include the low surrogate. + ++cutStart; + --cutLength; + } + if (NS_IS_LOW_SURROGATE(filenameUTF16[cutStart + cutLength])) { + // Likewise, don't drop a trailing low surrogate here. We want to + // increase cutLength, since it might be 0 already so we can't very well + // decrease it. + ++cutLength; + } + + // Insert U+2026 HORIZONTAL ELLIPSIS + filenameUTF16.Replace(cutStart, cutLength, NS_LITERAL_STRING("\x2026")); + } const char16_t *formatParams[] = { filenameUTF16.get() }; rv = nsContentUtils::FormatLocalizedString(nsContentUtils::eDOM_PROPERTIES, "KillScriptLocation",