Bug 737575 - fix arguments['integer'] (r=dvander)

--HG--
extra : rebase_source : 5cb580a47187f2a88a98efc3fa8a88ee4c8bc551
This commit is contained in:
Luke Wagner 2012-03-20 17:21:58 -07:00
parent 32a0f7bc5f
commit 7b7d34d1b2
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,6 @@
function f(s) {
return arguments[s];
}
for (var i = 0; i < 10; ++i)
assertEq(f(String(i+1), 0,1,2,3,4,5,6,7,8,9), i);

View File

@ -295,17 +295,29 @@ NormalArgumentsObject::optimizedGetElem(JSContext *cx, StackFrame *fp, const Val
{
JS_ASSERT(!fp->hasArgsObj());
/* Fast path: no need to convert to id when elem is already an int in range. */
if (elem.isInt32()) {
int32_t i = elem.toInt32();
if (i >= 0 && uint32_t(i) < fp->numActualArgs()) {
*vp = fp->canonicalActualArg(elem.toInt32());
*vp = fp->canonicalActualArg(i);
return true;
}
}
/* Slow path: create and canonicalize an id, then emulate args_resolve. */
jsid id;
if (!ValueToId(cx, elem, &id))
return false;
id = js_CheckForStringIndex(id);
if (JSID_IS_INT(id)) {
int32_t i = JSID_TO_INT(id);
if (i >= 0 && uint32_t(i) < fp->numActualArgs()) {
*vp = fp->canonicalActualArg(i);
return true;
}
}
if (id == ATOM_TO_JSID(cx->runtime->atomState.lengthAtom)) {
*vp = Int32Value(fp->numActualArgs());