Bug 1157648 - Make nsScriptError::ToString use only the first 512 characters of mSourceName and mSourceLine. r=bholley, a=bajaj
authorL. David Baron <dbaron@dbaron.org>
Mon, 27 Apr 2015 11:35:10 -0700
changeset 238291 5fd55bc7cad8ccdce043d916748bed30be641e65
parent 238290 8b83dbe19870386257f6c88e19defa6718510912
child 238292 a7fe1fb7b88b1225e87ea5430d4b604fcd4effff
push id553
push userryanvm@gmail.com
push dateFri, 01 May 2015 01:40:09 +0000
treeherdermozilla-b2g37_v2_2@5fd55bc7cad8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, bajaj
bugs1157648
milestone37.0
Bug 1157648 - Make nsScriptError::ToString use only the first 512 characters of mSourceName and mSourceLine. r=bholley, a=bajaj This means that when mSourceName and mSourceLine are large, ToString is not excessively expensive. This is particularly important for CSS errors, where we don't make an attempt to truncate these prior to constructing the script error, but we do ensure that when we report multiple errors on the same line (which is common for minified CSS), we share from the same string buffer and avoid copying. CLOSED TREE
js/xpconnect/src/nsScriptError.cpp
--- a/js/xpconnect/src/nsScriptError.cpp
+++ b/js/xpconnect/src/nsScriptError.cpp
@@ -198,19 +198,21 @@ nsScriptError::ToString(nsACString& /*UT
     char* temp;
     char* tempMessage = nullptr;
     char* tempSourceName = nullptr;
     char* tempSourceLine = nullptr;
 
     if (!mMessage.IsEmpty())
         tempMessage = ToNewUTF8String(mMessage);
     if (!mSourceName.IsEmpty())
-        tempSourceName = ToNewUTF8String(mSourceName);
+        // Use at most 512 characters from mSourceName.
+        tempSourceName = ToNewUTF8String(StringHead(mSourceName, 512));
     if (!mSourceLine.IsEmpty())
-        tempSourceLine = ToNewUTF8String(mSourceLine);
+        // Use at most 512 characters from mSourceLine.
+        tempSourceLine = ToNewUTF8String(StringHead(mSourceLine, 512));
 
     if (nullptr != tempSourceName && nullptr != tempSourceLine)
         temp = JS_smprintf(format0,
                            severity,
                            tempMessage,
                            tempSourceName,
                            mLineNumber,
                            mColumnNumber,