Bug 472787 - Eagerly set the return value. r=brendan
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 09 Jan 2009 18:32:04 -0800
changeset 23707 411b2f1e19de674725fe6e2d4f9b01882e1dcc98
parent 23706 d3a4e58a54f5c856754791220737f9e209d60cb2
child 23708 6475993319c4799269e365623f994f9e7b1bf5ed
push id4690
push userrsayre@mozilla.com
push dateThu, 15 Jan 2009 07:42:55 +0000
treeherdermozilla-central@ddfa483fea2a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbrendan
bugs472787
milestone1.9.2a1pre
Bug 472787 - Eagerly set the return value. r=brendan
js/src/jsstr.cpp
--- a/js/src/jsstr.cpp
+++ b/js/src/jsstr.cpp
@@ -2192,28 +2192,31 @@ static JSBool
 str_concat(JSContext *cx, uintN argc, jsval *vp)
 {
     JSString *str, *str2;
     jsval *argv;
     uintN i;
 
     NORMALIZE_THIS(cx, vp, str);
 
+    /* Set vp (aka rval) early to handle the argc == 0 case. */
+    *vp = STRING_TO_JSVAL(str);
+
     for (i = 0, argv = vp + 2; i < argc; i++) {
         str2 = js_ValueToString(cx, argv[i]);
         if (!str2)
             return JS_FALSE;
         argv[i] = STRING_TO_JSVAL(str2);
 
         str = js_ConcatStrings(cx, str, str2);
         if (!str)
             return JS_FALSE;
+        *vp = STRING_TO_JSVAL(str);
     }
 
-    *vp = STRING_TO_JSVAL(str);
     return JS_TRUE;
 }
 
 #ifdef JS_TRACER
 static JSString* FASTCALL
 String_p_concat_1int(JSContext* cx, JSString* str, int32 i)
 {
     // FIXME: should be able to use stack buffer and avoid istr...