diff --git a/jerry-core/parser/js/js-lexer.c b/jerry-core/parser/js/js-lexer.c index 87f2baa8a..3e4ee3bba 100644 --- a/jerry-core/parser/js/js-lexer.c +++ b/jerry-core/parser/js/js-lexer.c @@ -2457,7 +2457,8 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */ || context_p->token.type == LEXER_LEFT_SQUARE #endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */ || context_p->token.type == LEXER_RIGHT_BRACE - || context_p->token.type == LEXER_SEMICOLON) + || context_p->token.type == LEXER_SEMICOLON + || ((ident_opts & LEXER_SCAN_CLASS_LEFT_PAREN) && context_p->token.type == LEXER_LEFT_PAREN)) { return; } diff --git a/jerry-core/parser/js/js-lexer.h b/jerry-core/parser/js/js-lexer.h index 6fa5fca8c..08e1db7ef 100644 --- a/jerry-core/parser/js/js-lexer.h +++ b/jerry-core/parser/js/js-lexer.h @@ -265,6 +265,7 @@ typedef enum LEXER_SCAN_IDENT_NO_KEYW = (1u << 2), /**< don't scan keywords (e.g. get/set) */ #if ENABLED (JERRY_ES2015_CLASS) LEXER_SCAN_CLASS_PROPERTY = (1u << 3), /**< scan valid class property names */ + LEXER_SCAN_CLASS_LEFT_PAREN = (1u << 4), /**< also parse left parenthesis */ #endif /* ENABLED (JERRY_ES2015_CLASS) */ } lexer_scan_ident_opts_t; diff --git a/jerry-core/parser/js/js-scanner.c b/jerry-core/parser/js/js-scanner.c index 9eb5bfc84..d43a88f0e 100644 --- a/jerry-core/parser/js/js-scanner.c +++ b/jerry-core/parser/js/js-scanner.c @@ -1390,13 +1390,19 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY); } + parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FUNCTION); + scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; + if (lexer_compare_literal_to_identifier (context_p, "get", 3) || lexer_compare_literal_to_identifier (context_p, "set", 3)) { - lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY); - } + lexer_scan_identifier (context_p, LEXER_SCAN_CLASS_PROPERTY | LEXER_SCAN_CLASS_LEFT_PAREN); - parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FUNCTION); + if (context_p->token.type == LEXER_LEFT_PAREN) + { + continue; + } + } #if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) if (context_p->token.type == LEXER_LEFT_SQUARE) @@ -1408,7 +1414,6 @@ scanner_scan_all (parser_context_t *context_p) /**< context */ #endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */ lexer_next_token (context_p); - scanner_context.mode = SCAN_MODE_FUNCTION_ARGUMENTS; continue; } #endif /* ENABLED (JERRY_ES2015_CLASS) */ diff --git a/tests/jerry/es2015/class.js b/tests/jerry/es2015/class.js index f330f0988..4465f05c3 100644 --- a/tests/jerry/es2015/class.js +++ b/tests/jerry/es2015/class.js @@ -125,11 +125,21 @@ class E { set e(e) { this._e = e; } + + get () { + return 11; + } + + set () { + return 12; + } } var e = new E (5); assert (e.e === 5); e.e = 10; assert (e.e === 10); +assert (e.get() === 11); +assert (e.set() === 12); assert (e.constructor === E); var F = class ClassF { @@ -193,6 +203,14 @@ var G = class { return this._a; } + static get() { + return 11; + } + + static set() { + return 12; + } + static set constructor(a) { this._a = a; } @@ -214,6 +232,8 @@ assert (G.a === 10); assert (G.g1() === 10); G["1"] = 20; assert (G["1"] === 20); +assert (G.get() == 11); +assert (G.set() == 12); G.constructor = 30; assert (G.constructor === 30); diff --git a/tests/jerry/es2015/regression-test-issue-3095.js b/tests/jerry/es2015/regression-test-issue-3095.js new file mode 100644 index 000000000..e500e63be --- /dev/null +++ b/tests/jerry/es2015/regression-test-issue-3095.js @@ -0,0 +1,19 @@ +// 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. + +class $ { + set ( ) { + switch ( $ ) { } + } +} diff --git a/tests/jerry/fail/regression-test-issue-3094.js b/tests/jerry/fail/regression-test-issue-3094.js new file mode 100644 index 000000000..784a9e89b --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-3094.js @@ -0,0 +1,18 @@ +// 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. + +class $ { + set ( ) {} +} +for ( ; 10 ; i ) diff --git a/tests/jerry/fail/regression-test-issue-3096.js b/tests/jerry/fail/regression-test-issue-3096.js new file mode 100644 index 000000000..cb13b2aab --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-3096.js @@ -0,0 +1,19 @@ +// 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. + +class $ { + set ( ) { + while ( done ) + } +}