bug 716512 - make sure that gcparam in shell cannot set MAX_GC_BYTES to a value les than the current GC_BYTES. r=anygregor

This commit is contained in:
Igor Bukanov 2012-01-09 15:23:36 +01:00
parent 898a4771fc
commit 12c791efaf
2 changed files with 34 additions and 20 deletions

View File

@ -1254,7 +1254,7 @@ GCParameter(JSContext *cx, uintN argc, jsval *vp)
JSFlatString *flatStr = JS_FlattenString(cx, str);
if (!flatStr)
return JS_FALSE;
return false;
size_t paramIndex = 0;
for (;; paramIndex++) {
@ -1263,7 +1263,7 @@ GCParameter(JSContext *cx, uintN argc, jsval *vp)
"the first argument argument must be maxBytes, "
"maxMallocBytes, gcStackpoolLifespan, gcBytes or "
"gcNumber");
return JS_FALSE;
return false;
}
if (JS_FlatStringEqualsAscii(flatStr, paramMap[paramIndex].name))
break;
@ -1279,7 +1279,7 @@ GCParameter(JSContext *cx, uintN argc, jsval *vp)
param == JSGC_BYTES) {
JS_ReportError(cx, "Attempt to change read-only parameter %s",
paramMap[paramIndex].name);
return JS_FALSE;
return false;
}
uint32_t value;
@ -1287,11 +1287,23 @@ GCParameter(JSContext *cx, uintN argc, jsval *vp)
JS_ReportError(cx,
"the second argument must be convertable to uint32_t "
"with non-zero value");
return JS_FALSE;
return false;
}
if (param == JSGC_MAX_BYTES) {
uint32_t gcBytes = JS_GetGCParameter(cx->runtime, JSGC_BYTES);
if (value < gcBytes) {
JS_ReportError(cx,
"attempt to set maxBytes to the value less than the current "
"gcBytes (%u)",
gcBytes);
return false;
}
}
JS_SetGCParameter(cx->runtime, param, value);
*vp = JSVAL_VOID;
return JS_TRUE;
return true;
}
static JSBool

View File

@ -56,7 +56,9 @@ function test()
if (typeof gcparam != 'undefined')
{
gcparam("maxBytes", 22000);
gc();
gc();
gcparam("maxBytes", gcparam("gcBytes") + 4*1024);
expectExitCode(5);
}