Bug 987556 Part 11 Use allocated array version of ConvertToUTF16() in XPCJSRuntime. r=bz
authorBen Kelly <ben@wanderview.com>
Fri, 25 Apr 2014 10:11:57 -0400
changeset 180570 e034bbc3172ef6a7f11f859aeaf5ca9972cdc548
parent 180569 4d816e087f32085a7911c634aabfac225c5efc47
child 180571 02eb81ab06cb0abcd849c480363083fa7faa915c
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersbz
bugs987556
milestone31.0a1
Bug 987556 Part 11 Use allocated array version of ConvertToUTF16() in XPCJSRuntime. r=bz
js/xpconnect/src/XPCJSRuntime.cpp
--- a/js/xpconnect/src/XPCJSRuntime.cpp
+++ b/js/xpconnect/src/XPCJSRuntime.cpp
@@ -2981,27 +2981,27 @@ ReadSourceFromFilename(JSContext *cx, co
         uint32_t bytesRead;
         rv = scriptStream->Read(reinterpret_cast<char *>(ptr), end - ptr, &bytesRead);
         if (NS_FAILED(rv))
             return rv;
         MOZ_ASSERT(bytesRead > 0, "stream promised more bytes before EOF");
         ptr += bytesRead;
     }
 
-    nsString decoded;
     rv = nsScriptLoader::ConvertToUTF16(scriptChannel, buf, rawLen, EmptyString(),
-                                        nullptr, decoded);
+                                        nullptr, *src, *len);
     NS_ENSURE_SUCCESS(rv, rv);
 
-    // Copy to JS engine.
-    *len = decoded.Length();
-    *src = static_cast<jschar *>(JS_malloc(cx, decoded.Length()*sizeof(jschar)));
     if (!*src)
         return NS_ERROR_FAILURE;
-    memcpy(*src, decoded.get(), decoded.Length()*sizeof(jschar));
+
+    // Historically this method used JS_malloc() which updates the GC memory
+    // accounting.  Since ConvertToUTF16() now uses js_malloc() instead we
+    // update the accounting manually after the fact.
+    JS_updateMallocCounter(cx, *len);
 
     return NS_OK;
 }
 
 // The JS engine calls this object's 'load' member function when it needs
 // the source for a chrome JS function. See the comment in the XPCJSRuntime
 // constructor.
 class XPCJSSourceHook: public js::SourceHook {