mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2026-02-07 16:11:39 +00:00
Don't continue parsing expressions after ternary operators. (#3847)
Further benefits: new code requires less checks. Fixes #3841 Fixes #3842 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
parent
1414e9bb00
commit
e6ebc2be78
@ -3304,13 +3304,9 @@ parser_parse_initializer_by_next_char (parser_context_t *context_p, /**< context
|
||||
|
||||
/**
|
||||
* Process ternary expression.
|
||||
*
|
||||
* @return true - continue with primary expression parsing
|
||||
* false - otherwise
|
||||
*/
|
||||
static bool
|
||||
parser_process_ternary_expression (parser_context_t *context_p, /**< context */
|
||||
size_t grouping_level) /**< grouping level */
|
||||
static void
|
||||
parser_process_ternary_expression (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
JERRY_ASSERT (context_p->token.type == LEXER_QUESTION_MARK);
|
||||
|
||||
@ -3354,7 +3350,6 @@ parser_process_ternary_expression (parser_context_t *context_p, /**< context */
|
||||
parser_flush_cbc (context_p);
|
||||
|
||||
parser_process_binary_opcodes (context_p, 0);
|
||||
return grouping_level >= PARSER_GROUPING_LEVEL_INCREASE;
|
||||
} /* parser_process_ternary_expression */
|
||||
|
||||
/**
|
||||
@ -3524,12 +3519,6 @@ process_unary_expression:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (context_p->token.type == LEXER_QUESTION_MARK)
|
||||
&& (grouping_level != PARSE_EXPR_LEFT_HAND_SIDE)
|
||||
&& parser_process_ternary_expression (context_p, grouping_level))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3538,6 +3527,22 @@ process_unary_expression:
|
||||
break;
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (context_p->token.type == LEXER_QUESTION_MARK))
|
||||
{
|
||||
parser_process_ternary_expression (context_p);
|
||||
|
||||
if (context_p->token.type == LEXER_RIGHT_PAREN)
|
||||
{
|
||||
goto process_unary_expression;
|
||||
}
|
||||
}
|
||||
else if (LEXER_IS_BINARY_OP_TOKEN (context_p->token.type))
|
||||
{
|
||||
parser_append_binary_token (context_p);
|
||||
lexer_next_token (context_p);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (JERRY_UNLIKELY (context_p->token.type == LEXER_COMMA)
|
||||
&& (!(options & PARSE_EXPR_NO_COMMA) || grouping_level >= PARSER_GROUPING_LEVEL_INCREASE))
|
||||
{
|
||||
@ -3545,12 +3550,6 @@ process_unary_expression:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (LEXER_IS_BINARY_OP_TOKEN (context_p->token.type))
|
||||
{
|
||||
parser_append_binary_token (context_p);
|
||||
lexer_next_token (context_p);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
20
tests/jerry/es2015/regresssion-test-issue-3841.js
Normal file
20
tests/jerry/es2015/regresssion-test-issue-3841.js
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
try {
|
||||
eval('$?$:$=>{ }?{ }:$')
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
20
tests/jerry/es2015/regresssion-test-issue-3842.js
Normal file
20
tests/jerry/es2015/regresssion-test-issue-3842.js
Normal file
@ -0,0 +1,20 @@
|
||||
// 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.
|
||||
|
||||
try {
|
||||
eval('while(0 ? 0 : ()=>{} | {})')
|
||||
assert(false)
|
||||
} catch (e) {
|
||||
assert(e instanceof SyntaxError)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user