Skip to content

Commit 4660bab

Browse files
authored
Fix PropertyDefinition parsing in ObjectInitializer (#3832)
This patch fixes #3822 and fixes #3823 and fixes #3824 and fixes #3825. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent a56e31f commit 4660bab

File tree

5 files changed

+108
-2
lines changed

5 files changed

+108
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,18 +888,27 @@ parser_reparse_as_common_identifier (parser_context_t *context_p, /**< context *
888888
parser_line_counter_t start_line, /**< start line */
889889
parser_line_counter_t start_column) /**< start column */
890890
{
891+
/* context_p->token.lit_location.char_p is showing the character after the string start,
892+
so it is not suitable for reparsing as identifier.
893+
e.g.: { 'foo' } */
894+
if (context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
895+
{
896+
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
897+
}
898+
891899
context_p->source_p = context_p->token.lit_location.char_p;
892900
context_p->line = start_line;
893901
context_p->column = start_column;
894902

895903
lexer_next_token (context_p);
896904

897-
if (context_p->token.type != LEXER_LITERAL
898-
|| context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
905+
if (context_p->token.type != LEXER_LITERAL)
899906
{
900907
parser_raise_error (context_p, PARSER_ERR_IDENTIFIER_EXPECTED);
901908
}
902909

910+
JERRY_ASSERT (context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
911+
903912
lexer_construct_literal_object (context_p,
904913
&context_p->token.lit_location,
905914
LEXER_IDENT_LITERAL);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
try {
16+
eval(`function f ({array, 'a', { value: 'foo', enumerable: true } : 36}){}`);
17+
assert(false);
18+
} catch (e) {
19+
assert(e instanceof SyntaxError);
20+
}
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
try {
16+
eval(`function f ({"aba,a"}){}`);
17+
assert(false);
18+
} catch (e) {
19+
assert(e instanceof SyntaxError);
20+
}
21+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
try {
16+
eval(`var a = {"foo//b", };`);
17+
assert(false);
18+
} catch (e) {
19+
assert(e instanceof SyntaxError);
20+
}
21+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
try {
16+
eval(`var errorMessage = "toStringThrows"
17+
18+
var toStringThrows = {
19+
"foo//bar/baz//foo"
20+
}
21+
22+
try {
23+
var obj = {};
24+
obj[toStringThrows] = 3;
25+
assert(false);
26+
} catch (e) {
27+
assert(e.message == errorMessage);
28+
}
29+
`);
30+
assert(false);
31+
} catch (e) {
32+
assert(e instanceof SyntaxError);
33+
}
34+

0 commit comments

Comments
 (0)