Skip to content

Commit

Permalink
Fix three async function issues. (#3863)
Browse files Browse the repository at this point in the history
- 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]
  • Loading branch information
zherczeg authored Jun 8, 2020
1 parent c2c623d commit ab2e821
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion jerry-core/include/jerryscript-snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C"
/**
* Jerry snapshot format version.
*/
#define JERRY_SNAPSHOT_VERSION (45u)
#define JERRY_SNAPSHOT_VERSION (46u)

/**
* Flags for jerry_generate_snapshot and jerry_generate_function_snapshot.
Expand Down
2 changes: 1 addition & 1 deletion jerry-core/parser/js/byte-code.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
*/
JERRY_STATIC_ASSERT (CBC_END == 238,
number_of_cbc_opcodes_changed);
JERRY_STATIC_ASSERT (CBC_EXT_END == 115,
JERRY_STATIC_ASSERT (CBC_EXT_END == 116,
number_of_cbc_ext_opcodes_changed);

#if ENABLED (JERRY_PARSER)
Expand Down
2 changes: 2 additions & 0 deletions jerry-core/parser/js/byte-code.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@
VM_OC_EXT_RETURN | VM_OC_GET_STACK) \
CBC_OPCODE (CBC_EXT_RETURN_PROMISE, CBC_NO_FLAG, -1, \
VM_OC_RETURN_PROMISE | VM_OC_GET_STACK) \
CBC_OPCODE (CBC_EXT_RETURN_PROMISE_UNDEFINED, CBC_NO_FLAG, 0, \
VM_OC_RETURN_PROMISE) \
CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, \
VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \
\
Expand Down
3 changes: 1 addition & 2 deletions jerry-core/parser/js/js-parser-statm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3017,8 +3017,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
#if ENABLED (JERRY_ES2015)
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
{
parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED);
parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_PROMISE);
parser_emit_cbc_ext (context_p, CBC_EXT_RETURN_PROMISE_UNDEFINED);
break;
}
#endif /* ENABLED (JERRY_ES2015) */
Expand Down
12 changes: 6 additions & 6 deletions jerry-core/parser/js/js-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,8 @@ parser_post_processing (parser_context_t *context_p) /**< context */
length++;

#if ENABLED (JERRY_ES2015)
if (ext_opcode == CBC_EXT_RETURN_PROMISE)
if (ext_opcode == CBC_EXT_RETURN_PROMISE
|| ext_opcode == CBC_EXT_RETURN_PROMISE_UNDEFINED)
{
last_opcode = CBC_RETURN;
}
Expand Down Expand Up @@ -1163,7 +1164,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
#if ENABLED (JERRY_ES2015)
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
{
length += 2;
length++;
}
#endif /* ENABLED (JERRY_ES2015) */

Expand Down Expand Up @@ -1540,10 +1541,9 @@ parser_post_processing (parser_context_t *context_p) /**< context */
#if ENABLED (JERRY_ES2015)
if (context_p->status_flags & PARSER_IS_ASYNC_FUNCTION)
{
dst_p[-1] = CBC_PUSH_UNDEFINED;
dst_p[0] = CBC_EXT_OPCODE;
dst_p[1] = CBC_EXT_RETURN_PROMISE;
dst_p += 2;
dst_p[-1] = CBC_EXT_OPCODE;
dst_p[0] = CBC_EXT_RETURN_PROMISE_UNDEFINED;
dst_p++;
}
#endif /* ENABLED (JERRY_ES2015) */
}
Expand Down
17 changes: 13 additions & 4 deletions jerry-core/parser/js/js-scanner-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ scanner_check_async_function (parser_context_t *context_p, /**< context */
scanner_context_t *scanner_context_p) /**< scanner context */
{
JERRY_ASSERT (lexer_token_is_async (context_p));
JERRY_ASSERT (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION);
JERRY_ASSERT (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION
|| scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION_AFTER_NEW);
JERRY_ASSERT (scanner_context_p->async_source_p != NULL);

lexer_lit_location_t async_literal = context_p->token.lit_location;
Expand Down Expand Up @@ -430,10 +431,18 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */
async_source_p = source_p;
}
}
else if (depth == total_depth - 1 && lexer_check_arrow (context_p))
else if (depth == total_depth - 1)
{
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
break;
if (lexer_check_arrow (context_p))
{
arrow_type = SCANNER_SCAN_BRACKET_ARROW_WITH_ONE_ARG;
break;
}

if (context_p->stack_top_uint8 == SCAN_STACK_USE_ASYNC)
{
scanner_add_async_literal (context_p, scanner_context_p);
}
}

arrow_source_p = NULL;
Expand Down
18 changes: 18 additions & 0 deletions tests/jerry/es2015/regresssion-test-issue-3856.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

let str = '';
function async() {}

async(str)
17 changes: 17 additions & 0 deletions tests/jerry/es2015/regresssion-test-issue-3857.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright JS Foundation and other contributors, http://js.foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

function async() {}

new async

0 comments on commit ab2e821

Please sign in to comment.