Skip to content

Commit 47d025c

Browse files
author
Robert Fancsik
authored
Check rest initializer existence after pattern finalization (#4950)
Since the scanner info is not present for invalid destructuring patterns we can only ensure the existence of the rest element after the pattern is finalized. This patch fixes #4928. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 799583e commit 47d025c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4072,6 +4072,10 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
40724072
return;
40734073
}
40744074

4075+
#ifndef JERRY_NDEBUG
4076+
bool rest_found = false;
4077+
#endif /* !defined(JERRY_NDEBUG) */
4078+
40754079
cbc_ext_opcode_t context_opcode = CBC_EXT_OBJ_INIT_CONTEXT_CREATE;
40764080

40774081
if (flags & PARSER_PATTERN_HAS_REST_ELEMENT)
@@ -4115,8 +4119,9 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
41154119
parser_raise_error (context_p, PARSER_ERR_RIGHT_BRACE_EXPECTED);
41164120
}
41174121

4118-
/* Checked at the end because there might be syntax errors before. */
4119-
JERRY_ASSERT (flags & PARSER_PATTERN_HAS_REST_ELEMENT);
4122+
#ifndef JERRY_NDEBUG
4123+
rest_found = true;
4124+
#endif /* !defined(JERRY_NDEBUG) */
41204125
break;
41214126
}
41224127

@@ -4203,6 +4208,11 @@ parser_parse_object_initializer (parser_context_t *context_p, /**< context */
42034208
parser_emit_cbc_ext (context_p, CBC_EXT_OBJ_INIT_CONTEXT_END);
42044209

42054210
parser_pattern_finalize (context_p, flags, &end_pos);
4211+
4212+
#ifndef JERRY_NDEBUG
4213+
/* Checked at the end because there might be syntax errors before. */
4214+
JERRY_ASSERT (!!(flags & PARSER_PATTERN_HAS_REST_ELEMENT) == rest_found);
4215+
#endif /* !defined(JERRY_NDEBUG) */
42064216
} /* parser_parse_object_initializer */
42074217

42084218
/**
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
try {
16+
eval('var { a, b, ...rest }"');
17+
assert(false);
18+
} catch(e) {
19+
assert(e instanceof SyntaxError);
20+
}

0 commit comments

Comments
 (0)