Bug 1272813 - part 1 - fallibly assign strings in {NonVoid,}StringToJsval; r=peterv
authorNathan Froyd <froydnj@gmail.com>
Wed, 01 Jun 2016 16:26:59 -0400
changeset 338941 6a4d4bfb868bee78c16508da1381bb8a08ba218d
parent 338940 dc6dbe4c9cee01b8de585c6dc4c8e47892f07965
child 338942 fa493b763fb7f7131fa723a2b49b6f744302a973
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1272813
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1272813 - part 1 - fallibly assign strings in {NonVoid,}StringToJsval; r=peterv Avoiding large infallible allocations is always a good thing.
js/xpconnect/src/xpcpublic.h
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -16,16 +16,17 @@
 #include "nsIURI.h"
 #include "nsIPrincipal.h"
 #include "nsIGlobalObject.h"
 #include "nsPIDOMWindow.h"
 #include "nsWrapperCache.h"
 #include "nsStringGlue.h"
 #include "nsTArray.h"
 #include "mozilla/dom/JSSlots.h"
+#include "mozilla/fallible.h"
 #include "nsMathUtils.h"
 #include "nsStringBuffer.h"
 #include "mozilla/dom/BindingDeclarations.h"
 
 class nsGlobalWindow;
 class nsIPrincipal;
 class nsScriptNameSpaceManager;
 class nsIMemoryReporterCallback;
@@ -307,24 +308,32 @@ inline bool StringToJsval(JSContext* cx,
         return true;
     }
     return NonVoidStringToJsval(cx, str, rval);
 }
 
 inline bool
 NonVoidStringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
 {
-    nsString mutableCopy(str);
+    nsString mutableCopy;
+    if (!mutableCopy.Assign(str, mozilla::fallible)) {
+        JS_ReportOutOfMemory(cx);
+        return false;
+    }
     return NonVoidStringToJsval(cx, mutableCopy, rval);
 }
 
 inline bool
 StringToJsval(JSContext* cx, const nsAString& str, JS::MutableHandleValue rval)
 {
-    nsString mutableCopy(str);
+    nsString mutableCopy;
+    if (!mutableCopy.Assign(str, mozilla::fallible)) {
+        JS_ReportOutOfMemory(cx);
+        return false;
+    }
     return StringToJsval(cx, mutableCopy, rval);
 }
 
 /**
  * As above, but for mozilla::dom::DOMString.
  */
 MOZ_ALWAYS_INLINE
 bool NonVoidStringToJsval(JSContext* cx, mozilla::dom::DOMString& str,