Implement throwing ReferenceErrors for let/const variables. (#3264)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
d1faed7d03
commit
6a342fcdd6
@@ -488,6 +488,8 @@
|
||||
VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \
|
||||
CBC_OPCODE (CBC_MOV_IDENT, CBC_HAS_LITERAL_ARG, -1, \
|
||||
VM_OC_MOV_IDENT | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \
|
||||
CBC_OPCODE (CBC_ASSIGN_LET_CONST, CBC_HAS_LITERAL_ARG, -1, \
|
||||
VM_OC_ASSIGN_LET_CONST | VM_OC_GET_STACK) \
|
||||
\
|
||||
/* Last opcode (not a real opcode). */ \
|
||||
CBC_OPCODE (CBC_END, CBC_NO_FLAG, 0, \
|
||||
|
||||
@@ -586,6 +586,11 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
/* FIXME: Remove this hack after module classes are supported. */
|
||||
uint16_t assign_opcode = CBC_ASSIGN_LET_CONST;
|
||||
#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
|
||||
|
||||
uint16_t class_ident_index = PARSER_MAXIMUM_NUMBER_OF_LITERALS;
|
||||
|
||||
if (is_statement)
|
||||
@@ -595,19 +600,19 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL
|
||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
||||
{
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED);
|
||||
parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED);
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
class_ident_index = context_p->lit_object.index;
|
||||
|
||||
#if ENABLED (JERRY_ES2015_MODULE_SYSTEM)
|
||||
if (context_p->status_flags & PARSER_MODULE_STORE_IDENT)
|
||||
{
|
||||
assign_opcode = CBC_ASSIGN_SET_IDENT;
|
||||
|
||||
context_p->module_identifier_lit_p = context_p->lit_object.literal_p;
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_MODULE_STORE_IDENT);
|
||||
}
|
||||
@@ -658,17 +663,19 @@ parser_parse_class (parser_context_t *context_p, /**< context */
|
||||
|
||||
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, context_p->lit_object.index);
|
||||
|
||||
if (is_statement)
|
||||
{
|
||||
parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, class_ident_index);
|
||||
}
|
||||
|
||||
if (create_class_env)
|
||||
{
|
||||
parser_parse_super_class_context_end (context_p, is_statement);
|
||||
parser_parse_super_class_context_end (context_p);
|
||||
context_p->status_flags &= (uint32_t) ~(PARSER_CLASS_HAS_SUPER | PARSER_CLASS_IMPLICIT_SUPER);
|
||||
}
|
||||
|
||||
if (is_statement)
|
||||
{
|
||||
parser_emit_cbc_literal (context_p,
|
||||
class_ident_index >= PARSER_REGISTER_START ? CBC_MOV_IDENT : assign_opcode,
|
||||
class_ident_index);
|
||||
}
|
||||
|
||||
parser_flush_cbc (context_p);
|
||||
|
||||
if (!is_strict)
|
||||
|
||||
@@ -613,7 +613,7 @@ void parser_parse_expression (parser_context_t *context_p, int options);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
void parser_parse_class (parser_context_t *context_p, bool is_statement);
|
||||
void parser_parse_super_class_context_start (parser_context_t *context_p);
|
||||
void parser_parse_super_class_context_end (parser_context_t *context_p, bool is_statement);
|
||||
void parser_parse_super_class_context_end (parser_context_t *context_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
|
||||
@@ -353,7 +353,7 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
|
||||
|| context_p->token.type == LEXER_KEYW_CONST);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
bool is_const = context_p->token.type == LEXER_KEYW_CONST;
|
||||
uint8_t declaration_type = context_p->token.type;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
while (true)
|
||||
@@ -406,11 +406,36 @@ parser_parse_var_statement (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_LINE_INFO) */
|
||||
|
||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL);
|
||||
parser_parse_expression_statement (context_p, PARSE_EXPR_NO_COMMA | PARSE_EXPR_HAS_LITERAL);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (declaration_type != LEXER_KEYW_VAR
|
||||
&& context_p->lit_object.index < PARSER_REGISTER_START)
|
||||
{
|
||||
uint16_t index = context_p->lit_object.index;
|
||||
|
||||
lexer_next_token (context_p);
|
||||
parser_parse_expression (context_p, PARSE_EXPR_NO_COMMA);
|
||||
parser_emit_cbc_literal (context_p, CBC_ASSIGN_LET_CONST, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
parser_emit_cbc_literal_from_token (context_p, CBC_PUSH_LITERAL);
|
||||
parser_parse_expression_statement (context_p, PARSE_EXPR_NO_COMMA | PARSE_EXPR_HAS_LITERAL);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
else if (is_const)
|
||||
else if (declaration_type == LEXER_KEYW_LET)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED);
|
||||
|
||||
uint16_t index = context_p->lit_object.index;
|
||||
parser_emit_cbc_literal (context_p,
|
||||
index >= PARSER_REGISTER_START ? CBC_MOV_IDENT : CBC_ASSIGN_LET_CONST,
|
||||
index);
|
||||
}
|
||||
else if (declaration_type == LEXER_KEYW_CONST)
|
||||
{
|
||||
parser_raise_error (context_p, PARSER_ERR_MISSING_ASSIGN_AFTER_CONST);
|
||||
}
|
||||
@@ -699,9 +724,7 @@ parser_parse_super_class_context_start (parser_context_t *context_p) /**< contex
|
||||
* Parse super class context like a with statement (ending part).
|
||||
*/
|
||||
void
|
||||
parser_parse_super_class_context_end (parser_context_t *context_p, /**< context */
|
||||
bool is_statement) /**< true - if class is parsed as a statement
|
||||
* false - otherwise (as an expression) */
|
||||
parser_parse_super_class_context_end (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
parser_with_statement_t with_statement;
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
@@ -713,15 +736,7 @@ parser_parse_super_class_context_end (parser_context_t *context_p, /**< context
|
||||
PARSER_MINUS_EQUAL_U16 (context_p->context_stack_depth, PARSER_SUPER_CLASS_CONTEXT_STACK_ALLOCATION);
|
||||
#endif /* !JERRY_NDEBUG */
|
||||
|
||||
if (is_statement)
|
||||
{
|
||||
parser_emit_cbc (context_p, CBC_CONTEXT_END);
|
||||
}
|
||||
else
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_CLASS_EXPR_CONTEXT_END);
|
||||
}
|
||||
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_CLASS_EXPR_CONTEXT_END);
|
||||
parser_set_branch_to_current_position (context_p, &with_statement.branch);
|
||||
} /* parser_parse_super_class_context_end */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
@@ -34,38 +34,42 @@ typedef struct
|
||||
const uint8_t *source_p; /**< start source byte */
|
||||
} scanner_source_start_t;
|
||||
|
||||
/**
|
||||
* Descriptor for storing a let/const literal on stack.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
lexer_lit_location_t *literal_p; /**< let/const literal */
|
||||
} scanner_let_const_literal_t;
|
||||
|
||||
/**
|
||||
* Flags for type member of lexer_lit_location_t structure in the literal pool.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SCANNER_LITERAL_IS_ARG = (1 << 0), /**< literal is argument */
|
||||
SCANNER_LITERAL_IS_LOCAL = (1 << 1), /**< literal is local (similar to let,
|
||||
* but var is allowed with the same identifier) */
|
||||
SCANNER_LITERAL_IS_VAR = (1 << 2), /**< literal is var */
|
||||
SCANNER_LITERAL_IS_FUNC = (1 << 3), /**< literal is function */
|
||||
SCANNER_LITERAL_NO_REG = (1 << 4), /**< literal cannot be stored in register */
|
||||
SCANNER_LITERAL_IS_VAR = (1 << 1), /**< literal is var */
|
||||
SCANNER_LITERAL_IS_FUNC = (1 << 2), /**< literal is function */
|
||||
SCANNER_LITERAL_NO_REG = (1 << 3), /**< literal cannot be stored in register */
|
||||
SCANNER_LITERAL_IS_LET = (1 << 4), /**< literal is let */
|
||||
SCANNER_LITERAL_IS_CONST = (1 << 5), /**< literal is const */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
SCANNER_LITERAL_IS_LET = (1 << 5), /**< literal is let */
|
||||
SCANNER_LITERAL_IS_CONST = (1 << 6), /**< literal is const */
|
||||
SCANNER_LITERAL_IS_USED = (1 << 6), /**< literal is used */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
} scanner_literal_type_flags_t;
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
/*
|
||||
* Known combinations:
|
||||
*
|
||||
* SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET : function declared in this block, might be let or var
|
||||
* SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_CONST : function declared in this block, must be let
|
||||
* SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST : catch block variable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tells whether the literal is let or const declaration.
|
||||
* Literal is a local declration (let, const, catch variable, etc.)
|
||||
*/
|
||||
#define SCANNER_LITERAL_IS_LET_OR_CONST (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
|
||||
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
|
||||
/**
|
||||
* No literal is let or const declaration in ECMAScript 5.1.
|
||||
*/
|
||||
#define SCANNER_LITERAL_IS_LET_OR_CONST 0
|
||||
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
#define SCANNER_LITERAL_IS_LOCAL (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
|
||||
|
||||
/**
|
||||
* For statement descriptor.
|
||||
|
||||
@@ -431,7 +431,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
search_arguments = false;
|
||||
|
||||
if (type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET_OR_CONST))
|
||||
if (type & (SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LOCAL))
|
||||
{
|
||||
arguments_required = false;
|
||||
}
|
||||
@@ -444,8 +444,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (is_function
|
||||
&& (type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LET_OR_CONST)) == SCANNER_LITERAL_IS_FUNC)
|
||||
if (is_function && (type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_LOCAL)) == SCANNER_LITERAL_IS_FUNC)
|
||||
{
|
||||
type = (uint8_t) ((type & ~SCANNER_LITERAL_IS_FUNC) | SCANNER_LITERAL_IS_VAR);
|
||||
literal_p->type = type;
|
||||
@@ -453,7 +452,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if ((is_function && (type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_ARG)))
|
||||
|| (type & (SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_IS_LET_OR_CONST)))
|
||||
|| (type & SCANNER_LITERAL_IS_LOCAL))
|
||||
{
|
||||
JERRY_ASSERT (is_function || !(literal_p->type & SCANNER_LITERAL_IS_ARG));
|
||||
|
||||
@@ -513,16 +512,20 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
lexer_lit_location_t *literal_location_p = scanner_add_custom_literal (context_p,
|
||||
prev_literal_pool_p,
|
||||
literal_p);
|
||||
uint8_t extended_type = literal_location_p->type;
|
||||
|
||||
if (is_function || (type & SCANNER_LITERAL_NO_REG))
|
||||
{
|
||||
literal_location_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
extended_type |= SCANNER_LITERAL_NO_REG;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (literal_location_p->type & SCANNER_LITERAL_IS_LET_OR_CONST)
|
||||
extended_type |= SCANNER_LITERAL_IS_USED;
|
||||
|
||||
if (literal_location_p->type & SCANNER_LITERAL_IS_LOCAL)
|
||||
{
|
||||
JERRY_ASSERT (!(type & SCANNER_LITERAL_IS_VAR));
|
||||
/* Clears the SCANNER_LITERAL_IS_FUNC flag. */
|
||||
type = 0;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
@@ -530,7 +533,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
type = (uint8_t) (type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_FUNC));
|
||||
JERRY_ASSERT (type == 0 || !is_function);
|
||||
|
||||
literal_location_p->type = (uint8_t) (literal_location_p->type | type);
|
||||
literal_location_p->type = (uint8_t) (extended_type | type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,7 +597,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
if (JERRY_UNLIKELY (no_declarations > PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK)
|
||||
|| (!(is_function && (literal_p->type & (SCANNER_LITERAL_IS_VAR | SCANNER_LITERAL_IS_ARG)))
|
||||
&& !(literal_p->type & (SCANNER_LITERAL_IS_LOCAL | SCANNER_LITERAL_IS_LET_OR_CONST))))
|
||||
&& !(literal_p->type & SCANNER_LITERAL_IS_LOCAL)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -632,7 +635,10 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
else if (literal_p->type & SCANNER_LITERAL_IS_LET)
|
||||
{
|
||||
type = SCANNER_STREAM_TYPE_LET;
|
||||
if (!(literal_p->type & SCANNER_LITERAL_IS_CONST))
|
||||
{
|
||||
type = SCANNER_STREAM_TYPE_LET;
|
||||
}
|
||||
}
|
||||
else if (literal_p->type & SCANNER_LITERAL_IS_CONST)
|
||||
{
|
||||
@@ -873,6 +879,10 @@ scanner_add_reference (parser_context_t *context_p, /**< context */
|
||||
lexer_lit_location_t *lit_location_p = scanner_add_custom_literal (context_p,
|
||||
scanner_context_p->active_literal_pool_p,
|
||||
&context_p->token.lit_location);
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
lit_location_p->type |= SCANNER_LITERAL_IS_USED;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH)
|
||||
{
|
||||
lit_location_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
@@ -985,7 +995,7 @@ scanner_scope_find_let_declaration (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
|
||||
|
||||
if (property_p != NULL && (*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE))
|
||||
if (property_p != NULL && ecma_is_property_enumerable (*property_p))
|
||||
{
|
||||
ecma_deref_ecma_string (name_p);
|
||||
return true;
|
||||
@@ -1001,7 +1011,7 @@ scanner_scope_find_let_declaration (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
ecma_property_t *property_p = ecma_find_named_property (lex_env_p, name_p);
|
||||
|
||||
if (property_p != NULL && (*property_p & ECMA_PROPERTY_FLAG_ENUMERABLE))
|
||||
if (property_p != NULL && ecma_is_property_enumerable (*property_p))
|
||||
{
|
||||
ecma_deref_ecma_string (name_p);
|
||||
return true;
|
||||
@@ -1021,8 +1031,9 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
|
||||
scanner_context_t *scanner_context_p, /**< scanner context */
|
||||
lexer_lit_location_t *var_literal_p) /**< literal */
|
||||
{
|
||||
if (var_literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
|
||||
&& !(var_literal_p->type & SCANNER_LITERAL_IS_FUNC))
|
||||
if (var_literal_p->type & SCANNER_LITERAL_IS_LOCAL
|
||||
&& !(var_literal_p->type & SCANNER_LITERAL_IS_FUNC)
|
||||
&& (var_literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL)
|
||||
{
|
||||
scanner_raise_redeclaration_error (context_p);
|
||||
}
|
||||
@@ -1043,7 +1054,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
|
||||
{
|
||||
if (literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
|
||||
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
|
||||
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
|
||||
&& literal_p->length == length)
|
||||
{
|
||||
if (JERRY_LIKELY (!literal_p->has_escape))
|
||||
@@ -1066,7 +1078,8 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
|
||||
{
|
||||
if (literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST)
|
||||
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
|
||||
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
|
||||
&& literal_p->length == length
|
||||
&& lexer_compare_identifiers (literal_p->char_p, char_p, length))
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ typedef enum
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
SCAN_STACK_LET, /**< let statement */
|
||||
SCAN_STACK_CONST, /**< const statement */
|
||||
SCAN_STACK_LET_CONST_INIT, /**< let/const statement initializer */
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
/* The SCANNER_IS_FOR_START macro needs to be updated when the following constants are reordered. */
|
||||
SCAN_STACK_VAR, /**< var statement */
|
||||
@@ -523,6 +524,24 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case SCAN_STACK_LET_CONST_INIT:
|
||||
{
|
||||
scanner_let_const_literal_t let_const_literal;
|
||||
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
parser_stack_pop (context_p, &let_const_literal, sizeof (scanner_let_const_literal_t));
|
||||
|
||||
if (let_const_literal.literal_p->type & SCANNER_LITERAL_IS_USED)
|
||||
{
|
||||
let_const_literal.literal_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_LET
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_CONST);
|
||||
|
||||
scanner_context_p->mode = SCAN_MODE_VAR_STATEMENT;
|
||||
return SCAN_NEXT_TOKEN;
|
||||
}
|
||||
case SCAN_STACK_ARROW_ARGUMENTS:
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
@@ -635,6 +654,24 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
return SCAN_NEXT_TOKEN;
|
||||
}
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case SCAN_STACK_LET_CONST_INIT:
|
||||
{
|
||||
scanner_let_const_literal_t let_const_literal;
|
||||
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
parser_stack_pop (context_p, &let_const_literal, sizeof (scanner_let_const_literal_t));
|
||||
|
||||
if (let_const_literal.literal_p->type & SCANNER_LITERAL_IS_USED)
|
||||
{
|
||||
let_const_literal.literal_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_LET
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_CONST);
|
||||
/* FALLTHRU */
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
case SCAN_STACK_VAR:
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
case SCAN_STACK_LET:
|
||||
@@ -1214,7 +1251,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (literal_p->type & SCANNER_LITERAL_IS_LET_OR_CONST
|
||||
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
|
||||
&& !(literal_p->type & SCANNER_LITERAL_IS_FUNC))
|
||||
{
|
||||
scanner_raise_redeclaration_error (context_p);
|
||||
@@ -1252,9 +1289,8 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p);
|
||||
|
||||
if (literal_p->type & (SCANNER_LITERAL_IS_ARG
|
||||
| SCANNER_LITERAL_IS_LOCAL
|
||||
| SCANNER_LITERAL_IS_VAR
|
||||
| SCANNER_LITERAL_IS_LET_OR_CONST))
|
||||
| SCANNER_LITERAL_IS_LOCAL))
|
||||
{
|
||||
scanner_raise_redeclaration_error (context_p);
|
||||
}
|
||||
@@ -1422,7 +1458,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
|
||||
lexer_lit_location_t *location_p = scanner_add_literal (context_p, scanner_context_p);
|
||||
|
||||
#if ENABLED (JERRY_ES2015)
|
||||
if (location_p->type & SCANNER_LITERAL_IS_LET_OR_CONST
|
||||
if (location_p->type & SCANNER_LITERAL_IS_LOCAL
|
||||
&& !(location_p->type & SCANNER_LITERAL_IS_FUNC))
|
||||
{
|
||||
scanner_raise_redeclaration_error (context_p);
|
||||
@@ -2160,9 +2196,8 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
if (stack_top == SCAN_STACK_LET || stack_top == SCAN_STACK_CONST)
|
||||
{
|
||||
if (literal_p->type & (SCANNER_LITERAL_IS_ARG
|
||||
| SCANNER_LITERAL_IS_LOCAL
|
||||
| SCANNER_LITERAL_IS_VAR
|
||||
| SCANNER_LITERAL_IS_LET_OR_CONST))
|
||||
| SCANNER_LITERAL_IS_LOCAL))
|
||||
{
|
||||
scanner_raise_redeclaration_error (context_p);
|
||||
}
|
||||
@@ -2180,15 +2215,39 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
literal_p->type |= SCANNER_LITERAL_IS_CONST;
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
|
||||
if (literal_p->type & SCANNER_LITERAL_IS_USED)
|
||||
{
|
||||
literal_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
}
|
||||
else if (context_p->token.type == LEXER_ASSIGN)
|
||||
{
|
||||
scanner_let_const_literal_t let_const_literal;
|
||||
let_const_literal.literal_p = literal_p;
|
||||
|
||||
parser_stack_push (context_p, &let_const_literal, sizeof (scanner_let_const_literal_t));
|
||||
parser_stack_push_uint8 (context_p, SCAN_STACK_LET_CONST_INIT);
|
||||
}
|
||||
}
|
||||
else if (!(literal_p->type & SCANNER_LITERAL_IS_VAR))
|
||||
else
|
||||
{
|
||||
scanner_detect_invalid_var (context_p, &scanner_context, literal_p);
|
||||
literal_p->type |= SCANNER_LITERAL_IS_VAR;
|
||||
if (!(literal_p->type & SCANNER_LITERAL_IS_VAR))
|
||||
{
|
||||
scanner_detect_invalid_var (context_p, &scanner_context, literal_p);
|
||||
literal_p->type |= SCANNER_LITERAL_IS_VAR;
|
||||
|
||||
if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH)
|
||||
{
|
||||
literal_p->type |= SCANNER_LITERAL_NO_REG;
|
||||
}
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
}
|
||||
#else /* !ENABLED (JERRY_ES2015) */
|
||||
literal_p->type |= SCANNER_LITERAL_IS_VAR;
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
if (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_WITH)
|
||||
{
|
||||
@@ -2196,6 +2255,7 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
#endif /* ENABLED (JERRY_ES2015) */
|
||||
|
||||
switch (context_p->token.type)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user