Bug 765976 - Simplify CompileFunctionBody's control flow. r=sfink.
This commit is contained in:
@@ -241,10 +241,8 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
|
||||
return script;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compile a JS function body, which might appear as the value of an event
|
||||
* handler attribute in an HTML <INPUT> tag.
|
||||
*/
|
||||
// Compile a JS function body, which might appear as the value of an event
|
||||
// handler attribute in an HTML <INPUT> tag, or in a Function() constructor.
|
||||
bool
|
||||
frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
|
||||
JSPrincipals *principals, JSPrincipals *originPrincipals,
|
||||
@@ -284,34 +282,32 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
|
||||
|
||||
/* FIXME: make Function format the source for a function definition. */
|
||||
ParseNode *fn = FunctionNode::create(PNK_NAME, &parser);
|
||||
if (fn) {
|
||||
fn->pn_body = NULL;
|
||||
fn->pn_cookie.makeFree();
|
||||
if (!fn)
|
||||
return false;
|
||||
|
||||
ParseNode *argsbody = ListNode::create(PNK_ARGSBODY, &parser);
|
||||
if (!argsbody)
|
||||
fn->pn_body = NULL;
|
||||
fn->pn_cookie.makeFree();
|
||||
|
||||
ParseNode *argsbody = ListNode::create(PNK_ARGSBODY, &parser);
|
||||
if (!argsbody)
|
||||
return false;
|
||||
argsbody->setOp(JSOP_NOP);
|
||||
argsbody->makeEmpty();
|
||||
fn->pn_body = argsbody;
|
||||
|
||||
unsigned nargs = fun->nargs;
|
||||
if (nargs) {
|
||||
/*
|
||||
* NB: do not use AutoLocalNameArray because it will release space
|
||||
* allocated from cx->tempLifoAlloc by DefineArg.
|
||||
*/
|
||||
BindingNames names(cx);
|
||||
if (!funsc.bindings.getLocalNameArray(cx, &names))
|
||||
return false;
|
||||
argsbody->setOp(JSOP_NOP);
|
||||
argsbody->makeEmpty();
|
||||
fn->pn_body = argsbody;
|
||||
|
||||
unsigned nargs = fun->nargs;
|
||||
if (nargs) {
|
||||
/*
|
||||
* NB: do not use AutoLocalNameArray because it will release space
|
||||
* allocated from cx->tempLifoAlloc by DefineArg.
|
||||
*/
|
||||
BindingNames names(cx);
|
||||
if (!funsc.bindings.getLocalNameArray(cx, &names)) {
|
||||
fn = NULL;
|
||||
} else {
|
||||
for (unsigned i = 0; i < nargs; i++) {
|
||||
if (!DefineArg(fn, names[i].maybeAtom, i, &parser)) {
|
||||
fn = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0; i < nargs; i++) {
|
||||
if (!DefineArg(fn, names[i].maybeAtom, i, &parser))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,28 +316,30 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
|
||||
* functions, and generate code for this function, including a stop opcode
|
||||
* at the end.
|
||||
*/
|
||||
ParseNode *pn = fn ? parser.functionBody(Parser::StatementListBody) : NULL;
|
||||
if (pn) {
|
||||
if (!parser.tokenStream.matchToken(TOK_EOF)) {
|
||||
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
|
||||
pn = NULL;
|
||||
} else if (!FoldConstants(cx, pn, &parser)) {
|
||||
/* FoldConstants reported the error already. */
|
||||
pn = NULL;
|
||||
} else if (!AnalyzeFunctions(&parser)) {
|
||||
pn = NULL;
|
||||
} else {
|
||||
if (fn->pn_body) {
|
||||
JS_ASSERT(fn->pn_body->isKind(PNK_ARGSBODY));
|
||||
fn->pn_body->append(pn);
|
||||
fn->pn_body->pn_pos = pn->pn_pos;
|
||||
pn = fn->pn_body;
|
||||
}
|
||||
ParseNode *pn = parser.functionBody(Parser::StatementListBody);
|
||||
if (!pn)
|
||||
return false;
|
||||
|
||||
if (!EmitFunctionScript(cx, &funbce, pn))
|
||||
pn = NULL;
|
||||
}
|
||||
if (!parser.tokenStream.matchToken(TOK_EOF)) {
|
||||
parser.reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
return pn != NULL;
|
||||
if (!FoldConstants(cx, pn, &parser))
|
||||
return false;
|
||||
|
||||
if (!AnalyzeFunctions(&parser))
|
||||
return false;
|
||||
|
||||
if (fn->pn_body) {
|
||||
JS_ASSERT(fn->pn_body->isKind(PNK_ARGSBODY));
|
||||
fn->pn_body->append(pn);
|
||||
fn->pn_body->pn_pos = pn->pn_pos;
|
||||
pn = fn->pn_body;
|
||||
}
|
||||
|
||||
if (!EmitFunctionScript(cx, &funbce, pn))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user