Skip to content

Commit ab2e821

Browse files
authored
Fix three async function issues. (#3863)
- Invalid assert - Add missing async prefix check when an identifier is enclosed in brackets - Adding a new byte-code Fixes #3855 Fixes #3856 Fixes #3857 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent c2c623d commit ab2e821

File tree

8 files changed

+59
-14
lines changed

8 files changed

+59
-14
lines changed

jerry-core/include/jerryscript-snapshot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C"
3030
/**
3131
* Jerry snapshot format version.
3232
*/
33-
#define JERRY_SNAPSHOT_VERSION (45u)
33+
#define JERRY_SNAPSHOT_VERSION (46u)
3434

3535
/**
3636
* Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.

jerry-core/parser/js/byte-code.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
2727
*/
2828
JERRY_STATIC_ASSERT (CBC_END == 238,
2929
number_of_cbc_opcodes_changed);
30-
JERRY_STATIC_ASSERT (CBC_EXT_END == 115,
30+
JERRY_STATIC_ASSERT (CBC_EXT_END == 116,
3131
number_of_cbc_ext_opcodes_changed);
3232

3333
#if ENABLED (JERRY_PARSER)

jerry-core/parser/js/byte-code.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,8 @@
726726
VM_OC_EXT_RETURN | VM_OC_GET_STACK) \
727727
CBC_OPCODE (CBC_EXT_RETURN_PROMISE, CBC_NO_FLAG, -1, \
728728
VM_OC_RETURN_PROMISE | VM_OC_GET_STACK) \
729+
CBC_OPCODE (CBC_EXT_RETURN_PROMISE_UNDEFINED, CBC_NO_FLAG, 0, \
730+
VM_OC_RETURN_PROMISE) \
729731
CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, \
730732
VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \
731733
\

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3017,8 +3017,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
30173017
#if ENABLED (JERRY_ES2015)
30183018
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
30193019
{
3020-
parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED);
3021-
parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_PROMISE);
3020+
parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_PROMISE_UNDEFINED);
30223021
break;
30233022
}
30243023
#endif /* ENABLED (JERRY_ES2015) */

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */
10181018
length++;
10191019

10201020
#if ENABLED (JERRY_ES2015)
1021-
if (ext_opcode == CBC_EXT_RETURN_PROMISE)
1021+
if (ext_opcode == CBC_EXT_RETURN_PROMISE
1022+
|| ext_opcode == CBC_EXT_RETURN_PROMISE_UNDEFINED)
10221023
{
10231024
last_opcode = CBC_RETURN;
10241025
}
@@ -1163,7 +1164,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
11631164
#if ENABLED (JERRY_ES2015)
11641165
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
11651166
{
1166-
length += 2;
1167+
length++;
11671168
}
11681169
#endif /* ENABLED (JERRY_ES2015) */
11691170

@@ -1540,10 +1541,9 @@ parser_post_processing (parser_context_t *context_p) /**< context */
15401541
#if ENABLED (JERRY_ES2015)
15411542
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
15421543
{
1543-
dst_p[-1] = CBC_PUSH_UNDEFINED;
1544-
dst_p[0] = CBC_EXT_OPCODE;
1545-
dst_p[1] = CBC_EXT_RETURN_PROMISE;
1546-
dst_p += 2;
1544+
dst_p[-1] = CBC_EXT_OPCODE;
1545+
dst_p[0] = CBC_EXT_RETURN_PROMISE_UNDEFINED;
1546+
dst_p++;
15471547
}
15481548
#endif /* ENABLED (JERRY_ES2015) */
15491549
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ scanner_check_async_function (parser_context_t *context_p, /**< context */
260260
scanner_context_t *scanner_context_p) /**< scanner context */
261261
{
262262
JERRY_ASSERT (lexer_token_is_async (context_p));
263-
JERRY_ASSERT (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION);
263+
JERRY_ASSERT (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION
264+
|| scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW);
264265
JERRY_ASSERT (scanner_context_p->async_source_p != NULL);
265266

266267
lexer_lit_location_t async_literal = context_p->token.lit_location;
@@ -430,10 +431,18 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */
430431
async_source_p = source_p;
431432
}
432433
}
433-
else if (depth == total_depth - 1 && lexer_check_arrow (context_p))
434+
else if (depth == total_depth - 1)
434435
{
435-
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
436-
break;
436+
if (lexer_check_arrow (context_p))
437+
{
438+
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
439+
break;
440+
}
441+
442+
if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC)
443+
{
444+
scanner_add_async_literal (context_p, scanner_context_p);
445+
}
437446
}
438447

439448
arrow_source_p = NULL;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
let str = '';
16+
function async() {}
17+
18+
async(str)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
function async() {}
16+
17+
new async

0 commit comments

Comments
 (0)