Skip to content

Replace int parameters with bools in parser #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -22981,7 +22981,7 @@ static int js_parse_check_duplicate_parameter(JSParseState *s, JSAtom name)
return js_parse_error(s, "Duplicate parameter name not allowed in this context");
}

static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int is_arg)
static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, bool is_arg)
{
JSAtom name;

Expand All @@ -23005,9 +23005,11 @@ static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int is_arg)

/* Return -1 if error, 0 if no initializer, 1 if an initializer is
present at the top level. */
static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
int hasval, int has_ellipsis,
bool allow_initializer, bool export_flag)
static int js_parse_destructuring_element(JSParseState *s, int tok,
bool is_arg, bool hasval,
int has_ellipsis, // tri-state
bool allow_initializer,
bool export_flag)
{
int label_parse, label_assign, label_done, label_lvalue, depth_lvalue;
int start_addr, assign_addr;
Expand Down Expand Up @@ -23623,7 +23625,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
{
int skip_bits;
if (js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
if (js_parse_destructuring_element(s, 0, 0, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
if (js_parse_destructuring_element(s, 0, false, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
return -1;
} else {
if (s->token.val == '{') {
Expand Down Expand Up @@ -25182,7 +25184,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
if ((s->token.val == '[' || s->token.val == '{')
&& js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
emit_op(s, OP_undefined);
if (js_parse_destructuring_element(s, tok, 0, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
if (js_parse_destructuring_element(s, tok, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
return -1;
} else {
return js_parse_error(s, "variable name expected");
Expand Down Expand Up @@ -25304,7 +25306,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,

if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
if (s->token.val == '[' || s->token.val == '{') {
if (js_parse_destructuring_element(s, tok, 0, true, -1, false, false) < 0)
if (js_parse_destructuring_element(s, tok, false, true, -1, false, false) < 0)
return -1;
has_destructuring = true;
} else {
Expand Down Expand Up @@ -25332,7 +25334,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
int skip_bits;
if ((s->token.val == '[' || s->token.val == '{')
&& ((tok1 = js_parse_skip_parens_token(s, &skip_bits, false)) == TOK_IN || tok1 == TOK_OF)) {
if (js_parse_destructuring_element(s, 0, 0, true, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
if (js_parse_destructuring_element(s, 0, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
return -1;
} else {
int lvalue_label;
Expand Down Expand Up @@ -25586,7 +25588,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
case TOK_VAR:
if (next_token(s))
goto fail;
if (js_parse_var(s, true, tok, false))
if (js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/false))
goto fail;
if (js_parse_expect_semi(s))
goto fail;
Expand Down Expand Up @@ -25749,7 +25751,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
if (tok == TOK_VAR || tok == TOK_LET || tok == TOK_CONST) {
if (next_token(s))
goto fail;
if (js_parse_var(s, false, tok, false))
if (js_parse_var(s, 0, tok, /*export_flag*/false))
goto fail;
} else {
if (js_parse_expr2(s, false))
Expand Down Expand Up @@ -26011,7 +26013,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
if (s->token.val == '[' || s->token.val == '{') {
/* XXX: TOK_LET is not completely correct */
if (js_parse_destructuring_element(s, TOK_LET, 0, true, -1, true, false) < 0)
if (js_parse_destructuring_element(s, TOK_LET, false, true, -1, true, false) < 0)
goto fail;
} else {
js_parse_error(s, "identifier expected");
Expand Down Expand Up @@ -28246,7 +28248,7 @@ static __exception int js_parse_export(JSParseState *s)
case TOK_VAR:
case TOK_LET:
case TOK_CONST:
return js_parse_var(s, true, tok, true);
return js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/true);
default:
return js_parse_error(s, "invalid export syntax");
}
Expand Down Expand Up @@ -32959,7 +32961,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
emit_op(s, OP_get_arg);
emit_u16(s, idx);
}
has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, 1, true, -1, true, false);
has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, true, true, -1, true, false);
if (has_initializer < 0)
goto fail;
if (has_initializer)
Expand Down