Support dynamic import calls (#4652)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -31,7 +31,7 @@ JERRY_STATIC_ASSERT (offsetof (cbc_uint8_arguments_t, script_value) == offsetof
|
||||
*/
|
||||
JERRY_STATIC_ASSERT (CBC_END == 238,
|
||||
number_of_cbc_opcodes_changed);
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 146,
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 147,
|
||||
number_of_cbc_ext_opcodes_changed);
|
||||
|
||||
#if JERRY_PARSER || JERRY_PARSER_DUMP_BYTE_CODE
|
||||
|
||||
@@ -598,6 +598,8 @@
|
||||
VM_OC_COPY_FROM_ARG) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_REST_OBJECT, CBC_NO_FLAG, 1, \
|
||||
VM_OC_PUSH_REST_OBJECT) \
|
||||
CBC_OPCODE (CBC_EXT_MODULE_IMPORT, CBC_NO_FLAG, 0, \
|
||||
VM_OC_MODULE_IMPORT) \
|
||||
CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, \
|
||||
VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
|
||||
|
||||
@@ -1929,6 +1929,16 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
case LEXER_KEYW_IMPORT:
|
||||
{
|
||||
if (new_was_seen)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_IMPORT_AFTER_NEW);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
}
|
||||
|
||||
/* Bracketed expressions are primary expressions. At this
|
||||
@@ -2303,6 +2313,28 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
&& context_p->token.type != LEXER_COMMA);
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
case LEXER_KEYW_IMPORT:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type != LEXER_LEFT_PAREN)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED);
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
|
||||
|
||||
if (context_p->token.type != LEXER_RIGHT_PAREN)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
|
||||
}
|
||||
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_MODULE_IMPORT);
|
||||
break;
|
||||
}
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
default:
|
||||
{
|
||||
bool is_left_hand_side = (*grouping_level_p == PARSE_EXPR_LEFT_HAND_SIDE);
|
||||
|
||||
@@ -2424,6 +2424,18 @@ parser_parse_import_statement (parser_context_t *context_p) /**< parser context
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_IMPORT);
|
||||
JERRY_ASSERT (context_p->module_names_p == NULL);
|
||||
|
||||
if (lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
|
||||
{
|
||||
if (context_p->status_flags & PARSER_IS_FUNCTION)
|
||||
{
|
||||
parser_parse_expression_statement (context_p, PARSE_EXPR);
|
||||
return;
|
||||
}
|
||||
|
||||
parser_parse_block_expression (context_p, PARSE_EXPR);
|
||||
return;
|
||||
}
|
||||
|
||||
parser_module_check_request_place (context_p);
|
||||
lexer_next_token (context_p);
|
||||
|
||||
|
||||
@@ -1372,8 +1372,11 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Export not defined in module";
|
||||
}
|
||||
case PARSER_ERR_IMPORT_AFTER_NEW:
|
||||
{
|
||||
return "Module import call is not allowed after new";
|
||||
}
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (error == PARSER_ERR_NO_ERROR);
|
||||
|
||||
@@ -181,6 +181,7 @@ typedef enum
|
||||
PARSER_ERR_DUPLICATED_EXPORT_IDENTIFIER, /**< duplicated export identifier name */
|
||||
PARSER_ERR_DUPLICATED_IMPORT_BINDING, /**< duplicated import binding name */
|
||||
PARSER_ERR_EXPORT_NOT_DEFINED, /**< export is not defined in module */
|
||||
PARSER_ERR_IMPORT_AFTER_NEW, /**< module import call is not allowed after new */
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
|
||||
PARSER_ERR_NON_STRICT_ARG_DEFINITION /**< non-strict argument definition */
|
||||
|
||||
@@ -311,6 +311,20 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
#endif /* JERRY_ESNEXT */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
case LEXER_KEYW_IMPORT:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type != LEXER_LEFT_PAREN)
|
||||
{
|
||||
scanner_raise_error (context_p);
|
||||
}
|
||||
|
||||
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
#endif /* JERRY_MODULE_SYSTEM */
|
||||
case LEXER_RIGHT_PAREN:
|
||||
{
|
||||
if (stack_top == SCAN_STACK_PAREN_EXPRESSION)
|
||||
@@ -1681,13 +1695,20 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
#if JERRY_MODULE_SYSTEM
|
||||
case LEXER_KEYW_IMPORT:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type == LEXER_LEFT_PAREN)
|
||||
{
|
||||
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
|
||||
if (stack_top != SCAN_STACK_SCRIPT)
|
||||
{
|
||||
scanner_raise_error (context_p);
|
||||
}
|
||||
|
||||
scanner_context_p->mode = SCAN_MODE_STATEMENT_END;
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (context_p->token.type == LEXER_LITERAL
|
||||
&& context_p->token.lit_location.type == LEXER_STRING_LITERAL)
|
||||
|
||||
Reference in New Issue
Block a user