Skip to content

Commit daf3b36

Browse files
galpeterdbatyai
authored andcommitted
Fix new.target invalidity check (#3521)
Fixes #3519 Only check the assert if the new.target bytecode is detected. JerryScript-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
1 parent 51244b6 commit daf3b36

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

jerry-core/parser/js/js-parser-expr.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,18 @@ parser_check_invalid_assign (parser_context_t *context_p) /**< context */
119119
*/
120120
static void
121121
parser_check_invalid_new_target (parser_context_t *context_p, /**< parser context */
122-
cbc_opcode_t opcode) /**< current opcode under parsing */
122+
cbc_opcode_t opcode) /**< current opcode under parsing */
123123
{
124-
JERRY_ASSERT ((opcode >= CBC_PRE_INCR && opcode <= CBC_POST_DECR)
125-
|| (opcode == CBC_ASSIGN
126-
&& (context_p->token.type == LEXER_ASSIGN
127-
|| LEXER_IS_BINARY_LVALUE_TOKEN (context_p->token.type))));
128-
129124
/* new.target is an invalid left-hand side target */
130125
if (context_p->last_cbc_opcode == PARSER_TO_EXT_OPCODE (CBC_EXT_PUSH_NEW_TARGET))
131126
{
127+
/* Make sure that the call side is a post/pre increment or an assignment expression.
128+
* There should be no other ways the "new.target" expression should be here. */
129+
JERRY_ASSERT ((opcode >= CBC_PRE_INCR && opcode <= CBC_POST_DECR)
130+
|| (opcode == CBC_ASSIGN
131+
&& (context_p->token.type == LEXER_ASSIGN
132+
|| LEXER_IS_BINARY_LVALUE_TOKEN (context_p->token.type))));
133+
132134
parser_raise_error (context_p, PARSER_ERR_NEW_TARGET_NOT_ALLOWED);
133135
}
134136
} /* parser_check_invalid_new_target */
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function method () {
16+
[""] = $
17+
}
18+
19+
try {
20+
eval ("function mm () { [new.target] = 3; }");
21+
assert (false);
22+
} catch (ex) {
23+
assert (ex instanceof SyntaxError);
24+
}

0 commit comments

Comments
 (0)