Fix from igor.bukanov@gmail.com for old bug in argv provisioning/scanning (311497, r=me).

This commit is contained in:
brendan%mozilla.org 2005-10-15 00:14:08 +00:00
Родитель a642e301e7
Коммит 4de10b1527
2 изменённых файлов: 26 добавлений и 21 удалений

Просмотреть файл

@ -1747,8 +1747,11 @@ restart:
GC_MARK(cx, fp->thisp, "this", NULL);
if (fp->argv) {
nslots = fp->argc;
if (fp->fun && fp->fun->nargs > nslots)
if (fp->fun) {
if (fp->fun->nargs > nslots)
nslots = fp->fun->nargs;
nslots += fp->fun->extra;
}
GC_MARK_JSVALS(cx, nslots, fp->argv, "arg");
}
if (JSVAL_IS_GCTHING(fp->rval))

Просмотреть файл

@ -855,8 +855,7 @@ js_Invoke(JSContext *cx, uintN argc, uintN flags)
JSNative native;
JSFunction *fun;
JSScript *script;
uintN minargs, nvars;
intN nslots, nalloc, surplus;
uintN nslots, nvars, nalloc, surplus;
JSInterpreterHook hook;
void *hookData;
@ -1020,7 +1019,7 @@ js_Invoke(JSContext *cx, uintN argc, uintN flags)
}
fun = NULL;
script = NULL;
minargs = nvars = 0;
nslots = nvars = 0;
/* Try a call or construct native object op. */
native = (flags & JSINVOKE_CONSTRUCT) ? ops->construct : ops->call;
@ -1037,7 +1036,8 @@ have_fun:
native = fun->u.native;
script = NULL;
}
minargs = fun->nargs + fun->extra;
nslots = (fun->nargs > argc) ? fun->nargs - argc : 0;
nslots += fun->extra;
nvars = fun->nvars;
/* Handle bound method special case. */
@ -1076,8 +1076,7 @@ have_fun:
hook = cx->runtime->callHook;
hookData = NULL;
/* Check for missing arguments expected by the function. */
nslots = (intN)((argc < minargs) ? minargs - argc : 0);
/* Check for argument slots required by the function. */
if (nslots) {
/* All arguments must be contiguous, so we may have to copy actuals. */
nalloc = nslots;
@ -1087,15 +1086,15 @@ have_fun:
nalloc += 2 + argc;
} else {
/* Take advantage of surplus slots in the caller's frame depth. */
JS_ASSERT((jsval *)mark >= sp);
surplus = (jsval *)mark - sp;
JS_ASSERT(surplus >= 0);
nalloc -= surplus;
}
/* Check whether we have enough space in the caller's frame. */
if (nalloc > 0) {
if ((intN)nalloc > 0) {
/* Need space for actuals plus missing formals minus surplus. */
newsp = js_AllocRawStack(cx, (uintN)nalloc, NULL);
newsp = js_AllocRawStack(cx, nalloc, NULL);
if (!newsp) {
ok = JS_FALSE;
goto out;
@ -1104,7 +1103,7 @@ have_fun:
/* If we couldn't allocate contiguous args, copy actuals now. */
if (newsp != mark) {
JS_ASSERT(sp + nslots > limit);
JS_ASSERT(2 + argc + nslots == (uintN)nalloc);
JS_ASSERT(2 + argc + nslots == nalloc);
*newsp++ = vp[0];
*newsp++ = vp[1];
if (argc)
@ -1118,16 +1117,18 @@ have_fun:
frame.vars += nslots;
/* Push void to initialize missing args. */
while (--nslots >= 0)
do {
PUSH(JSVAL_VOID);
} while (--nslots != 0);
}
JS_ASSERT(nslots == 0);
/* Now allocate stack space for local variables. */
nslots = (intN)frame.nvars;
if (nslots) {
surplus = (intN)((jsval *)cx->stackPool.current->avail - frame.vars);
if (surplus < nslots) {
newsp = js_AllocRawStack(cx, (uintN)nslots, NULL);
if (nvars) {
JS_ASSERT((jsval *)cx->stackPool.current->avail >= frame.vars);
surplus = (jsval *)cx->stackPool.current->avail - frame.vars;
if (surplus < nvars) {
newsp = js_AllocRawStack(cx, nvars, NULL);
if (!newsp) {
ok = JS_FALSE;
goto out;
@ -1139,8 +1140,9 @@ have_fun:
}
/* Push void to initialize local variables. */
while (--nslots >= 0)
do {
PUSH(JSVAL_VOID);
} while (--nvars != 0);
}
/* Store the current sp in frame before calling fun. */