Bug 503524 - JSON.stringify does not condition number-typed space parameter per spec (r=sayrer).

This commit is contained in:
Brendan Eich 2009-07-10 16:02:38 -04:00
parent 4e705018ab
commit 107bba886d

View File

@ -578,11 +578,12 @@ InitializeGap(JSContext *cx, jsval space, JSStringBuffer *sb)
return WriteStringGap(cx, space, sb);
if (JSVAL_IS_NUMBER(space)) {
uint32 i;
if (!JS_ValueToECMAUint32(cx, space, &i))
return JS_FALSE;
js_RepeatChar(sb, jschar(' '), i);
jsdouble d = JSVAL_IS_INT(space)
? JSVAL_TO_INT(space)
: js_DoubleToInteger(*JSVAL_TO_DOUBLE(space));
d = JS_MIN(10, d);
if (d >= 1)
js_RepeatChar(sb, jschar(' '), uint32(d));
if (!STRING_BUFFER_OK(sb)) {
JS_ReportOutOfMemory(cx);