Skip to content

Commit 85bad33

Browse files
authored
Fix scanning bracketed expressions (#4964)
Scan 'async' literal with different depth of brackets This patch fixes #4924. This patch fixes #4748. JerryScript-DCO-1.0-Signed-off-by: Martin Negyokru [email protected]
1 parent 5467ac4 commit 85bad33

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

jerry-core/parser/js/js-scanner-ops.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,16 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */
480480
async_source_p = source_p;
481481
}
482482
}
483-
else if (depth == total_depth - 1)
483+
484+
if (depth == total_depth - 1 && lexer_check_arrow (context_p))
484485
{
485-
if (lexer_check_arrow (context_p))
486-
{
487-
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
488-
break;
489-
}
486+
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
487+
break;
488+
}
490489

491-
if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC)
492-
{
493-
scanner_add_async_literal (context_p, scanner_context_p);
494-
}
490+
if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC)
491+
{
492+
scanner_add_async_literal (context_p, scanner_context_p);
495493
}
496494

497495
arrow_source_p = NULL;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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(`async((a))`);
17+
assert(false);
18+
}
19+
catch (e) {
20+
assert(e instanceof ReferenceError);
21+
}
22+
23+
try {
24+
eval(`async(async((async((a)))))`);
25+
assert(false);
26+
}
27+
catch (e) {
28+
assert(e instanceof ReferenceError);
29+
}
30+
31+
try {
32+
eval(`async((a)`);
33+
assert(false);
34+
}
35+
catch (e) {
36+
assert(e instanceof SyntaxError);
37+
}
38+
39+
try {
40+
eval(`async((a)))`);
41+
assert(false);
42+
}
43+
catch (e) {
44+
assert(e instanceof SyntaxError);
45+
}

0 commit comments

Comments
 (0)