Skip to content

Commit dd6d148

Browse files
authored
Fix incorrect assertion in parser_parse_for_statement_start (#3795)
This patch fixes #3751. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 15629e8 commit dd6d148

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,16 +1372,14 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
13721372
: CBC_EXT_FOR_OF_GET_NEXT);
13731373
#if ENABLED (JERRY_ES2015)
13741374
#ifndef JERRY_NDEBUG
1375-
if (literal_index >= PARSER_REGISTER_START && has_context)
1375+
if (literal_index < PARSER_REGISTER_START
1376+
&& has_context
1377+
&& !scanner_literal_is_created (context_p, literal_index))
13761378
{
13771379
context_p->global_status_flags |= ECMA_PARSE_INTERNAL_FOR_IN_OFF_CONTEXT_ERROR;
13781380
}
13791381
#endif /* !JERRY_NDEBUG */
13801382

1381-
JERRY_ASSERT (literal_index >= PARSER_REGISTER_START
1382-
|| !has_context
1383-
|| scanner_literal_is_created (context_p, literal_index));
1384-
13851383
uint16_t opcode = (has_context ? CBC_ASSIGN_LET_CONST : CBC_ASSIGN_SET_IDENT);
13861384
parser_emit_cbc_literal (context_p, opcode, literal_index);
13871385
#else /* !ENABLED (JERRY_ES2015) */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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(`for (let i in {
17+
id_0: 1
18+
})
19+
20+
(function() {
21+
i
22+
`);
23+
assert (false);
24+
} catch (e) {
25+
assert (e instanceof SyntaxError);
26+
}

0 commit comments

Comments
 (0)