Skip to content

Commit 9712f77

Browse files
authored
Replace int parameters with bools in parser (#867)
Declaring int when the parameter is in fact used as a bool is needlessly confusing. Fixes: #864
1 parent eab8251 commit 9712f77

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

quickjs.c

+15-13
Original file line numberDiff line numberDiff line change
@@ -22981,7 +22981,7 @@ static int js_parse_check_duplicate_parameter(JSParseState *s, JSAtom name)
2298122981
return js_parse_error(s, "Duplicate parameter name not allowed in this context");
2298222982
}
2298322983

22984-
static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, int is_arg)
22984+
static JSAtom js_parse_destructuring_var(JSParseState *s, int tok, bool is_arg)
2298522985
{
2298622986
JSAtom name;
2298722987

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

2300623006
/* Return -1 if error, 0 if no initializer, 1 if an initializer is
2300723007
present at the top level. */
23008-
static int js_parse_destructuring_element(JSParseState *s, int tok, int is_arg,
23009-
int hasval, int has_ellipsis,
23010-
bool allow_initializer, bool export_flag)
23008+
static int js_parse_destructuring_element(JSParseState *s, int tok,
23009+
bool is_arg, bool hasval,
23010+
int has_ellipsis, // tri-state
23011+
bool allow_initializer,
23012+
bool export_flag)
2301123013
{
2301223014
int label_parse, label_assign, label_done, label_lvalue, depth_lvalue;
2301323015
int start_addr, assign_addr;
@@ -23623,7 +23625,7 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
2362323625
{
2362423626
int skip_bits;
2362523627
if (js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
23626-
if (js_parse_destructuring_element(s, 0, 0, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
23628+
if (js_parse_destructuring_element(s, 0, false, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
2362723629
return -1;
2362823630
} else {
2362923631
if (s->token.val == '{') {
@@ -25182,7 +25184,7 @@ static __exception int js_parse_var(JSParseState *s, int parse_flags, int tok,
2518225184
if ((s->token.val == '[' || s->token.val == '{')
2518325185
&& js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
2518425186
emit_op(s, OP_undefined);
25185-
if (js_parse_destructuring_element(s, tok, 0, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
25187+
if (js_parse_destructuring_element(s, tok, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, export_flag) < 0)
2518625188
return -1;
2518725189
} else {
2518825190
return js_parse_error(s, "variable name expected");
@@ -25304,7 +25306,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
2530425306

2530525307
if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
2530625308
if (s->token.val == '[' || s->token.val == '{') {
25307-
if (js_parse_destructuring_element(s, tok, 0, true, -1, false, false) < 0)
25309+
if (js_parse_destructuring_element(s, tok, false, true, -1, false, false) < 0)
2530825310
return -1;
2530925311
has_destructuring = true;
2531025312
} else {
@@ -25332,7 +25334,7 @@ static __exception int js_parse_for_in_of(JSParseState *s, int label_name,
2533225334
int skip_bits;
2533325335
if ((s->token.val == '[' || s->token.val == '{')
2533425336
&& ((tok1 = js_parse_skip_parens_token(s, &skip_bits, false)) == TOK_IN || tok1 == TOK_OF)) {
25335-
if (js_parse_destructuring_element(s, 0, 0, true, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
25337+
if (js_parse_destructuring_element(s, 0, false, true, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
2533625338
return -1;
2533725339
} else {
2533825340
int lvalue_label;
@@ -25586,7 +25588,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
2558625588
case TOK_VAR:
2558725589
if (next_token(s))
2558825590
goto fail;
25589-
if (js_parse_var(s, true, tok, false))
25591+
if (js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/false))
2559025592
goto fail;
2559125593
if (js_parse_expect_semi(s))
2559225594
goto fail;
@@ -25749,7 +25751,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
2574925751
if (tok == TOK_VAR || tok == TOK_LET || tok == TOK_CONST) {
2575025752
if (next_token(s))
2575125753
goto fail;
25752-
if (js_parse_var(s, false, tok, false))
25754+
if (js_parse_var(s, 0, tok, /*export_flag*/false))
2575325755
goto fail;
2575425756
} else {
2575525757
if (js_parse_expr2(s, false))
@@ -26011,7 +26013,7 @@ static __exception int js_parse_statement_or_decl(JSParseState *s,
2601126013
if (!(s->token.val == TOK_IDENT && !s->token.u.ident.is_reserved)) {
2601226014
if (s->token.val == '[' || s->token.val == '{') {
2601326015
/* XXX: TOK_LET is not completely correct */
26014-
if (js_parse_destructuring_element(s, TOK_LET, 0, true, -1, true, false) < 0)
26016+
if (js_parse_destructuring_element(s, TOK_LET, false, true, -1, true, false) < 0)
2601526017
goto fail;
2601626018
} else {
2601726019
js_parse_error(s, "identifier expected");
@@ -28246,7 +28248,7 @@ static __exception int js_parse_export(JSParseState *s)
2824628248
case TOK_VAR:
2824728249
case TOK_LET:
2824828250
case TOK_CONST:
28249-
return js_parse_var(s, true, tok, true);
28251+
return js_parse_var(s, PF_IN_ACCEPTED, tok, /*export_flag*/true);
2825028252
default:
2825128253
return js_parse_error(s, "invalid export syntax");
2825228254
}
@@ -32959,7 +32961,7 @@ static __exception int js_parse_function_decl2(JSParseState *s,
3295932961
emit_op(s, OP_get_arg);
3296032962
emit_u16(s, idx);
3296132963
}
32962-
has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, 1, true, -1, true, false);
32964+
has_initializer = js_parse_destructuring_element(s, fd->has_parameter_expressions ? TOK_LET : TOK_VAR, true, true, -1, true, false);
3296332965
if (has_initializer < 0)
3296432966
goto fail;
3296532967
if (has_initializer)

0 commit comments

Comments
 (0)