ref: d9588c2c985dfe8bd917ae193913efefb3a4a93a
parent: a476ffcc12421c576ed0658f0050a511adfc208f
author: Tor Andersson <[email protected]>
date: Sat Jan 11 08:03:58 EST 2014
Add UNDEF expression to handle array elisions properly.
--- a/jsdump.c
+++ b/jsdump.c
@@ -3,6 +3,22 @@
#include <assert.h>
+static const char *stype[] = {
+ "list", "ident", "number", "string", "regexp", "undef", "null", "true",
+ "false", "this", "array", "object", "prop_val", "prop_get", "prop_set",
+ "index", "member", "call", "new", "funexp", "delete", "void", "typeof",
+ "preinc", "predec", "postinc", "postdec", "pos", "neg", "bitnot",
+ "lognot", "logor", "logand", "bitor", "bitxor", "bitand", "eq", "ne",
+ "eq3", "ne3", "lt", "gt", "le", "ge", "instanceof", "in", "shl", "shr",
+ "ushr", "add", "sub", "mul", "div", "mod", "cond", "ass", "ass_mul",
+ "ass_div", "ass_mod", "ass_add", "ass_sub", "ass_shl", "ass_shr",
+ "ass_ushr", "ass_bitand", "ass_bitxor", "ass_bitor", "comma",
+ "var-init", "block", "fundec", "nop", "var", "if", "do-while", "while",
+ "for", "for-var", "for-in", "for-in-var", "continue", "break",
+ "return", "with", "switch", "throw", "try", "label", "case", "default",
+ "debugger",
+};
+
static void pstmlist(int d, js_Ast *list);
static void pexpi(int d, int i, js_Ast *exp);
static void pstm(int d, js_Ast *stm);
@@ -141,6 +157,7 @@
case AST_STRING: pstr(exp->string); break;
case AST_REGEXP: pregexp(exp->string, exp->number); break;
+ case EXP_UNDEF: break;
case EXP_NULL: ps("null"); break;
case EXP_TRUE: ps("true"); break;
case EXP_FALSE: ps("false"); break;
@@ -485,27 +502,6 @@
pc('\n');
}
}
-
-static const char *stype[] = {
- "list", "ident", "number", "string", "regexp", "null",
- "true", "false", "this", "array", "object",
- "prop_val", "prop_get", "prop_set", "index",
- "member", "call", "new", "funexp", "delete",
- "void", "typeof", "preinc", "predec", "postinc",
- "postdec", "pos", "neg", "bitnot", "lognot",
- "logor", "logand", "bitor", "bitxor", "bitand",
- "eq", "ne", "eq3", "ne3", "lt", "gt", "le",
- "ge", "instanceof", "in", "shl", "shr", "ushr",
- "add", "sub", "mul", "div", "mod", "cond",
- "ass", "ass_mul", "ass_div", "ass_mod", "ass_add",
- "ass_sub", "ass_shl", "ass_shr", "ass_ushr",
- "ass_bitand", "ass_bitxor", "ass_bitor", "comma",
- "var-init", "block", "fundec", "nop", "var", "if",
- "do-while", "while", "for", "for-var", "for-in",
- "for-in-var", "continue", "break", "return",
- "with", "switch", "throw", "try", "label",
- "case", "default", "debugger",
-};
static void snode(int d, js_Ast *node)
{
--- a/jsparse.c
+++ b/jsparse.c
@@ -134,7 +134,7 @@
static js_Ast *arrayelement(js_State *J)
{
if (J->lookahead == ',')
- return EXP0(NULL); /* TODO: should be 'undefined' */
+ return EXP0(UNDEF);
return assignment(J, 0);
}
--- a/jsparse.h
+++ b/jsparse.h
@@ -21,6 +21,7 @@
AST_REGEXP,
/* literals */
+ EXP_UNDEF, /* for array elisions */
EXP_NULL,
EXP_TRUE,
EXP_FALSE,