Support catch statement without argument. (#3956)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -1997,11 +1997,6 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
|
|||||||
{
|
{
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_LEFT_PAREN)
|
|
||||||
{
|
|
||||||
parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED);
|
|
||||||
}
|
|
||||||
|
|
||||||
try_statement.type = parser_catch_block;
|
try_statement.type = parser_catch_block;
|
||||||
parser_emit_cbc_ext_forward_branch (context_p,
|
parser_emit_cbc_ext_forward_branch (context_p,
|
||||||
CBC_EXT_CATCH,
|
CBC_EXT_CATCH,
|
||||||
@@ -2029,50 +2024,63 @@ parser_parse_try_statement_end (parser_context_t *context_p) /**< context */
|
|||||||
scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS);
|
scanner_create_variables (context_p, SCANNER_CREATE_VARS_NO_OPTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context_p->token.type == LEXER_LEFT_PAREN)
|
||||||
|
{
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE))
|
if (lexer_check_next_characters (context_p, LIT_CHAR_LEFT_SQUARE, LIT_CHAR_LEFT_BRACE))
|
||||||
{
|
{
|
||||||
parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING
|
parser_pattern_flags_t flags = (PARSER_PATTERN_BINDING
|
||||||
| PARSER_PATTERN_TARGET_ON_STACK
|
| PARSER_PATTERN_TARGET_ON_STACK
|
||||||
| PARSER_PATTERN_LET);
|
| PARSER_PATTERN_LET);
|
||||||
|
|
||||||
parser_parse_initializer_by_next_char (context_p, flags);
|
parser_parse_initializer_by_next_char (context_p, flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL);
|
lexer_expect_identifier (context_p, LEXER_IDENT_LITERAL);
|
||||||
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL
|
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL
|
||||||
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
uint16_t literal_index = context_p->lit_object.index;
|
uint16_t literal_index = context_p->lit_object.index;
|
||||||
parser_emit_cbc_literal (context_p,
|
parser_emit_cbc_literal (context_p,
|
||||||
(literal_index >= PARSER_REGISTER_START) ? CBC_ASSIGN_SET_IDENT : CBC_ASSIGN_LET_CONST,
|
(literal_index >= PARSER_REGISTER_START) ? CBC_ASSIGN_SET_IDENT : CBC_ASSIGN_LET_CONST,
|
||||||
literal_index);
|
literal_index);
|
||||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||||
parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, context_p->lit_object.index);
|
parser_emit_cbc_literal (context_p, CBC_ASSIGN_SET_IDENT, context_p->lit_object.index);
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
#ifndef JERRY_NDEBUG
|
||||||
|
JERRY_ASSERT (block_found);
|
||||||
|
#endif /* !JERRY_NDEBUG */
|
||||||
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
|
||||||
|
if (context_p->token.type != LEXER_RIGHT_PAREN)
|
||||||
|
{
|
||||||
|
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
|
||||||
|
}
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
#ifndef JERRY_NDEBUG
|
if (context_p->token.type != LEXER_LEFT_BRACE)
|
||||||
JERRY_ASSERT (block_found);
|
{
|
||||||
#endif /* !JERRY_NDEBUG */
|
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
|
else if (context_p->token.type == LEXER_LEFT_BRACE)
|
||||||
|
{
|
||||||
|
parser_emit_cbc (context_p, CBC_POP);
|
||||||
}
|
}
|
||||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
else
|
||||||
if (context_p->token.type != LEXER_RIGHT_PAREN)
|
|
||||||
{
|
{
|
||||||
parser_raise_error (context_p, PARSER_ERR_RIGHT_PAREN_EXPECTED);
|
parser_raise_error (context_p, PARSER_ERR_LEFT_PAREN_EXPECTED);
|
||||||
}
|
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_LEFT_BRACE)
|
|
||||||
{
|
|
||||||
parser_raise_error (context_p, PARSER_ERR_LEFT_BRACE_EXPECTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parser_flush_cbc (context_p);
|
parser_flush_cbc (context_p);
|
||||||
|
|||||||
@@ -2162,17 +2162,25 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
|||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
scanner_literal_pool_t *literal_pool_p;
|
||||||
|
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK);
|
||||||
|
literal_pool_p->source_p = context_p->source_p;
|
||||||
|
parser_stack_push_uint8 (context_p, SCAN_STACK_CATCH_STATEMENT);
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
|
if (context_p->token.type == LEXER_LEFT_BRACE)
|
||||||
|
{
|
||||||
|
scanner_context_p->mode = SCAN_MODE_STATEMENT_OR_TERMINATOR;
|
||||||
|
return SCAN_NEXT_TOKEN;
|
||||||
|
}
|
||||||
|
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||||
|
|
||||||
if (context_p->token.type != LEXER_LEFT_PAREN)
|
if (context_p->token.type != LEXER_LEFT_PAREN)
|
||||||
{
|
{
|
||||||
scanner_raise_error (context_p);
|
scanner_raise_error (context_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
scanner_literal_pool_t *literal_pool_p;
|
|
||||||
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK);
|
|
||||||
literal_pool_p->source_p = context_p->source_p;
|
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
parser_stack_push_uint8 (context_p, SCAN_STACK_CATCH_STATEMENT);
|
|
||||||
|
|
||||||
#if ENABLED (JERRY_ESNEXT)
|
#if ENABLED (JERRY_ESNEXT)
|
||||||
if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE)
|
if (context_p->token.type == LEXER_LEFT_SQUARE || context_p->token.type == LEXER_LEFT_BRACE)
|
||||||
|
|||||||
@@ -128,3 +128,37 @@ function f7()
|
|||||||
assert(e === 6)
|
assert(e === 6)
|
||||||
}
|
}
|
||||||
f7()
|
f7()
|
||||||
|
|
||||||
|
function f8()
|
||||||
|
{
|
||||||
|
var cnt = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw "A"
|
||||||
|
asert(false)
|
||||||
|
} catch {
|
||||||
|
cnt++
|
||||||
|
}
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
const j = 0
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw {}
|
||||||
|
asert(false)
|
||||||
|
} catch {
|
||||||
|
const i = 1.5
|
||||||
|
let j = 2
|
||||||
|
cnt += i * j
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(i === 0)
|
||||||
|
assert(j === 0)
|
||||||
|
return cnt
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
assert(f8() === 4)
|
||||||
|
} catch {
|
||||||
|
assert(false)
|
||||||
|
}
|
||||||
|
|||||||
@@ -360,10 +360,11 @@
|
|||||||
<test id="language/statements/continue/simple-and-labeled.js"><reason></reason></test>
|
<test id="language/statements/continue/simple-and-labeled.js"><reason></reason></test>
|
||||||
<test id="language/statements/for-of/body-dstr-assign-error.js"><reason></reason></test>
|
<test id="language/statements/for-of/body-dstr-assign-error.js"><reason></reason></test>
|
||||||
<test id="language/statements/for-of/body-dstr-assign.js"><reason></reason></test>
|
<test id="language/statements/for-of/body-dstr-assign.js"><reason></reason></test>
|
||||||
<test id="language/statements/for-of/iterator-next-reference.js"><reason>ES spec change: next method must be cached</reason></test>
|
<test id="language/statements/for-of/iterator-next-reference.js"><reason>ES2018 change: next method must be cached</reason></test>
|
||||||
<test id="language/statements/for/S12.6.3_A9.1.js"><reason></reason></test>
|
<test id="language/statements/for/S12.6.3_A9.1.js"><reason></reason></test>
|
||||||
<test id="language/statements/for/S12.6.3_A9.js"><reason></reason></test>
|
<test id="language/statements/for/S12.6.3_A9.js"><reason></reason></test>
|
||||||
<test id="language/statements/generators/has-instance.js"><reason></reason></test>
|
<test id="language/statements/generators/has-instance.js"><reason></reason></test>
|
||||||
<test id="language/statements/generators/prototype-value.js"><reason></reason></test>
|
<test id="language/statements/generators/prototype-value.js"><reason></reason></test>
|
||||||
<test id="language/statements/let/syntax/identifier-let-disallowed-as-boundname.js"><reason></reason></test>
|
<test id="language/statements/let/syntax/identifier-let-disallowed-as-boundname.js"><reason></reason></test>
|
||||||
|
<test id="language/statements/try/S12.14_A16_T4.js"><reason>ES2019 change: catch without parameter is allowed</reason></test>
|
||||||
</excludeList>
|
</excludeList>
|
||||||
|
|||||||
Reference in New Issue
Block a user