[INFER] Always add type for 'arguments' variables, even with local redefinitions, bug 621126.

This commit is contained in:
Brian Hackett 2010-12-23 23:09:24 -05:00
parent 01a2274ce4
commit 45c4e52a1d
2 changed files with 50 additions and 12 deletions

View File

@ -0,0 +1,35 @@
/* Resolve 'arguments' and the name of the function itself in the presence of such local variables. */
function f() {
return typeof arguments;
function arguments() {
return 7;
}
}
assertEq(f(), "object");
function g() {
var arguments = 0;
return typeof arguments;
}
assertEq(g(), "number");
function h() {
return typeof h;
function h() {
return 7;
}
}
assertEq(h(), "function");
function i() {
return typeof i;
var i;
}
assertEq(i(), "undefined");
function j() {
return typeof j;
}
assertEq(j(), "function");

View File

@ -1872,9 +1872,17 @@ Script::addVariable(JSContext *cx, jsid id, types::Variable *&var, bool localNam
JS_ASSERT(!var);
var = ArenaNew<types::Variable>(pool, &pool, id);
/* Variables which are definitely arguments or locals do not pull in builtin types. */
if (!localName) {
/* Augment with types for the 'arguments' variable. */
/*
* Augment with types for the function itself, unless this is an argument or
* local variable of the function.
*/
if (!localName && fun && id == ATOM_TO_JSID(fun->atom))
var->types.addType(cx, (jstype) function());
/*
* Augment with types for the 'arguments' variable, even if there is a local
* variable named 'arguments'
*/
if (fun && id == id_arguments(cx)) {
if (script->compileAndGo)
var->types.addType(cx, (jstype) getTypeNewObject(cx, JSProto_Object));
@ -1882,11 +1890,6 @@ Script::addVariable(JSContext *cx, jsid id, types::Variable *&var, bool localNam
var->types.addType(cx, TYPE_UNKNOWN);
}
/* Augment with types for the function itself. */
if (fun && id == ATOM_TO_JSID(fun->atom))
var->types.addType(cx, (jstype) function());
}
InferSpew(ISpewOps, "addVariable: #%lu %s T%u",
this->id, TypeIdString(id), var->types.id());
}