Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 15 additions & 9 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25365,6 +25365,9 @@ static __exception int js_parse_object_literal(JSParseState *s)
/* forbid the exponentiation operator in js_parse_unary() */
#define PF_POW_FORBIDDEN (1 << 3)
#define PF_AWAIT_USING (1 << 4)
/* an object/array literal may start a destructuring assignment: only set at
the leftmost position of an AssignmentExpression */
#define PF_PATTERN (1 << 5)

static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags);

Expand Down Expand Up @@ -27247,7 +27250,8 @@ static __exception int js_parse_postfix_expr(JSParseState *s, int parse_flags)
case '[':
{
int skip_bits;
if (js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
if ((parse_flags & PF_PATTERN) &&
js_parse_skip_parens_token(s, &skip_bits, false) == '=') {
if (js_parse_destructuring_element(s, 0, false, false, skip_bits & SKIP_HAS_ELLIPSIS, true, false) < 0)
return -1;
} else {
Expand Down Expand Up @@ -27912,7 +27916,8 @@ static __exception int js_parse_unary(JSParseState *s, int parse_flags)
parse_flags = 0;
break;
default:
if (js_parse_postfix_expr(s, PF_POSTFIX_CALL))
if (js_parse_postfix_expr(s, PF_POSTFIX_CALL |
(parse_flags & PF_PATTERN)))
return -1;
if (!s->got_lf &&
(s->token.val == TOK_DEC || s->token.val == TOK_INC)) {
Expand Down Expand Up @@ -27955,7 +27960,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
int op, opcode;

if (level == 0) {
return js_parse_unary(s, PF_POW_ALLOWED);
return js_parse_unary(s, PF_POW_ALLOWED | (parse_flags & PF_PATTERN));
} else if (s->token.val == TOK_PRIVATE_NAME &&
(parse_flags & PF_IN_ACCEPTED) && level == 4 &&
peek_token(s, false) == TOK_IN) {
Expand All @@ -27967,7 +27972,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
goto fail_private_in;
if (next_token(s))
goto fail_private_in;
if (js_parse_expr_binary(s, level - 1, parse_flags)) {
if (js_parse_expr_binary(s, level - 1, parse_flags & ~PF_PATTERN)) {
fail_private_in:
JS_FreeAtom(s->ctx, atom);
return -1;
Expand Down Expand Up @@ -28105,7 +28110,7 @@ static __exception int js_parse_expr_binary(JSParseState *s, int level,
if (next_token(s))
return -1;
emit_source_loc(s);
if (js_parse_expr_binary(s, level - 1, parse_flags))
if (js_parse_expr_binary(s, level - 1, parse_flags & ~PF_PATTERN))
return -1;
emit_op(s, opcode);
}
Expand Down Expand Up @@ -28136,10 +28141,11 @@ static __exception int js_parse_logical_and_or(JSParseState *s, int op,
emit_op(s, OP_drop);

if (op == TOK_LAND) {
if (js_parse_expr_binary(s, 8, parse_flags))
if (js_parse_expr_binary(s, 8, parse_flags & ~PF_PATTERN))
return -1;
} else {
if (js_parse_logical_and_or(s, TOK_LAND, parse_flags))
if (js_parse_logical_and_or(s, TOK_LAND,
parse_flags & ~PF_PATTERN))
return -1;
}
if (s->token.val != op) {
Expand Down Expand Up @@ -28171,7 +28177,7 @@ static __exception int js_parse_coalesce_expr(JSParseState *s, int parse_flags)
emit_goto(s, OP_if_false, label1);
emit_op(s, OP_drop);

if (js_parse_expr_binary(s, 8, parse_flags))
if (js_parse_expr_binary(s, 8, parse_flags & ~PF_PATTERN))
return -1;
if (s->token.val != TOK_DOUBLE_QUESTION_MARK)
break;
Expand Down Expand Up @@ -28401,7 +28407,7 @@ static __exception int js_parse_assign_expr2(JSParseState *s, int parse_flags)
/* name0 is used to check for OP_set_name pattern, not duplicated */
name0 = s->token.u.ident.atom;
}
if (js_parse_cond_expr(s, parse_flags))
if (js_parse_cond_expr(s, parse_flags | PF_PATTERN))
return -1;

op = s->token.val;
Expand Down
2 changes: 0 additions & 2 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ test262/test/language/expressions/assignment/target-member-computed-reference.js
test262/test/language/expressions/assignment/target-member-computed-reference.js:22: strict mode: Test262Error: Expected a DummyError but got a Test262Error
test262/test/language/expressions/assignment/target-super-computed-reference.js:20: Test262Error: Expected a DummyError but got a Test262Error
test262/test/language/expressions/assignment/target-super-computed-reference.js:20: strict mode: Test262Error: Expected a DummyError but got a Test262Error
test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js:31: Test262Error: Expected SameValue(«"bad"», «"ok"») to be true
test262/test/language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js:31: strict mode: Test262Error: Expected SameValue(«"bad"», «"ok"») to be true
test262/test/language/module-code/ambiguous-export-bindings/import-and-export-propagates-binding.js:75: SyntaxError: export 'foo' in module 'test262/test/language/module-code/ambiguous-export-bindings/imp' is ambiguous
Expand Down
Loading
Loading