Bug 877965 - In asm.js mode, use the last return statement instead of the last statement to find the return type of a function. r=luke

This commit is contained in:
Benjamin Bouvier 2013-06-07 12:06:53 -07:00
parent 8fa8aefe46
commit 961dc05264
2 changed files with 11 additions and 4 deletions

View File

@ -277,10 +277,16 @@ FunctionStatementList(ParseNode *fn)
}
static inline ParseNode *
FunctionLastStatementOrNull(ParseNode *fn)
FunctionLastReturnStatementOrNull(ParseNode *fn)
{
ParseNode *list = FunctionStatementList(fn);
return list->pn_count == 0 ? NULL : list->last();
ParseNode *listIter = ListHead(FunctionStatementList(fn));
ParseNode *lastReturn = NULL;
while (listIter) {
if (listIter->isKind(PNK_RETURN))
lastReturn = listIter;
listIter = listIter->pn_next;
}
return lastReturn;
}
static inline bool
@ -2861,7 +2867,7 @@ CheckArguments(ModuleCompiler &m, ParseNode *fn, MIRTypeVector *argTypes, ParseN
static bool
CheckReturnType(ModuleCompiler &m, ParseNode *fn, RetType *returnType)
{
ParseNode *stmt = FunctionLastStatementOrNull(fn);
ParseNode *stmt = FunctionLastReturnStatementOrNull(fn);
if (!stmt || !stmt->isKind(PNK_RETURN) || !UnaryKid(stmt)) {
*returnType = RetType::Void;
return true;

View File

@ -18,6 +18,7 @@ assertAsmTypeFail(USE_ASM + 'function f(x){} return f');
assertAsmTypeFail(USE_ASM + 'function f(){return; return 1} return f');
assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0} return f'))(42), undefined);
assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0; return x|0} return f'))(42), 42);
assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0; return x|0;;;} return f'))(42), 42);
assertEq(asmLink(asmCompile(USE_ASM + 'function f(x,y){x=x|0;y=y|0; return (x+y)|0} return f'))(44, -2), 42);
assertAsmTypeFail('a', USE_ASM + 'function a(){} return a');
assertAsmTypeFail('a','b','c', USE_ASM + 'var c');