From ecabfe425880cf022e43e9a0b101915de9c2ea2a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 25 Jan 2014 14:08:43 +0100 Subject: [PATCH] Don't look for labels past function borders. --- jscompile.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jscompile.c b/jscompile.c index 805bb9b..f2a1387 100644 --- a/jscompile.c +++ b/jscompile.c @@ -591,6 +591,11 @@ static int isloop(js_AstType T) T == STM_FOR_IN || T == STM_FOR_IN_VAR; } +static int isfun(js_AstType T) +{ + return T == AST_FUNDEC || T == EXP_FUN; +} + static int matchlabel(js_Ast *node, const char *label) { while (node && node->type == STM_LABEL) { @@ -604,6 +609,8 @@ static int matchlabel(js_Ast *node, const char *label) static js_Ast *breaktarget(JF, js_Ast *node, const char *label) { while (node) { + if (isfun(node->type)) + break; if (!label) { if (isloop(node->type) || node->type == STM_SWITCH) return node; @@ -619,6 +626,8 @@ static js_Ast *breaktarget(JF, js_Ast *node, const char *label) static js_Ast *continuetarget(JF, js_Ast *node, const char *label) { while (node) { + if (isfun(node->type)) + break; if (isloop(node->type)) { if (!label) return node; @@ -633,7 +642,7 @@ static js_Ast *continuetarget(JF, js_Ast *node, const char *label) static js_Ast *returntarget(JF, js_Ast *node) { while (node) { - if (node->type == AST_FUNDEC || node->type == EXP_FUN) + if (isfun(node->type)) return node; node = node->parent; } @@ -1049,7 +1058,7 @@ static void cvardecs(JF, js_Ast *node) { if (node->type == EXP_VAR) { emitstring(J, F, OP_VARDEC, node->a->string); - } else if (node->type != EXP_FUN && node->type != AST_FUNDEC) { + } else if (!isfun(node->type)) { if (node->a) cvardecs(J, F, node->a); if (node->b) cvardecs(J, F, node->b); if (node->c) cvardecs(J, F, node->c);