Bug 554152: Fix handling of space parameter match final spec. r=waldo
authorRobert Sayre <sayrer@gmail.com>
Thu, 01 Apr 2010 16:22:49 -0400
changeset 40436 b8acc9cb4afb8493067f0ad5723e5c21cca6ecca
parent 40435 12422087607e30703e25635636afa5cf5b3e820b
child 40437 2f9e98369fc364afd02d58f84fe0398c148f3995
push id12610
push userrsayre@mozilla.com
push dateMon, 05 Apr 2010 17:26:41 +0000
treeherdermozilla-central@1942c0b4e101 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs554152
milestone1.9.3a4pre
Bug 554152: Fix handling of space parameter match final spec. r=waldo
js/src/json.cpp
--- a/js/src/json.cpp
+++ b/js/src/json.cpp
@@ -509,29 +509,36 @@ Str(JSContext *cx, jsid id, JSObject *ho
 
     *vp = JSVAL_VOID;
     return JS_TRUE;
 }
 
 static JSBool
 InitializeGap(JSContext *cx, jsval space, JSCharBuffer &cb)
 {
+    AutoValueRooter gap(cx, space);
+
     if (!JSVAL_IS_PRIMITIVE(space)) {
-        JSClass *clasp = OBJ_GET_CLASS(cx, JSVAL_TO_OBJECT(space));
-        if (clasp == &js_StringClass || clasp == &js_NumberClass)
-            return js_ValueToCharBuffer(cx, space, cb);
+        JSObject *obj = JSVAL_TO_OBJECT(space);
+        JSClass *clasp = OBJ_GET_CLASS(cx, obj);
+        if (clasp == &js_NumberClass || clasp == &js_StringClass)
+            *gap.addr() = obj->fslots[JSSLOT_PRIMITIVE_THIS];
     }
 
-    if (JSVAL_IS_STRING(space))
-        return js_ValueToCharBuffer(cx, space, cb);
+    if (JSVAL_IS_STRING(gap.value())) {
+        if (!js_ValueToCharBuffer(cx, gap.value(), cb))
+            return JS_FALSE;
+        if (cb.length() > 10)
+            cb.resize(10);
+    }
 
-    if (JSVAL_IS_NUMBER(space)) {
-        jsdouble d = JSVAL_IS_INT(space)
-                     ? JSVAL_TO_INT(space)
-                     : js_DoubleToInteger(*JSVAL_TO_DOUBLE(space));
+    if (JSVAL_IS_NUMBER(gap.value())) {
+        jsdouble d = JSVAL_IS_INT(gap.value())
+                     ? JSVAL_TO_INT(gap.value())
+                     : js_DoubleToInteger(*JSVAL_TO_DOUBLE(gap.value()));
         d = JS_MIN(10, d);
         if (d >= 1 && !cb.appendN(' ', uint32(d)))
             return JS_FALSE;
     }
 
     return JS_TRUE;
 }