From 4c7e90689faa3f5ac1b5e0d32c7b2bdbffcc7115 Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 12 Sep 2006 21:56:32 +0000 Subject: [PATCH] Fix PNX_NEEDBRACES setting logic to detect only function statement directly contained in a block (352281, r=mrbkap). --- js/src/jsemit.h | 2 +- js/src/jsparse.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/src/jsemit.h b/js/src/jsemit.h index 518224b3a692..2310ea7f9e3e 100644 --- a/js/src/jsemit.h +++ b/js/src/jsemit.h @@ -159,7 +159,7 @@ struct JSTreeContext { /* tree context for semantic checks */ #define TCF_FUN_IS_GENERATOR 0x100 /* parsed yield statement in function */ #define TCF_FUN_FLAGS 0x1E0 /* flags to propagate from FunctionBody */ #define TCF_HAS_DEFXMLNS 0x200 /* default xml namespace = ...; parsed */ -#define TCF_HAS_CLOSURE 0x400 /* function statement was parsed */ +#define TCF_HAS_FUNCTION_STMT 0x400 /* block contains a function statement */ #define TREE_CONTEXT_INIT(tc) \ ((tc)->flags = (tc)->numGlobalVars = 0, \ diff --git a/js/src/jsparse.c b/js/src/jsparse.c index be65ba5ab67c..de9d15ebd3af 100644 --- a/js/src/jsparse.c +++ b/js/src/jsparse.c @@ -1388,7 +1388,6 @@ FunctionDef(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc, * sub-statement. */ op = JSOP_CLOSURE; - tc->flags |= TCF_HAS_CLOSURE; } else { op = JSOP_NOP; } @@ -1445,6 +1444,10 @@ Statements(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc) } ts->flags |= TSF_OPERAND; + /* Detect a function statement for the TOK_LC case in Statement. */ + if (pn2->pn_type == TOK_FUNCTION && !AT_TOP_LEVEL(tc)) + tc->flags |= TCF_HAS_FUNCTION_STMT; + /* If compiling top-level statements, emit as we go to save space. */ if (!tc->topStmt && (tc->flags & TCF_COMPILING)) { if (cx->fp->fun && @@ -3388,7 +3391,7 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc) uintN oldflags; oldflags = tc->flags; - tc->flags = oldflags & ~TCF_HAS_CLOSURE; + tc->flags = oldflags & ~TCF_HAS_FUNCTION_STMT; js_PushStatement(tc, &stmtInfo, STMT_BLOCK, -1); pn = Statements(cx, ts, tc); if (!pn) @@ -3401,7 +3404,7 @@ Statement(JSContext *cx, JSTokenStream *ts, JSTreeContext *tc) * If we contain a function statement and our container is top-level * or another block, flag pn to preserve braces when decompiling. */ - if ((tc->flags & TCF_HAS_CLOSURE) && + if ((tc->flags & TCF_HAS_FUNCTION_STMT) && (!tc->topStmt || tc->topStmt->type == STMT_BLOCK)) { pn->pn_extra |= PNX_NEEDBRACES; }